Commit d654ab8e authored by 吴春's avatar 吴春

提交支付回调

parent 0539f41e
...@@ -13,11 +13,7 @@ namespace Mall.Common.Pay.WeChatPat ...@@ -13,11 +13,7 @@ namespace Mall.Common.Pay.WeChatPat
{ {
private IHttpContextAccessor _accessor;
public ResponseHandler(IHttpContextAccessor accessor)
{
_accessor = accessor;
}
/// <summary> /// <summary>
/// 密钥 /// 密钥
...@@ -37,13 +33,15 @@ namespace Mall.Common.Pay.WeChatPat ...@@ -37,13 +33,15 @@ namespace Mall.Common.Pay.WeChatPat
/// <summary> /// <summary>
/// 获取页面提交的get和post参数 /// 获取页面提交的get和post参数
/// </summary> /// </summary>
public ResponseHandler() public ResponseHandler(IHttpContextAccessor _accessor)
{ {
xmlMap = new Hashtable(); xmlMap = new Hashtable();
if (_accessor.HttpContext.Request.ContentLength > 0) if (_accessor.HttpContext.Request.ContentLength > 0)
{ {
var reader = new System.IO.StreamReader(_accessor.HttpContext.Request.Body, Encoding.UTF8); var reader = new System.IO.StreamReader(_accessor.HttpContext.Request.Body, Encoding.UTF8);
Plugin.LogHelper.Write(null, "Notify支付回调:reader-" + reader.ToString());
_accessor.HttpContext.Request.Body.Position = 0; _accessor.HttpContext.Request.Body.Position = 0;
var xmlDoc = new XmlDocument(); var xmlDoc = new XmlDocument();
xmlDoc.Load(reader); xmlDoc.Load(reader);
...@@ -53,6 +51,7 @@ namespace Mall.Common.Pay.WeChatPat ...@@ -53,6 +51,7 @@ namespace Mall.Common.Pay.WeChatPat
{ {
xmlMap.Add(xnf.Name, xnf.InnerText); xmlMap.Add(xnf.Name, xnf.InnerText);
} }
Plugin.LogHelper.Write(null, "Notify支付回调:xmlMap-" + xmlMap.ToString());
} }
//if (HttpContext.Current.Request.InputStream.Length > 0) //if (HttpContext.Current.Request.InputStream.Length > 0)
//{ //{
...@@ -148,21 +147,21 @@ namespace Mall.Common.Pay.WeChatPat ...@@ -148,21 +147,21 @@ namespace Mall.Common.Pay.WeChatPat
return sign.Equals(xmlMap["sign"]); return sign.Equals(xmlMap["sign"]);
} }
/// <summary> ///// <summary>
/// 获取编码方式 ///// 获取编码方式
/// </summary> ///// </summary>
/// <returns></returns> ///// <returns></returns>
protected virtual string GetCharset() //protected virtual string GetCharset()
{ //{
//return "UTF-8"; // //return "UTF-8";
try // try
{ // {
return HttpHelper.GetRequestEncoding(_accessor.HttpContext.Request).BodyName; // return HttpHelper.GetRequestEncoding(_accessor.HttpContext.Request).BodyName;
} // }
catch (Exception) // catch (Exception)
{ // {
return "UTF-8"; // return "UTF-8";
} // }
} //}
} }
} }
...@@ -107,11 +107,11 @@ namespace Mall.WebApi.App_Code ...@@ -107,11 +107,11 @@ namespace Mall.WebApi.App_Code
/// 支付 /// 支付
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public BaseResult Notify() public BaseResult Notify(IHttpContextAccessor accessor)
{ {
try try
{ {
var res = new ResponseHandler(); var res = new ResponseHandler(accessor);
var tradeType = res.GetParameter("trade_type"); var tradeType = res.GetParameter("trade_type");
LogHelper.Write(null, "Notify支付回调:res-" + res.ToString()); LogHelper.Write(null, "Notify支付回调:res-" + res.ToString());
......
...@@ -10,6 +10,7 @@ using Mall.Common.Plugin; ...@@ -10,6 +10,7 @@ using Mall.Common.Plugin;
using Mall.Module.User; using Mall.Module.User;
using Mall.WebApi.Filter; using Mall.WebApi.Filter;
using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
...@@ -26,6 +27,17 @@ namespace Mall.WebApi.Controllers.AppletWeChat ...@@ -26,6 +27,17 @@ namespace Mall.WebApi.Controllers.AppletWeChat
UserCommonModule userCommonModule = new UserCommonModule(); UserCommonModule userCommonModule = new UserCommonModule();
private IHttpContextAccessor _accessor;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="accessor"></param>
public WeChatNotifyController(IHttpContextAccessor accessor)
{
_accessor = accessor;
}
/// <summary> /// <summary>
/// 订单支付回调 /// 订单支付回调
/// </summary> /// </summary>
...@@ -36,7 +48,7 @@ namespace Mall.WebApi.Controllers.AppletWeChat ...@@ -36,7 +48,7 @@ namespace Mall.WebApi.Controllers.AppletWeChat
{ {
var req = new RequestHandler(); var req = new RequestHandler();
App_Code.PayUtil PayUtil = new App_Code.PayUtil(); App_Code.PayUtil PayUtil = new App_Code.PayUtil();
var result = PayUtil.Notify(); var result = PayUtil.Notify(_accessor);
if (result.IsSuccess) if (result.IsSuccess)
{ {
var dic = ((Dictionary<string, string>)result.Data); var dic = ((Dictionary<string, string>)result.Data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment