Beispiel #1
0
        /**
         * 生成扫描支付模式一URL
         * @param productId 商品ID
         * @return 模式一URL
         */
        public string GetPrePayUrl(string productId)
        {
            Log.Info(this.GetType().ToString(), "Native pay mode 1 url is producing...");

            WxPayData data = new WxPayData();

            data.SetValue("appid", WxPayConfig.GetConfig().GetAppID());  //公众帐号id
            data.SetValue("mch_id", WxPayConfig.GetConfig().GetMchID()); //商户号
            data.SetValue("time_stamp", WxPayApi.GenerateTimeStamp());   //时间戳
            data.SetValue("nonce_str", WxPayApi.GenerateNonceStr());     //随机字符串
            data.SetValue("product_id", productId);                      //商品ID
            data.SetValue("sign", data.MakeSign());                      //签名
            string str = ToUrlParams(data.GetValues());                  //转换为URL串
            string url = "weixin://wxpay/bizpayurl?" + str;

            Log.Info(this.GetType().ToString(), "Get native pay mode 1 url : " + url);
            return(url);
        }
Beispiel #2
0
        /**
         *
         * 从统一下单成功返回的数据中获取微信浏览器调起jsapi支付所需的参数,
         * 微信浏览器调起JSAPI时的输入参数格式如下:
         * {
         *   "appId" : "wx2421b1c4370ec43b",     //公众号名称,由商户传入
         *   "timeStamp":" 1395712654",         //时间戳,自1970年以来的秒数
         *   "nonceStr" : "e61463f8efa94090b1f366cccfbbb444", //随机串
         *   "package" : "prepay_id=u802345jgfjsdfgsdg888",
         *   "signType" : "MD5",         //微信签名方式:
         *   "paySign" : "70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名
         * }
         * @return string 微信浏览器调起JSAPI时的输入参数,json格式可以直接做参数用
         * 更详细的说明请参考网页端调起支付API:http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7
         *
         */
        public SortedDictionary <string, object> GetJsApiParameters(WxPayData unifiedOrderResult)
        {
            Log.Debug(this.GetType().ToString(), "JsApiPay::GetJsApiParam is processing...");

            WxPayData jsApiParam = new WxPayData();

            jsApiParam.SetValue("appId", unifiedOrderResult.GetValue("appid"));
            jsApiParam.SetValue("timeStamp", WxPayApi.GenerateTimeStamp());
            jsApiParam.SetValue("nonceStr", WxPayApi.GenerateNonceStr());
            jsApiParam.SetValue("package", "prepay_id=" + unifiedOrderResult.GetValue("prepay_id"));
            jsApiParam.SetValue("signType", "MD5");
            jsApiParam.SetValue("paySign", jsApiParam.MakeSign());

            string parameters = jsApiParam.ToJson();

            Log.Debug(this.GetType().ToString(), "Get jsApiParam : " + parameters);
            return(jsApiParam.GetValues());
        }
Beispiel #3
0
        private bool QueryOrder(string transaction_id, string appid, string mchid)
        {
            WxPayData req = new WxPayData();

            req.SetValue("transaction_id", transaction_id);
            req.SetValue("appid", appid);
            req.SetValue("mch_id", mchid);
            WxPayData res = WxPayApi.OrderQuery(req);

            if (res.GetValue("return_code").ToString() == "SUCCESS" && res.GetValue("result_code").ToString() == "SUCCESS")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        /**
         *
         * 获取收货地址js函数入口参数,详情请参考收货地址共享接口:http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_9
         * @return string 共享收货地址js函数需要的参数,json格式可以直接做参数使用
         */
        public string GetEditAddressParameters()
        {
            string parameter = "";

            try
            {
                //这个地方要注意,参与签名的是网页授权获取用户信息时微信后台回传的完整url
                string url = "http://host/path/queryString";

                //构造需要用SHA1算法加密的数据
                WxPayData signData = new WxPayData();
                signData.SetValue("appid", WxPayConfig.APPID);
                signData.SetValue("url", url);
                signData.SetValue("timestamp", WxPayApi.GenerateTimeStamp());
                signData.SetValue("noncestr", WxPayApi.GenerateNonceStr());
                signData.SetValue("accesstoken", access_token);
                string param = signData.ToUrl();

                Log.Debug(this.GetType().ToString(), "SHA1 encrypt param : " + param);
                //SHA1加密
                string addrSign = FormsAuthentication.HashPasswordForStoringInConfigFile(param, "SHA1");
                Log.Debug(this.GetType().ToString(), "SHA1 encrypt result : " + addrSign);

                //获取收货地址js函数入口参数
                WxPayData afterData = new WxPayData();
                afterData.SetValue("appId", WxPayConfig.APPID);
                afterData.SetValue("scope", "jsapi_address");
                afterData.SetValue("signType", "sha1");
                afterData.SetValue("addrSign", addrSign);
                afterData.SetValue("timeStamp", signData.GetValue("timestamp"));
                afterData.SetValue("nonceStr", signData.GetValue("noncestr"));

                //转为json格式
                parameter = afterData.ToJson();
                Log.Debug(this.GetType().ToString(), "Get EditAddressParam : " + parameter);
            }
            catch (Exception ex)
            {
                Log.Error(this.GetType().ToString(), ex.ToString());
                throw new WxPayException(ex.ToString());
            }

            return(parameter);
        }
Beispiel #5
0
        /**
         *
         * 从统一下单成功返回的数据中获取微信浏览器调起jsapi支付所需的参数,
         * 微信浏览器调起JSAPI时的输入参数格式如下:
         * {
         *   "appId" : "wx2421b1c4370ec43b",     //公众号名称,由商户传入
         *   "timeStamp":" 1395712654",         //时间戳,自1970年以来的秒数
         *   "nonceStr" : "e61463f8efa94090b1f366cccfbbb444", //随机串
         *   "package" : "prepay_id=u802345jgfjsdfgsdg888",
         *   "signType" : "MD5",         //微信签名方式:
         *   "paySign" : "70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名
         * }
         * @return string 微信浏览器调起JSAPI时的输入参数,json格式可以直接做参数用
         * 更详细的说明请参考网页端调起支付API:http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7
         *
         */
        private static string GetJsOrder(WxPayData data)
        {
            try
            {
                WxPayData jsApiParam = new WxPayData();
                jsApiParam.SetValue("appId", data.GetValue("appid"));
                jsApiParam.SetValue("timeStamp", WxPayApi.GenerateTimeStamp());
                jsApiParam.SetValue("nonceStr", WxPayApi.GenerateNonceStr());
                jsApiParam.SetValue("package", "prepay_id=" + data.GetValue("prepay_id"));
                jsApiParam.SetValue("signType", "MD5");
                jsApiParam.SetValue("paySign", jsApiParam.MakeSign());

                return(jsApiParam.ToJson());
            }
            catch (Exception)
            {
            }
            return(null);
        }
Beispiel #6
0
        private WxPayData UnifiedOrder(string openId, string productId)
        {
            //统一下单
            WxPayData req = new WxPayData();

            req.SetValue("body", "test");
            req.SetValue("attach", "test");
            req.SetValue("out_trade_no", WxPayApi.GenerateOutTradeNo());
            req.SetValue("total_fee", 1);
            req.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
            req.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));
            req.SetValue("goods_tag", "test");
            req.SetValue("trade_type", "NATIVE");
            req.SetValue("openid", openId);
            req.SetValue("product_id", productId);
            WxPayData result = WxPayApi.UnifiedOrder(req);

            return(result);
        }
