diff --git a/src/2-api/HuanMeng.MiaoYu.WebPayApi/Controllers/PayController.cs b/src/2-api/HuanMeng.MiaoYu.WebPayApi/Controllers/PayController.cs index be14dea..2d5e188 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebPayApi/Controllers/PayController.cs +++ b/src/2-api/HuanMeng.MiaoYu.WebPayApi/Controllers/PayController.cs @@ -54,8 +54,16 @@ namespace HuanMeng.MiaoYu.WebPayApi.Controllers [HttpPost("{tenant?}/{pay?}/{orderId?}/{sign?}")] public async Task Post(string? tenant, string? pay, string? orderId, string? sign) { - #region 验证签名 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; + } + #region 验证签名 + var orderInfo = PaymentExtend.ParseCustomString(orderId); string newSign = $"{tenant}{orderId}{orderInfo.UserId}"; newSign = MD5Encryption.ComputeMD5Hash(newSign); @@ -109,7 +117,7 @@ namespace HuanMeng.MiaoYu.WebPayApi.Controllers await dao.daoDbMiaoYu.context.SaveChangesAsync(); return $"error;用户不存在"; } - using (IDbContextTransaction transaction = dao.daoDbMiaoYu.context.Database.BeginTransaction(System.Data.IsolationLevel.RepeatableRead)) + using (IDbContextTransaction transaction = dao.daoDbMiaoYu.context.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted)) { try { @@ -133,13 +141,7 @@ namespace HuanMeng.MiaoYu.WebPayApi.Controllers } } redis.KeyDelete(baseKey); - 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"; } diff --git a/src/2-api/HuanMeng.MiaoYu.WebPayApi/HuanMeng.MiaoYu.WebPayApi.csproj b/src/2-api/HuanMeng.MiaoYu.WebPayApi/HuanMeng.MiaoYu.WebPayApi.csproj index 9a3079a..f0d0831 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebPayApi/HuanMeng.MiaoYu.WebPayApi.csproj +++ b/src/2-api/HuanMeng.MiaoYu.WebPayApi/HuanMeng.MiaoYu.WebPayApi.csproj @@ -15,6 +15,7 @@ + diff --git a/src/2-api/HuanMeng.MiaoYu.WebPayApi/appsettings.json b/src/2-api/HuanMeng.MiaoYu.WebPayApi/appsettings.json index a39ff30..3612c9e 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebPayApi/appsettings.json +++ b/src/2-api/HuanMeng.MiaoYu.WebPayApi/appsettings.json @@ -9,7 +9,7 @@ "Serilog": { "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ], "MinimumLevel": { - "Default": "Information", + "Default": "Debug", "Override": { "Microsoft": "Warning", "System": "Warning" @@ -35,7 +35,12 @@ "restrictedToMinimumLevel": "Error", //写入日志的级别 //包括 Verbose、Debug、Information、Warning、Error 和 Fatal "shared": true //不占用文件 // "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}" - } + }, + "Filter": [ + { + "Expression": "Level == 'Error'" + } + ] }, { "Name": "File", @@ -45,7 +50,12 @@ "restrictedToMinimumLevel": "Debug", //写入日志的级别 //包括 Verbose、Debug、Information、Warning、Error 和 Fatal "shared": true //不占用文件 // "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}" - } + }, + "Filter": [ + { + "Expression": "Level == 'Debug'" + } + ] } ], "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]