Example #1
0
        /// <summary>
        /// 刷卡支付
        /// </summary>
        public static MicropayResponseModel Micropay(MicropayModel requestModel)
        {
            WxPayData data = new WxPayData();

            data.SetValue("auth_code", requestModel.auth_code);           //授权码
            data.SetValue("body", requestModel.body);                     //商品描述
            data.SetValue("total_fee", requestModel.total_fee);           //总金额
            data.SetValue("out_trade_no", WxPayApi.GenerateOutTradeNo()); //产生随机的商户订单号
            data.SetValue("device_info", requestModel.device_info);
            LogUtil.WriteWxpayLog("刷卡支付请求", "请求参数", data.ToJson());
            WxPayData result = WxPayApi.Micropay(data, 10); //提交被扫支付,接收返回结果

            //如果提交被扫支付接口调用失败,则抛异常
            if (!result.IsSet("return_code") || result.GetValue("return_code").ToString() == ReturnCode.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("微信接口调用出错 : " + returnMsg);
            }
            LogUtil.WriteWxpayLog("刷卡支付响应", "响应参数", result.ToJson());
            //签名验证
            result.CheckSign();
            MicropayResponseModel responseModel = LitJson.JsonMapper.ToObject <MicropayResponseModel>(result.ToJson());

            responseModel.out_trade_no = responseModel.out_trade_no ?? data.GetValue("out_trade_no").ToString();
            //if (responseModel.return_code == ReturnCode.FAIL) throw new WxPayException(responseModel.return_msg);
            return(responseModel);
        }
Example #2
0
        /// <summary>
        /// 微信刷卡支付
        /// </summary>
        /// <param name="micropayModel">刷卡支付请求</param>
        /// <param name="payOverCallBack">支付结束回调函数</param>
        /// <param name="payStateChangeCallBack">支付状态改变回调函数</param>
        public void Micropay(MicropayModel micropayModel, Action <bool, MicropayResponseModel> payOverCallBack, Action <bool, OrderQueryResponseModel> payStateChangeCallBack)
        {
            MicropayResponseModel response = ServiceUtil.WxPayClient.Micropay(micropayModel);

            ServiceUtil.WxPayClient.Close();
            if (response.result_code == ResultCode.SUCCESS)
            {//接口调用成功,业务成功
                payOverCallBack(true, response);
                return;
            }
            #region 1.业务结果确定处理失败
            if (response.err_code != ErrorCode.SYSTEMERROR && response.err_code != ErrorCode.USERPAYING)
            {
                payOverCallBack(false, response);
                return;
            }
            #endregion

            #region 2.不能确定是否失败,需查单
            //用商户订单号去查单
            string out_trade_no = response.out_trade_no;
            OrderQueryResponseModel orderQueryResponse = new OrderQueryResponseModel();
            orderQueryResponse = OrderQuery(new WxpayModel.OrderQueryModel()
            {
                out_trade_no = out_trade_no
            }, payStateChangeCallBack);
            #endregion
        }