Beispiel #7
0
        /***
         * 申请退款完整业务流程逻辑
         * @param transaction_id 微信订单号(优先使用)
         * @param out_trade_no 商户订单号
         * @param total_fee 订单总金额
         * @param refund_fee 退款金额
         * @return 退款结果(xml格式)
         */
        public static WxPayData Run(string transaction_id, string out_trade_no, string total_fee, string refund_fee)
        {
            WxPayData data = new WxPayData();

            if (!string.IsNullOrEmpty(transaction_id))//微信订单号存在的条件下,则已微信订单号为准
            {
                data.SetValue("transaction_id", transaction_id);
            }
            else//微信订单号不存在,才根据商户订单号去退款
            {
                data.SetValue("out_trade_no", out_trade_no);
            }

            data.SetValue("total_fee", int.Parse(total_fee));              //订单总金额
            data.SetValue("refund_fee", int.Parse(refund_fee));            //退款金额
            data.SetValue("out_refund_no", WxPayApi.GenerateOutTradeNo()); //随机生成商户退款单号
            data.SetValue("op_user_id", WxPayConfig.MCHID);                //操作员,默认为商户号

            return(WxPayApi.Refund(data));                                 //提交退款申请给API,接收返回数据
        }
Beispiel #8
0
        /***
         * 订单查询完整业务流程逻辑
         * @param transaction_id 微信订单号(优先使用)
         * @param out_trade_no 商户订单号
         * @return 订单查询结果(xml格式)
         */
        public static string Run(string transaction_id, string out_trade_no)
        {
            Log.Info("OrderQuery", "OrderQuery is processing...");

            WxPayData data = new WxPayData();

            if (!string.IsNullOrEmpty(transaction_id))//如果微信订单号存在,则以微信订单号为准
            {
                data.SetValue("transaction_id", transaction_id);
            }
            else//微信订单号不存在,才根据商户订单号去查单
            {
                data.SetValue("out_trade_no", out_trade_no);
            }

            WxPayData result = WxPayApi.OrderQuery(data);//提交订单查询请求给API,接收返回数据

            Log.Info("OrderQuery", "OrderQuery process complete, result : " + result.ToXml());
            return(result.ToPrintStr());
        }
