sunpengfei
2025-06-13 67fc39c356d8b480b7005cb2fa4769a0a6c6cfb1
LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs
@@ -1,6 +1,7 @@
using 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,6 +11,7 @@
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Caching;
using Volo.Abp.DistributedLocking;
using Volo.Abp.Uow;
using ZeroD.Util;
@@ -26,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(
@@ -33,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>
@@ -48,7 +53,7 @@
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        [UnitOfWork(false)]
        public async Task<WxRechargeNotifyResult> WxRechargeNotify(WxRechargeNotifyInput input)
        {
            try
@@ -59,10 +64,14 @@
                _logger.LogInformation($"生活管家微信充值回调通知data:" + data);
                var wxPayNotice = JsonConvert.DeserializeObject<WxPayNotice>(data);
                await using var orderLock = await distributedLock.TryAcquireAsync($"LockKey:UpdateOrder:{wxPayNotice.OutTradeNo}", TimeSpan.FromSeconds(60));
                _logger.LogInformation($"锁:LockKey:UpdateOrder:{wxPayNotice.OutTradeNo} - {orderLock != null}");
                if (wxPayNotice.OutTradeNo.Contains("JF"))
                {
                    if (wxPayNotice.TradeState == LifePaymentConstant.WxPayStatus.支付成功)
                    {
                        var key = $"WxRechargeNotify_{wxPayNotice.OutTradeNo}";
                        if (string.IsNullOrWhiteSpace(distributedCache.Get(key)))
                        {
@@ -85,6 +94,9 @@
                            {
                                AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10)
                            });
                            await CurrentUnitOfWork.CompleteAsync();
                            _logger.LogInformation("事务完成");
                        }
                        else
                        {
@@ -104,6 +116,7 @@
            catch (Exception ex)
            {
                await CurrentUnitOfWork.RollbackAsync();
                _logger.LogError($"微信支付回调异常:{ex.Message}", ex);
                return new WxRechargeNotifyResult
                {
                    Code = "FAIL",