Commit d654ab8e authored by 吴春's avatar 吴春

提交支付回调

parent 0539f41e
......@@ -13,11 +13,7 @@ namespace Mall.Common.Pay.WeChatPat
{
private IHttpContextAccessor _accessor;
public ResponseHandler(IHttpContextAccessor accessor)
{
_accessor = accessor;
}
/// <summary>
/// 密钥
......@@ -37,13 +33,15 @@ namespace Mall.Common.Pay.WeChatPat
/// <summary>
/// 获取页面提交的get和post参数
/// </summary>
public ResponseHandler()
public ResponseHandler(IHttpContextAccessor _accessor)
{
xmlMap = new Hashtable();
if (_accessor.HttpContext.Request.ContentLength > 0)
{
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;
var xmlDoc = new XmlDocument();
xmlDoc.Load(reader);
......@@ -53,6 +51,7 @@ namespace Mall.Common.Pay.WeChatPat
{
xmlMap.Add(xnf.Name, xnf.InnerText);
}
Plugin.LogHelper.Write(null, "Notify支付回调:xmlMap-" + xmlMap.ToString());
}
//if (HttpContext.Current.Request.InputStream.Length > 0)
//{
......@@ -148,21 +147,21 @@ namespace Mall.Common.Pay.WeChatPat
return sign.Equals(xmlMap["sign"]);
}
/// <summary>
/// 获取编码方式
/// </summary>
/// <returns></returns>
protected virtual string GetCharset()
{
//return "UTF-8";
try
{
return HttpHelper.GetRequestEncoding(_accessor.HttpContext.Request).BodyName;
}
catch (Exception)
{
return "UTF-8";
}
}
///// <summary>
///// 获取编码方式
///// </summary>
///// <returns></returns>
//protected virtual string GetCharset()
//{
// //return "UTF-8";
// try
// {
// return HttpHelper.GetRequestEncoding(_accessor.HttpContext.Request).BodyName;
// }
// catch (Exception)
// {
// return "UTF-8";
// }
//}
}
}
......@@ -107,11 +107,11 @@ namespace Mall.WebApi.App_Code
/// 支付
/// </summary>
/// <returns></returns>
public BaseResult Notify()
public BaseResult Notify(IHttpContextAccessor accessor)
{
try
{
var res = new ResponseHandler();
var res = new ResponseHandler(accessor);
var tradeType = res.GetParameter("trade_type");
LogHelper.Write(null, "Notify支付回调:res-" + res.ToString());
......
......@@ -10,6 +10,7 @@ using Mall.Common.Plugin;
using Mall.Module.User;
using Mall.WebApi.Filter;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
......@@ -26,6 +27,17 @@ namespace Mall.WebApi.Controllers.AppletWeChat
UserCommonModule userCommonModule = new UserCommonModule();
private IHttpContextAccessor _accessor;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="accessor"></param>
public WeChatNotifyController(IHttpContextAccessor accessor)
{
_accessor = accessor;
}
/// <summary>
/// 订单支付回调
/// </summary>
......@@ -36,7 +48,7 @@ namespace Mall.WebApi.Controllers.AppletWeChat
{
var req = new RequestHandler();
App_Code.PayUtil PayUtil = new App_Code.PayUtil();
var result = PayUtil.Notify();
var result = PayUtil.Notify(_accessor);
if (result.IsSuccess)
{
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