Beispiel #9
0
        private AlipayOrder GetFee(string uid, string feeid, string from, string paytype, string key)
        {
            AlipayOrder         fee = null;
            DataMsg             m   = new DataMsg();
            BaseModel <DataSet> bs  = null;
            //创建订单
            IList <TextAndValue> tv = new List <TextAndValue>();

            tv.Add(new TextAndValue("@uid", uid));
            tv.Add(new TextAndValue("@feeid", feeid));
            tv.Add(new TextAndValue("@from", from));
            isFrom(tv, key);
            tv.Add(new TextAndValue("@paytype", paytype));           //1:支付宝,2:微信支付
            string out_trade_no = WxPayApi.GenerateOutTradeNo(from); //请与贵网站订单系统中的唯一订单号匹配

            tv.Add(new TextAndValue("@orderno", out_trade_no));
            bs = com.zgyey.sgspay.core.DataProxy.SGS_PAYProxyData.GetList(tv, "payapp..sgs_CreateOrder", "tb1", "tb2");

            DataSet ds = bs.result;

            m.code = int.Parse(ds.Tables[0].Rows[0][0].ToString());
            m.info = ds.Tables[0].Rows[0][1].ToString();
            if (m.code == 0)
            {
                fee = (
                    from x in ds.Tables[1].AsEnumerable()
                    select new AlipayOrder()
                {
                    feeid = x["fee_id"],
                    orderNo = x["order_no"],
                    feeName = x["fee_name"],
                    fee_des = x["fee_des"],
                    amount = x["fee_money"],
                    crttime = DateTime.Parse(x["crttime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"),
                    paytype = paytype
                }
                    ).ToList()[0];
            }

            return(fee);
        }
Beispiel #10
0
        /**
         *
         * 查询订单情况
         * @param string out_trade_no  商户订单号
         * @param int succCode         查询订单结果:0表示订单不成功,1表示订单成功,2表示继续查询
         * @return 订单查询接口返回的数据,参见协议接口
         */
        public static WxPayData Query(string out_trade_no, out int succCode, string AppId = "", string MacId = "", string key = "")
        {
            WxPayData queryOrderInput = new WxPayData();

            queryOrderInput.SetValue("out_trade_no", out_trade_no);
            WxPayData result = WxPayApi.OrderQuery(queryOrderInput, 20, AppId, MacId, key);

            if (result.GetValue("return_code").ToString() == "SUCCESS" &&
                result.GetValue("result_code").ToString() == "SUCCESS")
            {
                //支付成功
                if (result.GetValue("trade_state") != null && result.GetValue("trade_state").ToString() == "SUCCESS")
                {
                    succCode = 1;
                    return(result);
                }
                //用户支付中,需要继续查询
                else if (result.GetValue("trade_state") != null && result.GetValue("trade_state").ToString() == "USERPAYING")
                {
                    succCode = 2;
                    return(result);
                }
                else if (result.GetValue("trade_state") != null && result.GetValue("trade_state").ToString() == "NOTPAY")
                {
                    succCode = 3;
                    return(result);
                }
            }

            //如果返回错误码为“此交易订单号不存在”则直接认定失败
            if (result.GetValue("err_code") != null && result.GetValue("err_code").ToString() == "ORDERNOTEXIST")
            {
                succCode = 0;
            }
            else
            {
                //如果是系统错误,则后续继续
                succCode = 2;
            }
            return(result);
        }
Beispiel #11
0
        /**
         * 生成直接支付url,支付url有效期为2小时,模式二
         * @param rId 订单ID加密
         * @return 模式二URL
         */
        public string GetPayUrl(string rId)
        {
            //Log.Info(this.GetType().ToString(), "Native pay mode 2 url is producing...");

            rId = Rc.Common.DBUtility.DESEncrypt.Decrypt(rId);
            Model_UserOrder model = new Model_UserOrder();
            BLL_UserOrder   bll   = new BLL_UserOrder();

            model = bll.GetModelByOrderNo(rId);
            int total_fee = Convert.ToInt32(model.UserOrder_Amount * 100);

            WxPayData data = new WxPayData();

            data.SetValue("body", Rc.Cloud.Web.Common.pfunction.GetSubstring(model.Book_Name, 20, false));//商品描述 示例值:腾讯充值中心-QQ会员充值
            //data.SetValue("detail", model.Book_Name); // 商品详情
            //data.SetValue("attach", "test");//附加数据
            data.SetValue("out_trade_no", model.UserOrder_No); //订单号 //随机字符串WxPayApi.GenerateOutTradeNo()
            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", "jjj");//商品标记
            data.SetValue("trade_type", "NATIVE");                                                                                                 //交易类型
            data.SetValue("product_id", model.Book_Id);                                                                                            //商品ID
            data.SetValue("notify_url", string.Format("{0}/Payment/WxPayAPI/ResultNotifyPage.aspx", Rc.Cloud.Web.Common.pfunction.getHostPath())); //异步通知url

            WxPayData result = WxPayApi.UnifiedOrder(data);                                                                                        //调用统一下单接口
            //Log.Info(this.GetType().ToString(), "调用统一下单接口返回数据 : " + result.ToXml());
            string url = string.Empty;

            if (result.GetValue("return_code").ToString() == "SUCCESS" && result.GetValue("result_code").ToString() == "SUCCESS")
            {
                url = result.GetValue("code_url").ToString();//获得统一下单接口返回的二维码链接
            }
            else
            {
                Log.Error("Get native pay mode 2 url ", result.ToXml());
            }

            //Log.Info(this.GetType().ToString(), "Get native pay mode 2 url : " + url);
            return(url);
        }
Beispiel #12
0
        public string GetPayUrl1(string clientip, string orderCode, decimal totalAmount)
        {
            Log.Info(this.GetType().ToString(), "H5 pay url is producing...");
            WxPayData data = new WxPayData();

            data.SetValue("body", "汇款申请");                                                                                 //这里替换成你的数据
            data.SetValue("attach", "详见我的汇款订单");                                                                           //这里替换成你的数据
            data.SetValue("out_trade_no", orderCode);                                                                      //这里替换成你的数据  "商户订单号"
            data.SetValue("total_fee", ((int)totalAmount).ToString());                                                     //这里替换成你的数据  "总金额"
            data.SetValue("spbill_create_ip", clientip);                                                                   //终端IP
            data.SetValue("trade_type", "MWEB");                                                                           //交易类型
            data.SetValue("scene_info", "{'h5_info':{'type':'Wap','wap_url':'tjyy.fabeisha.cn','wap_name':'法贝莎总代订货系统'}}"); //场景信息
            WxPayData result = WxPayApi.UnifiedOrder(data);                                                                //调用统一下单接口

            LogHelper.Error("支付接口错误:" + result);

            string url = result.GetValue("mweb_url").ToString();//获得统一下单接口返回的链接

            Log.Info(this.GetType().ToString(), "Get H5 pay url : " + url);
            return(url);
        }
Beispiel #13
0
        public WxPayData GetUnifiedTransferResult(string orderNo, string userName, string desc)
        {
            WxPayData data = new WxPayData();

            data.SetValue("partner_trade_no", orderNo);
            data.SetValue("openid", openid);
            data.SetValue("re_user_name", userName);
            data.SetValue("amount", total_fee);
            data.SetValue("desc", desc);
            WxPayData result = WxPayApi.UnifiedTransfer(data);

            if (!result.IsSet("payment_no"))//(!result.IsSet("mch_appid") || !result.IsSet("mchid"))
            {
                Log.Error(this.GetType().ToString(), "UnifiedTransfer response error!");
                throw new WxPayException("UnifiedTransfer response error!");
            }
            unifiedOrderResult = result;
            return(result);
            //data.SetValue("mchid", WxPayConfig.MCHID);
            //data.SetValue()
        }
        }                                            //H5调起JS API参数
        protected void Page_Load(object sender, EventArgs e)
        {
            Log.Info(this.GetType().ToString(), "page load");
            if (!IsPostBack)
            {
                string openid    = Request.QueryString["openid"];
                string total_fee = Request.QueryString["total_fee"];
                //检测是否给当前页面传递了相关参数
                if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee))
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>");
                    Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit...");
                    submit.Visible = false;
                    return;
                }

                //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
                JsApiPay jsApiPay = new JsApiPay(this);
                jsApiPay.openid    = openid;
                jsApiPay.total_fee = int.Parse(total_fee);

                //JSAPI支付预处理
                try
                {
                    //统一下单
                    WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(WxPayApi.GenerateOutTradeNo());
                    //获取H5调起JS API参数
                    wxJsApiParam = jsApiPay.GetJsApiParameters(WxPayConfig.KEY);// 用于前端js调用
                    Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
                    //在页面上显示订单信息
                    Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>");
                    Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>");
                }
                catch (Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>");
                    submit.Visible = false;
                }
            }
        }
