diff --git a/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs b/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs index 70f05ae..1f04a35 100644 --- a/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs +++ b/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs @@ -39,10 +39,11 @@ namespace CoreCms.Net.Core.Config typeof(LogingSubscribe), typeof(UserSubscribe), -# if DEBUG + typeof(WeChatPayNoticeSubscribe), -# endif + typeof(SendWxTemplateMessageSubscribe), + typeof(AfterSalesReviewSubscribe), }; //显示日志 diff --git a/CoreCms.Net.Web.WebApi/Controllers/PayNotify/WeChatPayController.cs b/CoreCms.Net.Web.WebApi/Controllers/PayNotify/WeChatPayController.cs index f3599d7..c39e853 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/PayNotify/WeChatPayController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/PayNotify/WeChatPayController.cs @@ -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(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(); } } diff --git a/CoreCms.Net.Web.WebApi/appsettings.json b/CoreCms.Net.Web.WebApi/appsettings.json index f99de77..3f82c9a 100644 --- a/CoreCms.Net.Web.WebApi/appsettings.json +++ b/CoreCms.Net.Web.WebApi/appsettings.json @@ -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": "", //支付宝退款回调