예제 #1
0
        public BaseResult Notify(WeChatParam param,HttpContextBase context)
        {
            var sbResult = new StringBuilder();
            try
            {
                sbResult.Append("@参数:" + JsonConvert.SerializeObject(param) + "\r\n");
                sbResult.Append("@HttpContextLength:" + context.Request.InputStream.Length + "\r\n");
                sbResult.Append("@开始创建ResponseHandler实例\r\n");
                var res = new ResponseHandler(context);
                sbResult.Append("@创建ResponseHandler实例成功\r\n");
                res.SetKey(GetConfig.GetKey(param));
                sbResult.Append("@设置密钥成功\r\n");
                var error = "";
                //判断签名
                if (res.IsWXsign(out error))
                {
                    sbResult.Append("@判断签名成功\r\n");
                    #region 参数
                    var returnCode = res.GetParameter("return_code");
                    //返回信息,如非空,为错误原因签名失败参数格式校验错误
                    var returnMsg = res.GetParameter("return_msg");
                    var appid = res.GetParameter("appid");

                    //以下字段在 return_code 为 SUCCESS 的时候有返回--------------------------------
                    var mchId = res.GetParameter("mch_id");
                    var deviceInfo = res.GetParameter("device_info");
                    var nonceStr = res.GetParameter("nonce_str");
                    var resultCode = res.GetParameter("result_code");
                    var errCode = res.GetParameter("err_code");
                    var errCodeDes = res.GetParameter("err_code_des");

                    //以下字段在 return_code 和 result_code 都为 SUCCESS 的时候有返回---------------
                    var openid = res.GetParameter("openid");
                    //Y-关注,N-未关注,仅在公众账号类型支付有效
                    var isSubscribe = res.GetParameter("is_subscribe");
                    var tradeType = res.GetParameter("trade_type");
                    //银行类型,采用字符串类型的银行标识
                    var bankType = res.GetParameter("bank_type");
                    var totalFee = res.GetParameter("total_fee");
                    //货币类型,符合 ISO 4217 标准的三位字母代码,默认人民币:CNY
                    var feeType = res.GetParameter("fee_type");
                    //微信支付订单号
                    var transactionId = res.GetParameter("transaction_id");
                    //商户系统的订单号,与请求一致。
                    var outTradeNo = res.GetParameter("out_trade_no");
                    var attach = res.GetParameter("attach");
                    //格 式 为yyyyMMddhhmmss
                    var timeEnd = res.GetParameter("time_end");
                    #endregion
                    sbResult.Append("@取所有参数成功\r\n");
                    //支付成功
                    if (!outTradeNo.Equals("") && returnCode.Equals("SUCCESS") && resultCode.Equals("SUCCESS"))
                    {
                        sbResult.Append("@支付成功\r\n" + outTradeNo);
                        //LogHelper.WriteLog("支付回调:", sbResult.ToString() + "notify > success \r\n",EnumService.LogType.Debug);
                        //在外面回写订单
                        return new BaseResult()
                        {
                            IsSuccess = true,
                            Data = new Dictionary<string, string>
                            {
                                {"OrderNumber", outTradeNo},
                                {"WeChat", openid},
                            }
                        };
                    }
                    else
                    {
                        sbResult.Append("@支付失败\r\n");
                        //LogHelper.WriteLog("支付回调:", sbResult.ToString() + "notify > total_fee= " + totalFee + " \r\n  err_code_des= " + errCodeDes + " \r\n  result_code= " + resultCode + " \r\n", EnumService.LogType.Exception);
                    }
                }
                else
                {
                    sbResult.Append("@判断签名失败\r\n");
                    //LogHelper.WriteLog("支付回调:",sbResult.ToString() + "notify > isWXsign= false \r\n" + error, EnumService.LogType.Exception);
                }
            }
            catch (Exception ex)
            {
                //LogHelper.WriteLog("支付回调:",sbResult.ToString() + "notify > ex=" + ex.Message + @ex.StackTrace + @ex.InnerException + " \r\n",  EnumService.LogType.Exception);
            }
            return new BaseResult() { IsSuccess = false };
        }