Beispiel #15
0
        /// <summary>
        /// 生成直接支付url,支付url有效期为2小时,模式二
        /// </summary>
        /// <param name="productId">商品ID</param>
        /// <param name="body">商品描述,此处为平台名称</param>
        /// <param name="out_trade_no">商户订单号</param>
        /// <param name="total_fee">充值金额,单位为分</param>
        /// <param name="appid">公众号id</param>
        /// <param name="mchid">微信商户id</param>
        /// <param name="paykey">微信商户支付密码</param>
        /// <param name="notify_url">回调地址</param>
        /// <param name="buyer">买家信息</param>
        /// <returns></returns>
        public string GetPayUrl(string productId, string body, string out_trade_no, int total_fee, string appid, string mchid, string paykey, string notify_url, string buyer)
        {
            Log.Info(this.GetType().ToString(), "Native pay mode 2 url is producing...");

            WxPayData data = new WxPayData();

            data.SetValue("body", body);                                          //商品描述
            data.SetValue("attach", buyer);                                       //附加数据
            data.SetValue("out_trade_no", out_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", "null");                                   //商品标记
            data.SetValue("trade_type", "NATIVE");                                //交易类型(JSAPI 公众号支付、NATIVE 扫码支付、APP APP支付)
            data.SetValue("product_id", productId);                               //商品ID

            WxPayData result = WxPayApi.UnifiedOrder(data, appid, mchid, paykey, WeiSha.Common.Server.IP, notify_url);
            string    url    = result.GetValue("code_url").ToString();//获得统一下单接口返回的二维码链接

            Log.Info(this.GetType().ToString(), "Get native pay mode 2 url : " + url);
            return(url);
        }
Beispiel #16
0
        /**
         * 生成直接支付url,支付url有效期为2小时,模式二
         * @param productId 商品ID
         * @return 模式二URL
         */
        public string GetPayUrl(string productId)
        {
            Log.Info(this.GetType().ToString(), "正在为您进入支付页面...");

            WxPayData data = new WxPayData();

            data.SetValue("body", "锐锋科技自动化产品");                                                   //商品描述
            data.SetValue("attach", "永久激活");                                                      //附加数据
            data.SetValue("out_trade_no", WxPayApi.GenerateOutTradeNo());                         //随机字符串
            data.SetValue("total_fee", 0.1);                                                      //总金额
            data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));                 //交易起始时间
            data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss")); //交易结束时间
            data.SetValue("goods_tag", "二次开发数字化中心");                                              //商品标记
            data.SetValue("trade_type", "NATIVE");                                                //交易类型
            data.SetValue("product_id", productId);                                               //商品ID

            WxPayData result = WxPayApi.UnifiedOrder(data);                                       //调用统一下单接口
            string    url    = result.GetValue("code_url").ToString();                            //获得统一下单接口返回的二维码链接

            Log.Info(this.GetType().ToString(), "Get native pay mode 2 url : " + url);
            return(url);
        }
Beispiel #17
0
        /**
         * 生成直接支付url,支付url有效期为2小时,模式二
         * @param productId 商品ID
         * @return 模式二URL
         */
        public string GetPayUrl(PaperInfo paperInfo, out string _orderNumber)
        {
            _orderNumber = WxPayApi.GenerateOutTradeNo();
            Log.Info(this.GetType().ToString(), "Native pay mode 2 url is producing...");
            int       price = Convert.ToInt32(paperInfo.Price * 100);
            WxPayData data  = new WxPayData();

            data.SetValue("body", "启源论文网");                                                       //商品描述
            data.SetValue("attach", "QYLW");                                                      //附加数据
            data.SetValue("out_trade_no", _orderNumber);                                          //随机字符串
            data.SetValue("total_fee", price);                                                    //总金额
            data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));                 //交易起始时间
            data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss")); //交易结束时间
            data.SetValue("goods_tag", "QY");                                                     //商品标记
            data.SetValue("trade_type", "NATIVE");                                                //交易类型
            data.SetValue("product_id", paperInfo.Code);                                          //商品ID
            WxPayData result = WxPayApi.UnifiedOrder(data);                                       //调用统一下单接口
            string    url    = result.GetValue("code_url").ToString();                            //获得统一下单接口返回的二维码链接

            Log.Info(this.GetType().ToString(), "Get native pay mode 2 url : " + url);
            return(url);
        }
Beispiel #18
0
        /**
         * 生成直接支付url,支付url有效期为2小时,模式二
         * @param productId 商品ID
         * @return 模式二URL
         */
        public string GetPayUrl(string productId, int price, string name, string tradeNo)
        {
            Log.Info(this.GetType().ToString(), "Native pay mode 2 url is producing...");

            WxPayData data = new WxPayData();

            data.SetValue("body", name);                                                          //商品描述
            data.SetValue("attach", name);                                                        //附加数据
            data.SetValue("out_trade_no", tradeNo);                                               //随机字符串
            data.SetValue("total_fee", price);                                                    //总金额
            data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));                 //交易起始时间
            data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss")); //交易结束时间
            data.SetValue("goods_tag", "jjj");                                                    //商品标记
            data.SetValue("trade_type", "NATIVE");                                                //交易类型
            data.SetValue("product_id", productId);                                               //商品ID

            WxPayData result = WxPayApi.UnifiedOrder(data);                                       //调用统一下单接口
            string    url    = result.GetValue("code_url").ToString();                            //获得统一下单接口返回的二维码链接

            Log.Info(this.GetType().ToString(), "Get native pay mode 2 url : " + url);
            return(url);
        }
