This commit is contained in:
zpc 2025-09-26 15:36:45 +08:00
parent a0c22015d7
commit e39fee2352
3 changed files with 29 additions and 5 deletions

View File

@ -39,10 +39,11 @@ namespace CoreCms.Net.Core.Config
typeof(LogingSubscribe),
typeof(UserSubscribe),
# if DEBUG
typeof(WeChatPayNoticeSubscribe),
# endif
typeof(SendWxTemplateMessageSubscribe),
typeof(AfterSalesReviewSubscribe),
};
//显示日志

View File

@ -22,6 +22,9 @@ using CoreCms.Net.Caching.AutoMate.RedisCache;
using Essensoft.Paylink.WeChatPay;
using Essensoft.Paylink.WeChatPay.V2;
using Essensoft.Paylink.WeChatPay.V2.Notify;
using Microsoft.AspNetCore.Http;
using System.IO;
using System.Text;
namespace CoreCms.Net.Web.WebApi.Controllers.PayNotify
{
@ -59,18 +62,38 @@ namespace CoreCms.Net.Web.WebApi.Controllers.PayNotify
{
try
{
// 先读取原始请求 Body
Request.EnableBuffering(); // 允许多次读取流
string body = "";
using (var reader = new StreamReader(Request.Body, Encoding.UTF8, leaveOpen: true))
{
body = await reader.ReadToEndAsync();
Request.Body.Position = 0; // 重置流指针,保证后续能再次读取
}
// 打印原始请求内容(方便定位问题)
NLogUtil.WriteAll(LogLevel.Trace, LogType.Order, "微信支付成功回调原始请求", body);
NLogUtil.WriteAll(LogLevel.Trace, LogType.Order, "微信支付成功回调解析结果_optionsAccessor", JsonConvert.SerializeObject(_optionsAccessor.Value));
var notify = await _client.ExecuteAsync<WeChatPayUnifiedOrderNotify>(Request, _optionsAccessor.Value);
// 打印解析后的对象
NLogUtil.WriteAll(LogLevel.Trace, LogType.Order, "微信支付成功回调解析结果", JsonConvert.SerializeObject(notify));
if (notify.ReturnCode == WeChatPayCode.Success)
{
await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.WeChatPayNotice, JsonConvert.SerializeObject(notify));
return WeChatPayNotifyResult.Success;
}
NLogUtil.WriteAll(LogLevel.Trace, LogType.Order, "微信支付成功回调", JsonConvert.SerializeObject(notify));
//Request.Body
return NoContent();
}
catch (Exception ex)
{
NLogUtil.WriteAll(LogLevel.Trace, LogType.Order, "微信支付成功回调", "统一下单支付结果通知", ex);
NLogUtil.WriteAll(LogLevel.Trace, LogType.Order, "微信支付成功回调", "统一下单支付结果通知" + $"异常: {ex.Message}", ex);
return NoContent();
}
}

View File

@ -156,9 +156,9 @@
},
"PayCallBack": {
//
"WeChatPayUrl": "https://api.demo.coreshop.cn/Notify/WeChatPay/Unifiedorder",
"WeChatPayUrl": "https://sqqp.zpc-xy.com/Notify/WeChatPay/Unifiedorder",
//退
"WeChatRefundUrl": "https://api.demo.coreshop.cn/Notify/WeChatPay/Refund",
"WeChatRefundUrl": "https://sqqp.zpc-xy.com/Notify/WeChatPay/Refund",
//
"AlipayUrl": "",
//退