Beispiel #1
0
        public override void ProcessNotify(UpdateOrderStateHandler UpdateOrderState, string appId)
        {
            var WxPayConfig = Configuration.GetAppPayConfig <Config.Sections.Pay.WXPay>(appId);


            Log.Info(this.GetType().ToString(), "ProcessNotify");
            WxPayData notifyData = GetNotifyData(WxPayConfig.KEY);

            //检查支付结果中transaction_id是否存在
            if (!notifyData.IsSet("transaction_id"))
            {
                //若transaction_id不存在,则立即返回结果给微信支付后台
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "支付结果中微信订单号不存在");
                Log.Error(this.GetType().ToString(), "The Pay result is error : " + res.ToXml());
                HttpContext.Current.Response.Write(res.ToXml());
                HttpContext.Current.Response.End();
            }

            string transaction_id = notifyData.GetValue("transaction_id").ToString();

            //查询订单,判断订单真实性
            if (!QueryOrder(transaction_id, appId))
            {
                //若订单查询失败,则立即返回结果给微信支付后台
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "订单查询失败");
                Log.Error(this.GetType().ToString(), "Order query failure : " + res.ToXml());
                HttpContext.Current.Response.Write(res.ToXml());
                HttpContext.Current.Response.End();
            }
            //查询订单成功
            else
            {
                string out_trade_no = notifyData.GetValue("out_trade_no").ToString();

                if (UpdateOrderState(out_trade_no, transaction_id))
                {
                    WxPayData res = new WxPayData();
                    res.SetValue("return_code", "SUCCESS");
                    res.SetValue("return_msg", "OK");
                    Log.Info(this.GetType().ToString(), "order query success : " + res.ToXml());
                    HttpContext.Current.Response.Write(res.ToXml());
                    HttpContext.Current.Response.End();
                }
                else
                {
                    WxPayData res = new WxPayData();
                    res.SetValue("return_code", "FAIL");
                    res.SetValue("return_msg", "更新订单:" + out_trade_no + "状态失败");
                    Log.Info(this.GetType().ToString(), "order query success : " + res.ToXml());
                    HttpContext.Current.Response.Write(res.ToXml());
                    HttpContext.Current.Response.End();
                }
            }
        }
Beispiel #2
0
 public virtual void ProcessNotify(UpdateOrderStateHandler UpdateOrderState, string appId)
 {
 }
Beispiel #3
0
        public override void ProcessNotify(UpdateOrderStateHandler UpdateOrderState, string appId)
        {
            var WxPayConfig = Configuration.GetAppPayConfig <Config.Sections.Pay.WXPay>(appId);


            WxPayData notifyData = GetNotifyData(WxPayConfig.KEY);

            //检查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());
                HttpContext.Current.Response.Write(res.ToXml());
                HttpContext.Current.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, appId);
            }
            catch (Exception ex)//若在调统一下单接口时抛异常,立即返回结果给微信支付后台
            {
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "统一下单失败");
                Log.Error(this.GetType().ToString(), "UnifiedOrder failure : " + res.ToXml());
                HttpContext.Current.Response.Write(res.ToXml());
                HttpContext.Current.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());
                HttpContext.Current.Response.Write(res.ToXml());
                HttpContext.Current.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());
            HttpContext.Current.Response.Write(data.ToXml());
            HttpContext.Current.Response.End();
        }