Beispiel #19
0
        /// <summary>
        ///  调用统一下单,获得下单结果
        /// </summary>
        /// <param name="tracetype">支付方式,(JSAPI 公众号支付、NATIVE 扫码支付、APP APP支付、MWEB H5支付)</param>
        /// <param name="body">平台名称</param>
        /// <param name="out_trade_no">商户订单号</param>
        /// <param name="appid">公众号id</param>
        /// <param name="mchid">商户id</param>
        /// <param name="paykey">商户支付密钥</param>
        /// <param name="notify_url">返回域</param>
        /// <param name="buyer">付款方账号(学习系统账号,非微信账号)</param>
        /// <returns></returns>
        public WxPayData GetUnifiedOrderResult(string tracetype, string body, string out_trade_no, string appid, string mchid, string paykey, string notify_url, string buyer)
        {
            //统一下单
            WxPayData data = new WxPayData();

            //商品简单描述,该字段请按照规范传递,(商家名称-销售商品类目)https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_2
            body = !string.IsNullOrWhiteSpace(body) && body.Length > 100 ? body.Substring(0, 100) : body;
            data.SetValue("body", body);
            //附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
            data.SetValue("attach", buyer);
            //商户系统内部订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。
            //data.SetValue("out_trade_no", WxPayApi.GenerateOutTradeNo());
            data.SetValue("out_trade_no", out_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", "null");
            //支付方式(JSAPI 公众号支付、NATIVE 扫码支付、APP APP支付)
            data.SetValue("trade_type", tracetype);
            data.SetValue("openid", openid);
            if (!string.IsNullOrWhiteSpace(this.fingerprint))
            {
                data.SetValue("fingerprint", fingerprint);
            }

            WxPayData result = WxPayApi.UnifiedOrder(data, appid, mchid, paykey, WeiSha.Common.Browser.IP, notify_url);

            if (!result.IsSet("appid") || !result.IsSet("prepay_id") || result.GetValue("prepay_id").ToString() == "")
            {
                Log.Error(this, "UnifiedOrder response error!");
                throw new WxPayException("UnifiedOrder response error!");
            }

            unifiedOrderResult = result;
            return(result);
        }
Beispiel #20
0
        /**
         *
         * 查询订单
         * @param WxPayData inputObj 提交给查询订单API的参数
         * @param int timeOut 超时时间
         * @throws WxPayException
         * @return 成功时返回订单查询结果,其他抛异常
         */
        public static WxPayData OrderQuery(WxPayData inputObj, int timeOut = 6)
        {
            string url = "https://api.mch.weixin.qq.com/pay/orderquery";

            //检测必填参数
            if (!inputObj.IsSet("out_trade_no") && !inputObj.IsSet("transaction_id"))
            {
                throw new WxPayException("订单查询接口中,out_trade_no、transaction_id至少填一个!");
            }

            inputObj.SetValue("appid", WxPayConfig.GetConfig().GetAppID());  //公众账号ID
            inputObj.SetValue("mch_id", WxPayConfig.GetConfig().GetMchID()); //商户号
            inputObj.SetValue("nonce_str", WxPayApi.GenerateNonceStr());     //随机字符串
            inputObj.SetValue("sign_type", WxPayData.SIGN_TYPE_MD5);         //签名类型
            inputObj.SetValue("sign", inputObj.MakeSign());                  //签名


            string xml = inputObj.ToXml();

            var start = DateTime.Now;

            Log.Debug("WxPayApi", "OrderQuery request : " + xml);
            string response = HttpService.Post(xml, url, false, timeOut);//调用HTTP通信接口提交数据

            Log.Debug("WxPayApi", "OrderQuery response : " + response);

            var end      = DateTime.Now;
            int timeCost = (int)((end - start).TotalMilliseconds);//获得接口耗时

            //将xml格式的数据转化为对象以返回
            WxPayData result = new WxPayData();

            result.FromXml(response);

            ReportCostTime(url, timeCost, result);//测速上报

            return(result);
        }
Beispiel #21
0
        /**
         *
         * 查询订单
         * @param WxPayData inputObj 提交给查询订单API的参数
         * @param int timeOut 超时时间
         * @throws WxPayException
         * @return 成功时返回订单查询结果,其他抛异常
         */
        public static WxPayData OrderQuery(WxPayData inputObj, int timeOut = 6)
        {
            string url = "https://api.mch.weixin.qq.com/pay/orderquery";

            //检测必填参数
            if (!inputObj.IsSet("out_trade_no") && !inputObj.IsSet("transaction_id"))
            {
                throw new WxPayException("订单查询接口中,out_trade_no、transaction_id至少填一个!");
            }

            inputObj.SetValue("appid", WxPayConfig.APPID);               //公众账号ID
            inputObj.SetValue("mch_id", WxPayConfig.MCHID);              //商户号
            inputObj.SetValue("nonce_str", WxPayApi.GenerateNonceStr()); //随机字符串
            inputObj.SetValue("sign", inputObj.MakeSign());              //签名

            string xml      = inputObj.ToXml();
            string response = HttpService.Post(xml, url, false, timeOut);//调用HTTP通信接口提交数据
            //将xml格式的数据转化为对象以返回
            WxPayData result = new WxPayData();

            result.FromXml(response);
            return(result);
        }
Beispiel #22
0
        /// <summary>
        /// 通過商品ID,生成直接支付url,支付url有效期为2小时,模式二
        /// </summary>
        /// <param name="productId">商品ID</param>
        /// <returns>模式二URL</returns>
        public string GetPayUrl(string productId, out string strBusinessNo)
        {
            Log.Info(this.GetType().ToString(), "Native pay mode 2 url is producing...");

            WxPayData data = new WxPayData();

            data.SetValue("body", "汕頭大學智能儀錶繳費系統");                                                //商品描述
            data.SetValue("attach", "test");                                                      //附加数据
            data.SetValue("out_trade_no", WxPayApi.GenerateOutTradeNo());                         //随机字符串
            data.SetValue("total_fee", 1);                                                        //总金额,單位是:分
            data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));                 //交易起始时间
            data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss")); //交易结束时间
            data.SetValue("goods_tag", "YADA");                                                   //商品标记
            data.SetValue("trade_type", "NATIVE");                                                //交易类型
            data.SetValue("product_id", productId);                                               //商品ID

            WxPayData result = WxPayApi.UnifiedOrder(data);                                       //调用统一下单接口
            string    url    = result.GetValue("code_url").ToString();                            //获得统一下单接口返回的二维码链接

            strBusinessNo = data.GetValue("out_trade_no").ToString();
            Log.Info(this.GetType().ToString(), "Get native pay mode 2 url : " + url);
            return(url);
        }
