private OrderNotifyUrlReq GetOrderNotifyUrlXml()
        {
            OrderNotifyUrlReq request = new OrderNotifyUrlReq();

            if (HttpContext.Current != null)
            {
                StreamReader reader  = new StreamReader(HttpContext.Current.Request.InputStream);
                String       xmlData = reader.ReadToEnd();
                request = XmlUtils.Deserialize <OrderNotifyUrlReq>(xmlData);
            }
            else
            {
                LogHelper.Info("/api/order/GetOrderNotifyUrlXml=>HttpContext.Current ==null");
            }
            return(request);
        }
        public HttpResponseMessage OrderPayNotifyUrl()
        {
            OrderNotifyUrlReq request = GetOrderNotifyUrlXml();

            LogHelper.Info("调用支付通知地址...");
            string strRlt = @"<xml><return_code><![CDATA[{SUCCESS}]]></return_code><return_msg><![CDATA[{Msg}]]></return_msg></xml>";
            string errmsg = string.Empty;

            if (request?.return_code == "SUCCESS")
            {
                var blSign = CheckSign(request);

                if (request.result_code == "SUCCESS")
                {
                    OrderUpdateStatusSuccess(new OrderPayUpdateRequest()
                    {
                        orderNo = request.out_trade_no, buyerEmail = "", sellerEmail = ""
                    }, out errmsg);
                    if (!string.IsNullOrEmpty(errmsg))
                    {
                        LogHelper.Error($"/order/OrderPayNotifyUrl,订单:{request.out_trade_no} 支付完成状态更新异常:{errmsg}");
                    }
                }
                else
                {
                    strRlt = strRlt.Replace("{SUCCESS}", "FAIL").Replace("{Msg}", $"{request.err_code_des };错误代码{request.err_code }");
                }
                strRlt = strRlt.Replace("{SUCCESS}", "SUCCESS").Replace("{Msg}", "OK");
                LogHelper.Info($"调用微信支付通知地址成功... 返回消息:{strRlt}");
            }
            else
            {
                LogHelper.Info($"调用微信支付通知地址错误...{request.return_msg}");
                strRlt = strRlt.Replace("{SUCCESS}", "FAIL").Replace("{Msg}", request.return_msg);
            }

            return(new HttpResponseMessage()
            {
                Content = new StringContent(strRlt)
            });
        }
        private bool CheckSign(OrderNotifyUrlReq request)
        {
            WeiXinPayConfig config = new WeiXinPayConfig();

            config.AppId      = ConfigUtils.WxAppId;
            config.PaySecret  = ConfigUtils.WxPaySecret;
            config.PartnerKey = ConfigUtils.WxPayMchId;
            WeiXinPayClient             client     = new WeiXinPayClient(config);
            SortedList <String, String> postParams = new SortedList <String, String>();

            postParams.Add("appid", request.appid);
            postParams.Add("mch_id", request.mch_id);
            postParams.Add("nonce_str", request.nonce_str);
            postParams.Add("body", "性之助商城购物");
            postParams.Add("out_trade_no", request.out_trade_no);
            postParams.Add("total_fee", request.total_fee.ToString());
            postParams.Add("spbill_create_ip", HttpContext.Current.Request.UserHostAddress);
            postParams.Add("notify_url", ConstDataValues.WxOrderPayNotifyUrl);
            postParams.Add("trade_type", "JSAPI");//APP
            string sign = client.CreateSign(postParams);

            return(request.sign == sign);
        }