Esempio n. 1
0
        public static bool WxPayRefundResult(string trade_no, string out_refund_no)
        {
            string    url       = "https://api.mch.weixin.qq.com/pay/refundquery";
            string    wx_appid  = PaymentConfig.WeiXinConfig.MobileAppID;
            string    wx_mch_id = PaymentConfig.WeiXinConfig.MobileMCHID;
            WxPayData data      = new WxPayData();

            data.SetValue("out_refund_no", out_refund_no);
            data.SetValue("appid", wx_appid);                                       //公众账号ID
            data.SetValue("mch_id", wx_mch_id);                                     //商户号
            data.SetValue("nonce_str", Guid.NewGuid().ToString().Replace("-", "")); //随机字符串
            data.SetValue("sign", data.MakeAPPSign());                              //签名

            string    xml      = data.ToXml();
            string    response = HttpService.Post(xml, url, true, 6, SSLCERT_PATH: PaymentConfig.WeiXinConfig.MobileSSLCERT_PATH, SSLCERT_PASSWORD: PaymentConfig.WeiXinConfig.MobileSSLCERT_PASSWORD);//调用HTTP通信接口提交数据到API
            WxPayData result   = new WxPayData();

            result.FromXml(response);
            if (result.IsSet("return_code"))
            {
                if (result.GetValue("return_code").Equals("SUCCESS"))
                {
                    return(true);
                }
                return(false);
            }
            return(false);
        }
Esempio n. 2
0
        public static Dictionary <string, string> H5WxPayUnifiedorder(string trade_no, string body, string total_fee)
        {
            string url        = "https://api.mch.weixin.qq.com/pay/unifiedorder";
            string wx_appid   = PaymentConfig.WeiXinConfig.MobileAppID;
            string wx_mch_id  = PaymentConfig.WeiXinConfig.MobileMCHID;
            string notify_url = WeixinConfig.app_notify_url;
            string Server_ID  = Utility.Tools.GetClientIP();
            //统一下单
            WxPayData data = new WxPayData();

            data.SetValue("body", body);
            data.SetValue("attach", "test");
            data.SetValue("out_trade_no", trade_no);
            data.SetValue("total_fee", total_fee);
            data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
            data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));
            data.SetValue("goods_tag", "yongyouapp");
            data.SetValue("trade_type", "MWEB");
            data.SetValue("notify_url", notify_url);                 //异步通知url
            data.SetValue("appid", wx_appid);                        //公众账号ID
            data.SetValue("mch_id", wx_mch_id);                      //商户号
            data.SetValue("spbill_create_ip", Server_ID);            //终端ip
            data.SetValue("nonce_str", WxPayApi.GenerateNonceStr()); //随机字符串
            data.SetValue("sign", data.MakeAPPSign());

            string    xml      = data.ToXml();
            string    response = HttpService.Post(xml, url, false, 6);
            WxPayData result   = new WxPayData();

            result.FromXml(response);
            if (!result.IsSet("mweb_url"))
            {
                throw new Exception("UnifiedOrder response error!");
            }
            WxPayData appApiParam = new WxPayData();

            appApiParam.SetValue("appid", wx_appid);
            appApiParam.SetValue("partnerid", wx_mch_id);
            appApiParam.SetValue("prepayid", result.GetValue("prepay_id"));
            appApiParam.SetValue("package", "Sign=WXPay");
            appApiParam.SetValue("noncestr", WxPayApi.GenerateNonceStr());
            appApiParam.SetValue("timestamp", WxPayApi.GenerateTimeStamp());
            //appApiParam.SetValue("signType", "MD5");
            appApiParam.SetValue("sign", appApiParam.MakeAPPSign());
            //通信成功
            var res = new Dictionary <string, string>
            {
                { "mweb_url", result.GetValue("mweb_url").ToString() },
            };

            //在服务器上签名
            return(res);
        }
Esempio n. 3
0
        public static bool WxPayRefundRequest(string trade_no, int total_fee, string out_refund_no, out string response)
        {
            response = string.Empty;
            if (string.IsNullOrEmpty(out_refund_no))
            {
                out_refund_no = WxPayApi.GenerateOutTradeNo();
            }
            string    url       = "https://api.mch.weixin.qq.com/secapi/pay/refund";
            string    wx_appid  = PaymentConfig.WeiXinConfig.MobileAppID;
            string    wx_mch_id = PaymentConfig.WeiXinConfig.MobileMCHID;
            WxPayData data      = new WxPayData();

            data.SetValue("out_trade_no", trade_no);
            data.SetValue("total_fee", total_fee);                                  //订单总金额
            data.SetValue("refund_fee", total_fee);                                 //退款金额
            data.SetValue("out_refund_no", out_refund_no);                          //随机生成商户退款单号
            data.SetValue("op_user_id", wx_mch_id);                                 //操作员,默认为商户号
            data.SetValue("appid", wx_appid);                                       //公众账号ID
            data.SetValue("mch_id", wx_mch_id);                                     //商户号
            data.SetValue("nonce_str", Guid.NewGuid().ToString().Replace("-", "")); //随机字符串
            data.SetValue("sign", data.MakeAPPSign());                              //签名

            string xml = data.ToXml();

            response = HttpService.Post(xml, url, true, 6, SSLCERT_PATH: PaymentConfig.WeiXinConfig.MobileSSLCERT_PATH, SSLCERT_PASSWORD: PaymentConfig.WeiXinConfig.MobileSSLCERT_PASSWORD);//调用HTTP通信接口提交数据到API
            WxPayData result = new WxPayData();

            result.FromXml(response);
            if (result.IsSet("return_code"))
            {
                if (result.GetValue("return_code").ToString().Equals("SUCCESS"))
                {
                    return(true);
                }
                return(false);
            }
            else
            {
                response = result.GetValue("return_msg").ToString();
            }
            return(false);
        }