Beispiel #23
0
        /**
         *
         * 查询订单情况
         * @param string out_trade_no  商户订单号
         * @param int succCode         查询订单结果:0表示订单不成功,1表示订单成功,2表示继续查询
         * @return 订单查询接口返回的数据,参见协议接口
         */
        public static WxPayData Query(WeiXinPayConfig weiXinPayConfig, string out_trade_no, out int succCode)
        {
            WxPayData queryOrderInput = new WxPayData();

            queryOrderInput.SetValue("out_trade_no", out_trade_no);
            WxPayData result = WxPayApi.OrderQuery(weiXinPayConfig, queryOrderInput);

            if (result.GetValue("return_code").ToString() == "SUCCESS" &&
                result.GetValue("result_code").ToString() == "SUCCESS")
            {
                //支付成功
                if (result.GetValue("trade_state").ToString() == "SUCCESS")
                {
                    succCode = 1;
                    return(result);
                }
                //用户支付中,需要继续查询
                else if (result.GetValue("trade_state").ToString() == "USERPAYING")
                {
                    succCode = 2;
                    return(result);
                }
            }

            //如果返回错误码为“此交易订单号不存在”则直接认定失败
            if (result.GetValue("err_code").ToString() == "ORDERNOTEXIST")
            {
                succCode = 0;
            }
            else
            {
                //如果是系统错误,则后续继续
                succCode = 2;
            }
            return(result);
        }
Beispiel #24
0
        public string GetPayUrl(string clientip, string orderCode, decimal totalAmount)
        {
            Log.Info(this.GetType().ToString(), "H5 pay url is producing...");
            WxPayData data = new WxPayData();

            data.SetValue("body", "商品描述");                             //这里替换成你的数据
            data.SetValue("attach", "详见我的订单");                         //这里替换成你的数据
            data.SetValue("out_trade_no", orderCode);                  //这里替换成你的数据  "商户订单号"
            data.SetValue("total_fee", ((int)totalAmount).ToString()); //这里替换成你的数据  "总金额"
            data.SetValue("spbill_create_ip", clientip);               //终端IP
            data.SetValue("trade_type", "MWEB");                       //交易类型
            data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
            data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));
            //data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
            //data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));
            data.SetValue("scene_info", "{'h5_info':{'type':'Wap','wap_url':'www.jst1314.cn','wap_name':'会员商城'}}"); //场景信息
            WxPayData result = WxPayApi.UnifiedOrder(data);                                                         //调用统一下单接口
            string    url    = result.GetValue("mweb_url").ToString();                                              //获得统一下单接口返回的链接

            Log.Info(this.GetType().ToString(), "Get H5 pay url : " + url);
            Log.Info(this.GetType().ToString(), url + "&redirect_url=http%3A%2F%2Fwww.jst1314.cn/mobile/mobilecenter");
            url = url + "&redirect_url=http%3A%2F%2Fwww.jst1314.cn/mobile/mobilecenter";
            return(url);
        }
Beispiel #25
0
        /**
         * 生成直接支付url,支付url有效期为2小时,模式二
         * @param productId 商品ID
         * @return 模式二URL
         */
        public string GetPayUrl(string Ordernum, int total_fee)
        {
            Log.Info(this.GetType().ToString(), "Native pay mode 2 url is producing...");
            string    NewOrderNum = WxPayApi.GetOutNewOrder(Ordernum);
            string    Sercond     = DateTime.Now.Millisecond.ToString();
            WxPayData data        = new WxPayData();

            data.SetValue("body", "华体健康");//商品描述
            //data.SetValue("attach", "商品支付");//附加数据
            //data.SetValue("out_trade_no", DateTime.Now.Millisecond + "$" + models.Ordernum + "NA");//随机字符串
            data.SetValue("out_trade_no", NewOrderNum);                                           //随机字符串
            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", "jjj");//商品标记
            data.SetValue("trade_type", "NATIVE");                                                //交易类型
            data.SetValue("product_id", Ordernum);                                                //商品ID

            WxPayData result = WxPayApi.UnifiedOrder(data);                                       //调用统一下单接口
            string    url    = result.GetValue("code_url").ToString();                            //获得统一下单接口返回的二维码链接

            Log.Info(this.GetType().ToString(), "Get native pay mode 2 url : " + url);
            return(url);
        }
        public WxPayData GetPayUrl(int total_fee, string productId, string productName, string flag, string remark)
        {
            Log.Info(this.GetType().ToString(), "Native pay mode 2 url is producing...");

            WxPayData data = new WxPayData();

            out_trade_no = WxPayApi.GenerateOutTradeNo();
            data.SetValue("body", productName);                                                   //商品描述
            data.SetValue("attach", remark);                                                      //附加数据
            data.SetValue("out_trade_no", out_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", flag);                                                     //商品标记
            data.SetValue("trade_type", "NATIVE");                                                //交易类型
            data.SetValue("product_id", productId);                                               //商品ID

            WxPayData result = WxPayApi.UnifiedOrder(data);                                       //调用统一下单接口

            result.SetValue("out_trade_no", out_trade_no);
            //  string url = result.GetValue("code_url").ToString();//获得统一下单接口返回的二维码链接
            //  Log.Info(this.GetType().ToString(), "Get native pay mode 2 url : " + url);
            return(result);
        }
Beispiel #27
0
        public override void ProcessNotify()
        {
            WxPayData notifyData = GetNotifyData();

            //检查openid和product_id是否返回
            if (!notifyData.IsSet("openid") || !notifyData.IsSet("product_id"))
            {
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "回调数据异常");
                Log.Info(this.GetType().ToString(), "The data WeChat post is error : " + res.ToXml());
                page.Response.Write(res.ToXml());
                page.Response.End();
            }

            //调统一下单接口,获得下单结果
            string    openid             = notifyData.GetValue("openid").ToString();
            string    product_id         = notifyData.GetValue("product_id").ToString();
            WxPayData unifiedOrderResult = new WxPayData();

            try
            {
                unifiedOrderResult = UnifiedOrder(openid, product_id);
            }
            catch (Exception)//若在调统一下单接口时抛异常,立即返回结果给微信支付后台
            {
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "统一下单失败");
                Log.Error(this.GetType().ToString(), "UnifiedOrder failure : " + res.ToXml());
                page.Response.Write(res.ToXml());
                page.Response.End();
            }

            //若下单失败,则立即返回结果给微信支付后台
            if (!unifiedOrderResult.IsSet("appid") || !unifiedOrderResult.IsSet("mch_id") || !unifiedOrderResult.IsSet("prepay_id"))
            {
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "统一下单失败");
                Log.Error(this.GetType().ToString(), "UnifiedOrder failure : " + res.ToXml());
                page.Response.Write(res.ToXml());
                page.Response.End();
            }

            //统一下单成功,则返回成功结果给微信支付后台
            WxPayData data = new WxPayData();

            data.SetValue("return_code", "SUCCESS");
            data.SetValue("return_msg", "OK");
            data.SetValue("appid", WxPayConfig.APPID);
            data.SetValue("mch_id", WxPayConfig.MCHID);
            data.SetValue("nonce_str", WxPayApi.GenerateNonceStr());
            data.SetValue("prepay_id", unifiedOrderResult.GetValue("prepay_id"));
            data.SetValue("result_code", "SUCCESS");
            data.SetValue("err_code_des", "OK");
            data.SetValue("sign", data.MakeSign(WxPayConfig.KEY));

            Log.Info(this.GetType().ToString(), "UnifiedOrder success , send data to WeChat : " + data.ToXml());
            page.Response.Write(data.ToXml());
            page.Response.End();
        }
