From 630f4fb37eabb6da0fe34bc398d8a35a88f200a9 Mon Sep 17 00:00:00 2001 From: zpc Date: Tue, 27 Aug 2024 01:17:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=94=AF=E4=BB=98=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HuanMeng.MiaoYu.Code/Order/OrderBLL.cs | 2 +- .../Controllers/PayController.cs | 28 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Order/OrderBLL.cs b/src/0-core/HuanMeng.MiaoYu.Code/Order/OrderBLL.cs index f456808..4752b7b 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Order/OrderBLL.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Order/OrderBLL.cs @@ -49,7 +49,7 @@ namespace HuanMeng.MiaoYu.Code.Order { var ip = HttpContextAccessor.HttpContext.GetClientIpAddress(); var price = product.Price; - var payment = PaymentExtend.GetPayment(paymentMethod); + var payment = PaymentExtend.GetPayment(paymentMethod, this); UserInfoBLL userInfo = new UserInfoBLL(Dao, _UserId); if (userInfo.User.IsTest ?? false) { diff --git a/src/2-api/HuanMeng.MiaoYu.WebPayApi/Controllers/PayController.cs b/src/2-api/HuanMeng.MiaoYu.WebPayApi/Controllers/PayController.cs index 1ed1031..77eeed3 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebPayApi/Controllers/PayController.cs +++ b/src/2-api/HuanMeng.MiaoYu.WebPayApi/Controllers/PayController.cs @@ -1,20 +1,30 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System.Text; + namespace HuanMeng.MiaoYu.WebPayApi.Controllers { [Route("api/[controller]/")] [ApiController] - public class PayController : ControllerBase + public class PayController(ILogger logger, IHttpContextAccessor httpContextAccessor) : ControllerBase { /// /// /// /// [HttpGet("{tenant?}/{pay?}/{orderId?}")] - public string Get(string? tenant, string? pay, string? orderId) + public async Task Get(string? tenant, string? pay, string? orderId) { - return "ok"; + var context = httpContextAccessor.HttpContext; + context.Request.EnableBuffering(); // Enable buffering to allow the body to be read multiple times + using (var reader = new StreamReader(context.Request.Body, Encoding.UTF8, true, 1024, leaveOpen: true)) + { + var bodyContent = await reader.ReadToEndAsync(); + logger.LogInformation($"请求支付回调接口,请求路径: {context.Request.Path}, 请求Body: {bodyContent}"); + context.Request.Body.Position = 0; + } + return $"success"; } /// @@ -22,9 +32,17 @@ namespace HuanMeng.MiaoYu.WebPayApi.Controllers /// /// [HttpPost("{tenant?}/{pay?}/{orderId?}")] - public string Post(string? tenant, string? pay,string? orderId) + public async Task Post(string? tenant, string? pay, string? orderId) { - return $"ok;{pay},{orderId}"; + var context = httpContextAccessor.HttpContext; + context.Request.EnableBuffering(); // Enable buffering to allow the body to be read multiple times + using (var reader = new StreamReader(context.Request.Body, Encoding.UTF8, true, 1024, leaveOpen: true)) + { + var bodyContent = await reader.ReadToEndAsync(); + logger.LogInformation($"请求支付回调接口,请求路径: {context.Request.Path}, 请求Body: {bodyContent}"); + context.Request.Body.Position = 0; + } + return $"success"; } } }