Ejemplo n.º 1
0
        /// <summary>
        /// 公众号支付下单
        /// </summary>
        /// <param name="Model"></param>
        public WeChatPayRespone DoRequest(WeChatPayModel model)
        {
            WeChatPayByJsModel   Model   = model as WeChatPayByJsModel;
            WeChatPayByJsRespone Respone = new WeChatPayByJsRespone();
            var Parameters = new Dictionary <string, string>();

            Model.sNonceStr = WeChatPayHelper.GetRandomStr();//获取随机字符串
            Parameters.Add("appid", Model.sAppId);
            Parameters.Add("mch_id", Model.sMchId);
            Parameters.Add("nonce_str", Model.sNonceStr);
            Parameters.Add("body", Model.sBody);
            Parameters.Add("out_trade_no", Model.sOrderNo);
            Parameters.Add("total_fee", Model.iTotalFee.ToString());
            Parameters.Add("spbill_create_ip", Model.spbill_create_ip);
            Parameters.Add("notify_url", Model.sNotifyUrl);
            Parameters.Add("trade_type", Enum.GetName(typeof(WeChatPayType), Model.sTradeType));
            Parameters.Add("openid", Model.sOpenId);
            if (!string.IsNullOrEmpty(model.attach))
            {
                Parameters.Add("attach", model.attach); //添加商户自定义数据
            }
            //创建签名
            Model.sSign = WeChatPayHelper.CreateSign(Parameters, Model.sPayKey);
            Parameters.Add("sign", Model.sSign);
            string sRequestXmlStr = WeChatPayHelper.InstallXml(Parameters);
            //获取微信响应结果
            string sResponeXmlStr   = WeChatPayHelper.HttpPost(sUrl, sRequestXmlStr, null);
            var    ResponeParameter = WeChatPayHelper.GetDictionaryFromCDATAXml(sResponeXmlStr);

            Respone.sReturnParams = ResponeParameter;
            //判断返回结果
            if (ResponeParameter["return_code"] == "SUCCESS")
            {
                if (WeChatPayHelper.CheckSign(ResponeParameter, Model.sPayKey))
                {
                    if (ResponeParameter["result_code"] == "SUCCESS")
                    {
                        Respone.bSuccess   = true;
                        Respone.sReturnMsg = ResponeParameter["return_msg"];
                        Respone.sPrepayId  = ResponeParameter["prepay_id"];//微信生成的预支付会话标识,用于后续接口调用中使用,该值有效期为2小时
                    }
                    else
                    {
                        Respone.bSuccess   = false;
                        Respone.sReturnMsg = ResponeParameter["err_code_des"];
                    }
                }
                else
                {
                    Respone.bSuccess   = false;
                    Respone.sReturnMsg = "签名验证失败";
                }
            }
            else
            {
                Respone.bSuccess   = false;
                Respone.sReturnMsg = ResponeParameter["return_msg"];
            }
            return(Respone);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 扫码支付下单
        /// </summary>
        /// <param name="Model"></param>
        public WeChatPayRespone DoRequest(WeChatPayModel model)
        {
            WeChatPayByScanModel   Model   = model as WeChatPayByScanModel;
            WeChatPayByScanRespone Respone = new WeChatPayByScanRespone();
            var Parameters = new Dictionary <string, string>();

            Model.sNonceStr = WeChatPayHelper.GetRandomStr();//获取随机字符串
            Parameters.Add("appid", Model.sAppId);
            Parameters.Add("mch_id", Model.sMchId);
            Parameters.Add("nonce_str", Model.sNonceStr);
            Parameters.Add("body", Model.sBody);
            Parameters.Add("out_trade_no", Model.sOrderNo);
            Parameters.Add("total_fee", Model.iTotalFee.ToString());
            Parameters.Add("spbill_create_ip", Model.spbill_create_ip);
            Parameters.Add("notify_url", Model.sNotifyUrl);
            Parameters.Add("trade_type", Enum.GetName(typeof(WeChatPayType), Model.sTradeType));
            Parameters.Add("product_id", Model.sProductId);
            Parameters.Add("attach", Model.sAttach);//自定义参数
            //创建签名
            Model.sSign = WeChatPayHelper.CreateSign(Parameters, Model.sPayKey);
            Parameters.Add("sign", Model.sSign);
            string sRequestXmlStr = WeChatPayHelper.InstallXml(Parameters);
            //获取微信响应结果
            string sResponeXmlStr   = WeChatPayHelper.HttpPost(sUrl, sRequestXmlStr, null);
            var    ResponeParameter = WeChatPayHelper.GetDictionaryFromCDATAXml(sResponeXmlStr);

            Respone.sReturnParams = ResponeParameter;
            //判断返回结果
            if (ResponeParameter["return_code"] == "SUCCESS")
            {
                if (WeChatPayHelper.CheckSign(ResponeParameter, Model.sPayKey))
                {
                    if (ResponeParameter["result_code"] == "SUCCESS")
                    {
                        Respone.bSuccess   = true;
                        Respone.sReturnMsg = ResponeParameter["return_msg"];
                        Respone.sCodeUrl   = ResponeParameter["code_url"];//返回的支付二维码链接有效期2个小时
                    }
                    else
                    {
                        Respone.bSuccess   = false;
                        Respone.sReturnMsg = ResponeParameter["err_code_des"];
                    }
                }
                else
                {
                    Respone.bSuccess   = false;
                    Respone.sReturnMsg = "签名验证失败";
                }
            }
            else
            {
                Respone.bSuccess   = false;
                Respone.sReturnMsg = ResponeParameter["return_msg"];
            }
            return(Respone);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 执行微信申请退款
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public WeChatPayRespone DoRequest(WeChatPayModel model)
        {
            WeChatPayRefundModel   Model   = model as WeChatPayRefundModel;
            WeChatPayRefundRespone Respone = new WeChatPayRefundRespone();
            var Parameters = new Dictionary <string, string>();

            Model.sNonceStr = WeChatPayHelper.GetRandomStr();//获取随机字符串
            Parameters.Add("appid", Model.sAppId);
            Parameters.Add("mch_id", Model.sMchId);
            Parameters.Add("nonce_str", Model.sNonceStr);
            Parameters.Add("out_trade_no", Model.sOrderNo);
            Parameters.Add("out_refund_no", Model.sRefundNo);
            Parameters.Add("total_fee", Model.iTotalFee.ToString());   //订单总金额
            Parameters.Add("refund_fee", Model.iRefundFee.ToString()); //退款金额
            //创建签名
            Model.sSign = WeChatPayHelper.CreateSign(Parameters, Model.sPayKey);
            Parameters.Add("sign", Model.sSign);
            string sRequestXmlStr = WeChatPayHelper.InstallXml(Parameters);
            //获取微信响应结果
            string sResponeXmlStr   = WeChatPayHelper.HttpPost(sUrl, sRequestXmlStr, Model, true);//申请退款需要证书
            var    ResponeParameter = WeChatPayHelper.GetDictionaryFromCDATAXml(sResponeXmlStr);

            //判断返回结果
            if (ResponeParameter["return_code"] == "SUCCESS")
            {
                if (WeChatPayHelper.CheckSign(ResponeParameter, Model.sPayKey))
                {     //验证签名正确
                    if (ResponeParameter["result_code"] == "SUCCESS")
                    { //申请退款成功
                        Respone.bSuccess = true;
                    }
                    else
                    {
                        Respone.bSuccess   = false;
                        Respone.sReturnMsg = ResponeParameter["err_code_des"];
                    }
                }
                else
                {
                    //签名验证失败
                    Respone.bSuccess   = false;
                    Respone.sReturnMsg = "签名验证失败";
                }
            }
            else
            {
                Respone.bSuccess   = false;
                Respone.sReturnMsg = ResponeParameter["return_msg"];
            }
            return(Respone);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 企业付款请求
        /// </summary>
        /// <param name="Model"></param>
        public WeChatPayRespone DoRequest(WeChatPayModel model)
        {
            WeChatPayByEnterpriseModel   Model   = model as WeChatPayByEnterpriseModel;
            WeChatPayByEnterpriseRespone Respone = new WeChatPayByEnterpriseRespone();
            var Parameters = new Dictionary <string, string>();

            Model.sNonceStr = WeChatPayHelper.GetRandomStr();//获取随机字符串
            Parameters.Add("mch_appid", Model.sAppId);
            Parameters.Add("mchid", Model.sMchId);
            Parameters.Add("nonce_str", Model.sNonceStr);
            Parameters.Add("partner_trade_no", Model.sOrderNo);
            Parameters.Add("openid", Model.sOpenId);
            Parameters.Add("check_name", "NO_CHECK");                   //不校验真实姓名
            Parameters.Add("amount", Model.iTotalFee.ToString());       //付款金额
            Parameters.Add("desc", Model.sDescribe);
            Parameters.Add("spbill_create_ip", Model.spbill_create_ip); //该IP同在商户平台设置的IP白名单中的IP没有关联,该IP可传用户端或者服务端的IP。
            //创建签名
            Model.sSign = WeChatPayHelper.CreateSign(Parameters, Model.sPayKey);
            Parameters.Add("sign", Model.sSign);
            string sRequestXmlStr = WeChatPayHelper.InstallXml(Parameters);
            //获取微信响应结果
            string sResponeXmlStr   = WeChatPayHelper.HttpPost(sUrl, sRequestXmlStr, model, true);//需要证书
            var    ResponeParameter = WeChatPayHelper.GetDictionaryFromCDATAXml(sResponeXmlStr);

            Respone.sReturnParams = ResponeParameter;
            //判断返回结果
            if (ResponeParameter["return_code"] == "SUCCESS")
            {
                if (ResponeParameter["result_code"] == "SUCCESS")
                {
                    Respone.bSuccess   = true;
                    Respone.sReturnMsg = ResponeParameter["return_msg"];
                }
                else
                {
                    Respone.bSuccess   = false;
                    Respone.sReturnMsg = ResponeParameter["err_code_des"];
                }
            }
            else
            {
                Respone.bSuccess   = false;
                Respone.sReturnMsg = ResponeParameter["return_msg"];
            }
            return(Respone);
        }
        /// <summary>
        /// 查询微信支付结果请求
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public WeChatPayRespone DoRequest(WeChatPayModel model)
        {
            WeChatPayQueryModel   Model   = model as WeChatPayQueryModel;
            WeChatPayQueryRespone Respone = new WeChatPayQueryRespone();
            var Parameters = new Dictionary <string, string>();

            Model.sNonceStr = WeChatPayHelper.GetRandomStr();//获取随机字符串
            Parameters.Add("appid", Model.sAppId);
            Parameters.Add("mch_id", Model.sMchId);
            Parameters.Add("transaction_id", Model.sTransactionNo);
            Parameters.Add("out_trade_no", Model.sOrderNo);
            Parameters.Add("nonce_str", Model.sNonceStr);
            //创建签名
            Model.sSign = WeChatPayHelper.CreateSign(Parameters, Model.sPayKey);
            Parameters.Add("sign", Model.sSign);
            string sRequestXmlStr = WeChatPayHelper.InstallXml(Parameters);
            //获取微信响应结果
            string sResponeXmlStr   = WeChatPayHelper.HttpPost(sUrl, sRequestXmlStr, null);
            var    ResponeParameter = WeChatPayHelper.GetDictionaryFromCDATAXml(sResponeXmlStr);

            Respone.sReturnParams = ResponeParameter;
            //判断返回结果
            if (ResponeParameter["return_code"] == "SUCCESS")
            {
                if (WeChatPayHelper.CheckSign(ResponeParameter, Model.sPayKey))
                {
                    if (ResponeParameter["result_code"] == "SUCCESS")
                    {//查询成功
                        if (ResponeParameter["trade_state"] == "SUCCESS")
                        {
                            Respone.bSuccess      = true;
                            Respone.sReturnMsg    = ResponeParameter["return_msg"];
                            Respone.TradeState    = true;//交易状态 支付成功
                            Respone.TradeStateMsg = ResponeParameter["trade_state"];
                        }
                        else
                        {
                            Respone.bSuccess      = true;
                            Respone.sReturnMsg    = ResponeParameter["return_msg"];
                            Respone.TradeState    = false;//交易状态
                            Respone.TradeStateMsg = ResponeParameter["trade_state"];
                        }
                    }
                    else
                    {
                        Respone.bSuccess      = false;
                        Respone.sReturnMsg    = ResponeParameter["err_code_des"];
                        Respone.TradeState    = false;
                        Respone.TradeStateMsg = Respone.sReturnMsg;
                    }
                }
                else
                {
                    //签名验证失败
                    Respone.bSuccess   = false;
                    Respone.sReturnMsg = "签名验证失败";
                    Respone.TradeState = false;
                }
            }
            else
            {
                Respone.bSuccess   = false;
                Respone.sReturnMsg = ResponeParameter["return_msg"];
            }
            return(Respone);
        }