Beispiel #28
0
        public WxPayData UnifiedOrder(WxPayData inputObj, int timeOut = 6)
        {
            string url = "https://api.mch.weixin.qq.com/pay/unifiedorder";

            //检测必填参数
            if (!inputObj.IsSet("out_trade_no"))
            {
                throw new WxPayException("缺少统一支付接口必填参数out_trade_no!");
            }
            else if (!inputObj.IsSet("body"))
            {
                throw new WxPayException("缺少统一支付接口必填参数body!");
            }
            else if (!inputObj.IsSet("total_fee"))
            {
                throw new WxPayException("缺少统一支付接口必填参数total_fee!");
            }
            else if (!inputObj.IsSet("trade_type"))
            {
                throw new WxPayException("缺少统一支付接口必填参数trade_type!");
            }

            //关联参数
            if (inputObj.GetValue("trade_type").ToString() == "JSAPI" && !inputObj.IsSet("openid"))
            {
                throw new WxPayException("统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!");
            }
            if (inputObj.GetValue("trade_type").ToString() == "NATIVE" && !inputObj.IsSet("product_id"))
            {
                throw new WxPayException("统一支付接口中,缺少必填参数product_id!trade_type为JSAPI时,product_id为必填参数!");
            }

            //异步通知url未设置,则使用配置文件中的url
            if (!inputObj.IsSet("notify_url"))
            {
                writeFile("url");
                inputObj.SetValue("notify_url", WxPayConfig.NOTIFY_URL);//异步通知url
                writeFile(inputObj.GetValue("notify_url").ToString());
            }

            inputObj.SetValue("appid", WxPayConfig.APPID);               //公众账号ID
            writeFile(inputObj.GetValue("appid").ToString());
            inputObj.SetValue("mch_id", WxPayConfig.MCHID);              //商户号
            writeFile(inputObj.GetValue("mch_id").ToString());
            inputObj.SetValue("spbill_create_ip", WxPayConfig.IP);       //终端ip
            writeFile(inputObj.GetValue("spbill_create_ip").ToString());
            inputObj.SetValue("nonce_str", WxPayApi.GenerateNonceStr()); //随机字符串
            writeFile(inputObj.GetValue("nonce_str").ToString());
            //签名
            inputObj.SetValue("sign", inputObj.MakeSign());
            writeFile(inputObj.GetValue("sign").ToString());
            string xml = inputObj.ToXml();

            writeFile(xml);

            var start = DateTime.Now;

            Log.Debug("WxPayApi", "UnfiedOrder request : " + xml);
            string response = HttpService.Post(xml, url, false, timeOut);

            Log.Debug("WxPayApi", "UnfiedOrder response : " + response);

            var end      = DateTime.Now;
            int timeCost = (int)((end - start).TotalMilliseconds);

            writeFile(response);
            WxPayData result = new WxPayData();

            result.FromXml(response);

            //ReportCostTime(url, timeCost, result);//测速上报

            return(result);
        }
