示例#1
0
        public override PayProcessResult QueryPaymentResult(long transactionId, IOrderProcessor orderProcessor)
        {
            var res = new PayProcessResult();

            //--发起订单查询,判断订单真实性
            if (!QueryOrderSuccess(null, transactionId.ToString()))
            {
                res.ResultType = PayProcessResType.RequestSuccess;
                return(res);
            }

            //支付成功,调用订单处理逻辑
            res.ResultType = PayProcessResType.PaymentSuccess;
            if (orderProcessor == null)
            {
                return(res);
            }

            var orderHdRes = orderProcessor.OnOrderPaid(new OrderProcessPara
            {
                TransactionId = transactionId,
                GatewayTranId = null
            });

            LogService.InfoFormat("Wxpay rehandle pay:{0}, is success:{1}", transactionId, orderHdRes.IsSuccess());

            //记录处理失败消息
            res.ErrorMsg = orderHdRes.ErrorMsg;

            return(res);
        }
示例#2
0
        /// <summary>
        /// 处理支付结果通知
        /// </summary>
        protected NotifyProcessResult HandlePayNotify(HttpContext httpContext, IOrderProcessor orderProcessor)
        {
            //通知参数解析
            var notifyData = Notify.GetNotifyData(httpContext.Request, WxPayConfig, out var error);
            var handRes    = new NotifyProcessResult
            {
                ErrorMsg      = error,
                TransactionId = notifyData.GetValueStr("out_trade_no"),
                GatewayTranId = notifyData.GetValueStr("transaction_id")
            };

            if (error.NotNull())
            {
                return(handRes);
            }

            //回复结果
            var             replyRes = new WxPayData(WxPayConfig);
            Action <string> FailRes  = msg =>
            {
                replyRes.SetValue("return_code", "FAIL");
                replyRes.SetValue("return_msg", msg);
                handRes.ErrorMsg = msg;
                //handRes.ResultType = PayProcessResType.Error;
            };

            //检查支付结果中transaction_id是否存在
            if (handRes.GatewayTranId.NotNull() && notifyData.GetValueStr("result_code") == "SUCCESS")
            {
                //--发起订单查询,判断订单真实性
                if (QueryOrderSuccess(handRes.GatewayTranId))
                {
                    //订单处理逻辑
                    var orderHdRes = orderProcessor.OnOrderPaid(new OrderProcessPara
                    {
                        TransactionId = handRes.TransactionId.ToLong(),
                        GatewayTranId = handRes.GatewayTranId
                    });
                    if (orderHdRes.IsSuccess())
                    {
                        replyRes.SetValue("return_code", "SUCCESS");
                        replyRes.SetValue("return_msg", "OK");
                        httpContext.Response.WriteAsync(replyRes.ToXml());
                        //httpContext.Response.End();

                        LogService.DebugFormat("Wxpay process notify success:{0}", replyRes.ToXml());
                        //handRes.ResultType = PayProcessResType.PaymentSuccess;
                        return(handRes); //---成功直接返回
                    }

                    //订单处理失败返回非success,网关将持续通知
                    FailRes("订单支付处理失败: " + orderHdRes.ErrorMsg);
                }
                else //订单查询失败
                {
                    FailRes("订单查询失败");
                }
            }
            else
            {
                //若transaction_id不存在,则立即返回结果给微信支付后台
                FailRes("支付结果中微信订单号不存在");
            }

            //返回失败结果给微信支付后台
            httpContext.Response.WriteAsync(replyRes.ToXml());
            //httpContext.Response.End();

            LogService.ErrorFormat("Wxpay process notify failure:{0}", replyRes.ToXml());
            return(handRes);
        }