From 714eca49223a7eabdfc6666eb745c631d27046dc Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期三, 11 六月 2025 19:37:04 +0800 Subject: [PATCH] pref:锁日志 --- LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs | 41 +++++++++++++++++++++++++++++++++-------- 1 files changed, 33 insertions(+), 8 deletions(-) diff --git a/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs b/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs index d5bead3..74ddb7b 100644 --- a/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs +++ b/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs @@ -1,6 +1,7 @@ 锘縰sing LifePayment.Application.Contracts; using LifePayment.Domain; using LifePayment.Domain.Shared; +using Medallion.Threading; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Logging; @@ -10,7 +11,9 @@ using System.Threading.Tasks; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.Caching; +using Volo.Abp.DistributedLocking; using Volo.Abp.Uow; +using ZeroD.Util; namespace LifePayment.HttpApi { @@ -25,6 +28,7 @@ private readonly ILifePayService _lifePayService; private readonly ILifePayOrderService _lifePayOrderService; private readonly IDistributedCache<string> distributedCache; + private readonly IAbpDistributedLock distributedLock; private readonly ILogger<WxPayNotifyController> _logger; public WxPayNotifyController( @@ -32,13 +36,15 @@ ILogger<WxPayNotifyController> logger, ILifePayService lifePayService, ILifePayOrderService lifePayOrderService, - IDistributedCache<string> distributedCache) + IDistributedCache<string> distributedCache, + IAbpDistributedLock distributedLock) { _wxPayApi = wxPayApi; _logger = logger; _lifePayService = lifePayService; _lifePayOrderService = lifePayOrderService; this.distributedCache = distributedCache; + this.distributedLock = distributedLock; } /// <summary> @@ -52,19 +58,25 @@ { try { - _logger.LogError($"鐢熸椿绠″寰俊鍏呭�煎洖璋冮�氱煡锛氳繘鍏ュ井淇″洖璋�:"); + var req = input.ToJson(); + _logger.LogInformation($"鐢熸椿绠″寰俊鍏呭�煎洖璋冮�氱煡锛氳繘鍏ュ井淇″洖璋�:" + req); var data = _wxPayApi.AesGcmDecrypt(input.Resource.AssociatedData, input.Resource.Nonce, input.Resource.Ciphertext); - _logger.LogError($"鐢熸椿绠″寰俊鍏呭�煎洖璋冮�氱煡data锛�" + data); + _logger.LogInformation($"鐢熸椿绠″寰俊鍏呭�煎洖璋冮�氱煡data锛�" + data); var wxPayNotice = JsonConvert.DeserializeObject<WxPayNotice>(data); - if (wxPayNotice.OutTradeNo.Contains("JF") ) + if (wxPayNotice.OutTradeNo.Contains("JF")) { if (wxPayNotice.TradeState == LifePaymentConstant.WxPayStatus.鏀粯鎴愬姛) { + await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{wxPayNotice.OutTradeNo}", TimeSpan.FromSeconds(60)); + _logger.LogInformation($"閿侊細LockKey:UpdateOrder:{wxPayNotice.OutTradeNo} - {orderLock != null}"); + var key = $"WxRechargeNotify_{wxPayNotice.OutTradeNo}"; if (string.IsNullOrWhiteSpace(distributedCache.Get(key))) { + _logger.LogInformation("姝e湪澶勭悊鍥炶皟"); await _lifePayService.LifePaySuccessHandler(wxPayNotice.OutTradeNo, wxPayNotice.TransactionId); + _logger.LogInformation("宸插鐞嗗洖璋�"); // 鎻掑叆鏀舵敮娴佹按 await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() @@ -75,13 +87,26 @@ ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses, Amount = wxPayNotice.Amount.Total }); + _logger.LogInformation("宸叉彃鍏ユ敹鏀祦姘�"); distributedCache.Set(key, data, new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10) }); } + else + { + _logger.LogInformation("宸茶繃婊ら噸澶嶈姹�"); + } } + else + { + _logger.LogInformation("浜ゆ槗鐘舵�佷笉绗﹀悎瑙勫垯"); + } + } + else + { + _logger.LogInformation("璁㈠崟鍙蜂笉绗﹀悎瑙勫垯"); } } catch (Exception ex) @@ -113,12 +138,12 @@ { _logger.LogError($"寰俊閫�娆惧洖璋冮�氱煡锛氳繘鍏ュ井淇″洖璋�"); var data = _wxPayApi.AesGcmDecrypt(input.Resource.AssociatedData, input.Resource.Nonce, input.Resource.Ciphertext); - _logger.LogError($"寰俊閫�娆惧洖璋冮�氱煡data锛�"+ data); + _logger.LogError($"寰俊閫�娆惧洖璋冮�氱煡data锛�" + data); var wxPayNotice = JsonConvert.DeserializeObject<WxPayDomesticRefundsNotice>(data); if (wxPayNotice.OutTradeNo.Contains("JF")) { - + switch (wxPayNotice.RefundStatus) { case LifePaymentConstant.WxPayRefundStatus.閫�娆炬垚鍔�: @@ -139,13 +164,13 @@ case LifePaymentConstant.WxPayRefundStatus.閫�娆惧紓甯�: await _lifePayService.LifePayRefundsHandler(wxPayNotice.OutTradeNo, LifePayRefundStatusEnum.閫�娆句腑); break; - default : await _lifePayService.LifePayRefundsHandler(wxPayNotice.OutTradeNo, LifePayRefundStatusEnum.閫�娆句腑);break; + default: await _lifePayService.LifePayRefundsHandler(wxPayNotice.OutTradeNo, LifePayRefundStatusEnum.閫�娆句腑); break; } } } catch (Exception ex) { - + return new WxRechargeNotifyResult { Code = "FAIL", -- Gitblit v1.9.1