Beispiel #29
0
        //public WxPayData unifiedOrderResult { get; set; }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            writeFile("coming2");
            string openid           = HttpContext.Current.Request.QueryString["openid"];
            string total_fee        = HttpContext.Current.Request.QueryString["jiage"];
            string goods            = HttpContext.Current.Request.QueryString["wupinglx"];
            string huowuguizhongF   = HttpContext.Current.Request.QueryString["huowuguizhongF"];
            string qujianhao        = HttpContext.Current.Request.QueryString["qujianhao"];
            string huojiahao        = HttpContext.Current.Request.QueryString["huojiahao"];
            string zhongliangleibie = HttpContext.Current.Request.QueryString["zhongliangleibie"];
            string name             = HttpContext.Current.Request.QueryString["shouhuoren"];
            string tel         = HttpContext.Current.Request.QueryString["tel"];
            string kuaididizhi = HttpContext.Current.Request.QueryString["kuaididizhi"];

            JsApiPay jsApiPay = new JsApiPay(context);

            jsApiPay.openid = openid;
            writeFile(jsApiPay.openid);
            jsApiPay.goods = goods;
            writeFile(jsApiPay.goods.ToString());
            jsApiPay.total_fee = int.Parse(total_fee);
            double price = jsApiPay.total_fee / 100.0;


            writeFile(jsApiPay.total_fee.ToString());

            //统一下单
            WxPayData data = new WxPayData();

            data.SetValue("body", goods);
            writeFile(data.GetValue("body").ToString());
            data.SetValue("attach", goods);
            writeFile(data.GetValue("attach").ToString());
            data.SetValue("out_trade_no", WxPayApi.GenerateOutTradeNo());

            string out_trade_no = data.GetValue("out_trade_no").ToString();

            writeFile(data.GetValue("out_trade_no").ToString());
            data.SetValue("total_fee", total_fee);
            writeFile(data.GetValue("total_fee").ToString());
            data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
            writeFile(data.GetValue("time_start").ToString());
            data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));
            writeFile(data.GetValue("time_expire").ToString());
            data.SetValue("goods_tag", goods);
            writeFile(data.GetValue("goods_tag").ToString());
            data.SetValue("trade_type", "JSAPI");
            writeFile(data.GetValue("trade_type").ToString());
            data.SetValue("openid", openid);
            writeFile(data.GetValue("openid").ToString());
            WxPayData result = UnifiedOrder(data);

            writeFile("over...");
            if (!result.IsSet("appid") || !result.IsSet("prepay_id") || result.GetValue("prepay_id").ToString() == "")
            {
                Log.Error(this.GetType().ToString(), "UnifiedOrder response error!");
                throw new WxPayException("UnifiedOrder response error!");
            }
            writeFile("overing");
            kyfly.BLL.yewu_dingdanxinxiB bll = new kyfly.BLL.yewu_dingdanxinxiB(context);
            string jiedanshijian             = DateTime.Now.Date.ToString();
            string peisongshijian            = DateTime.Now.Date.ToString();
            string xiuzhengshijian           = DateTime.Now.Date.ToString();



            WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); //此处有问题!

            context.Response.Write(jsApiPay.GetJsApiParameters());           //获取H5调起JS API参数

            bll.Add(name, tel, goods, "", kuaididizhi, "待付款", jiedanshijian, qujianhao, huojiahao, huowuguizhongF, zhongliangleibie, price.ToString(), "", peisongshijian, "", "", xiuzhengshijian, out_trade_no, "", "", "");
        }
Beispiel #30
0
        /// <summary>
        /// 刷卡支付完整业务流程逻辑
        /// </summary>
        /// <param name="body">商品描述</param>
        /// <param name="total_fee">总金额</param>
        /// <param name="auth_code">支付授权码</param>
        /// <returns>刷卡支付结果</returns>
        public static string Run(string body, string total_fee, string auth_code)
        {
            Log.Info("MicroPay", "Micropay is processing...");

            WxPayData data = new WxPayData();

            data.SetValue("auth_code", auth_code);                        //授权码
            data.SetValue("body", body);                                  //商品描述
            data.SetValue("total_fee", int.Parse(total_fee));             //总金额
            data.SetValue("out_trade_no", WxPayApi.GenerateOutTradeNo()); //产生随机的商户订单号

            WxPayData result = WxPayApi.Micropay(data, 10);               //提交被扫支付,接收返回结果

            //如果提交被扫支付接口调用失败,则抛异常
            if (!result.IsSet("return_code") || result.GetValue("return_code").ToString() == "FAIL")
            {
                string returnMsg = result.IsSet("return_msg") ? result.GetValue("return_msg").ToString() : "";
                Log.Error("MicroPay", "Micropay API interface call failure, result : " + result.ToXml());
                throw new WxPayException("Micropay API interface call failure, return_msg : " + returnMsg);
            }

            //签名验证
            result.CheckSign();
            Log.Debug("MicroPay", "Micropay response check sign success");

            //刷卡支付直接成功
            if (result.GetValue("return_code").ToString() == "SUCCESS" &&
                result.GetValue("result_code").ToString() == "SUCCESS")
            {
                Log.Debug("MicroPay", "Micropay business success, result : " + result.ToXml());
                return(result.ToPrintStr());
            }

            /****************************************************************
             * 剩下的都是接口调用成功,业务失败的情况
             * ****************************************************************/

            //1)业务结果明确失败
            if (result.GetValue("err_code").ToString() != "USERPAYING" &&
                result.GetValue("err_code").ToString() != "SYSTEMERROR")
            {
                Log.Error("MicroPay", "micropay API interface call success, business failure, result : " + result.ToXml());
                return(result.ToPrintStr());
            }

            //2)不能确定是否失败,需查单
            //用商户订单号去查单
            string out_trade_no = data.GetValue("out_trade_no").ToString();

            //确认支付是否成功,每隔一段时间查询一次订单,共查询10次
            int queryTimes = 10;//查询次数计数器

            while (queryTimes-- > 0)
            {
                //查询结果
                WxPayData queryResult = Query(out_trade_no, out int succResult);

                //如果需要继续查询,则等待2s后继续
                if (succResult == 2)
                {
                    Thread.Sleep(2000);
                    continue;
                }

                //查询成功,返回订单查询接口返回的数据
                else if (succResult == 1)
                {
                    Log.Debug("MicroPay", "Mircopay success, return order query result : " + queryResult.ToXml());
                    return(queryResult.ToPrintStr());
                }

                //订单交易失败,直接返回刷卡支付接口返回的结果,失败原因会在err_code中描述
                else
                {
                    Log.Error("MicroPay", "Micropay failure, return micropay result : " + result.ToXml());
                    return(result.ToPrintStr());
                }
            }

            //确认失败,则撤销订单
            Log.Error("MicroPay", "Micropay failure, Reverse order is processing...");
            if (!Cancel(out_trade_no))
            {
                Log.Error("MicroPay", "Reverse order failure");
                throw new WxPayException("Reverse order failure!");
            }

            return(result.ToPrintStr());
        }