예제 #2
0
        public BaseResult Notify(WeChatParam param, HttpContextBase context)
        {
            var sbResult = new StringBuilder();

            try
            {
                sbResult.Append("@参数:" + JsonConvert.SerializeObject(param) + "\r\n");
                sbResult.Append("@HttpContextLength:" + context.Request.InputStream.Length + "\r\n");
                sbResult.Append("@开始创建ResponseHandler实例\r\n");
                var res = new ResponseHandler(context);
                sbResult.Append("@创建ResponseHandler实例成功\r\n");
                res.SetKey(GetConfig.GetKey(param));
                sbResult.Append("@设置密钥成功\r\n");
                var error = "";
                //判断签名
                if (res.IsWXsign(out error))
                {
                    sbResult.Append("@判断签名成功\r\n");
                    #region 参数
                    var returnCode = res.GetParameter("return_code");
                    //返回信息,如非空,为错误原因签名失败参数格式校验错误
                    var returnMsg = res.GetParameter("return_msg");
                    var appid     = res.GetParameter("appid");

                    //以下字段在 return_code 为 SUCCESS 的时候有返回--------------------------------
                    var mchId      = res.GetParameter("mch_id");
                    var deviceInfo = res.GetParameter("device_info");
                    var nonceStr   = res.GetParameter("nonce_str");
                    var resultCode = res.GetParameter("result_code");
                    var errCode    = res.GetParameter("err_code");
                    var errCodeDes = res.GetParameter("err_code_des");

                    //以下字段在 return_code 和 result_code 都为 SUCCESS 的时候有返回---------------
                    var openid = res.GetParameter("openid");
                    //Y-关注,N-未关注,仅在公众账号类型支付有效
                    var isSubscribe = res.GetParameter("is_subscribe");
                    var tradeType   = res.GetParameter("trade_type");
                    //银行类型,采用字符串类型的银行标识
                    var bankType = res.GetParameter("bank_type");
                    var totalFee = res.GetParameter("total_fee");
                    //货币类型,符合 ISO 4217 标准的三位字母代码,默认人民币:CNY
                    var feeType = res.GetParameter("fee_type");
                    //微信支付订单号
                    var transactionId = res.GetParameter("transaction_id");
                    //商户系统的订单号,与请求一致。
                    var outTradeNo = res.GetParameter("out_trade_no");
                    var attach     = res.GetParameter("attach");
                    //格 式 为yyyyMMddhhmmss
                    var timeEnd = res.GetParameter("time_end");
                    #endregion
                    sbResult.Append("@取所有参数成功\r\n");
                    //支付成功
                    if (!outTradeNo.Equals("") && returnCode.Equals("SUCCESS") && resultCode.Equals("SUCCESS"))
                    {
                        sbResult.Append("@支付成功\r\n" + outTradeNo);
                        //LogHelper.WriteLog("支付回调:", sbResult.ToString() + "notify > success \r\n",EnumService.LogType.Debug);
                        //在外面回写订单
                        return(new BaseResult()
                        {
                            IsSuccess = true,
                            Data = new Dictionary <string, string>
                            {
                                { "OrderNumber", outTradeNo },
                                { "WeChat", openid },
                            }
                        });
                    }
                    else
                    {
                        sbResult.Append("@支付失败\r\n");
                        //LogHelper.WriteLog("支付回调:", sbResult.ToString() + "notify > total_fee= " + totalFee + " \r\n  err_code_des= " + errCodeDes + " \r\n  result_code= " + resultCode + " \r\n", EnumService.LogType.Exception);
                    }
                }
                else
                {
                    sbResult.Append("@判断签名失败\r\n");
                    //LogHelper.WriteLog("支付回调:",sbResult.ToString() + "notify > isWXsign= false \r\n" + error, EnumService.LogType.Exception);
                }
            }
            catch (Exception ex)
            {
                //LogHelper.WriteLog("支付回调:",sbResult.ToString() + "notify > ex=" + ex.Message + @ex.StackTrace + @ex.InnerException + " \r\n",  EnumService.LogType.Exception);
            }
            return(new BaseResult()
            {
                IsSuccess = false
            });
        }