sunpengfei
2025-06-09 3274bc9ca97ce02bd7eb86107898a40531057477
pref:多次接收到支付回调的bug
2个文件已修改
18 ■■■■ 已修改文件
LifePayment/LifePayment.Application/LifePay/LifePayService.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -1306,7 +1306,7 @@
        var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync();
        CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在");
        if (order.PayStatus == LifePayStatusEnum.已支付)
        if (order.PayStatus != LifePayStatusEnum.未支付)
        {
            return;
        }
LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs
@@ -2,12 +2,14 @@
using LifePayment.Domain;
using LifePayment.Domain.Shared;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Caching;
using Volo.Abp.Uow;
namespace LifePayment.HttpApi
@@ -22,18 +24,21 @@
        private readonly IWxPayApi _wxPayApi;
        private readonly ILifePayService _lifePayService;
        private readonly ILifePayOrderService _lifePayOrderService;
        private readonly IDistributedCache<string> distributedCache;
        private readonly ILogger<WxPayNotifyController> _logger;
        public WxPayNotifyController(
               IWxPayApi wxPayApi,
               ILogger<WxPayNotifyController> logger,
               ILifePayService lifePayService,
               ILifePayOrderService lifePayOrderService)
               ILifePayOrderService lifePayOrderService,
               IDistributedCache<string> distributedCache)
        {
            _wxPayApi = wxPayApi;
            _logger = logger;
            _lifePayService = lifePayService;
            _lifePayOrderService = lifePayOrderService;
            this.distributedCache = distributedCache;
        }
        /// <summary>
@@ -56,6 +61,9 @@
                {
                    if (wxPayNotice.TradeState == LifePaymentConstant.WxPayStatus.支付成功)
                    {
                        var key = $"WxRechargeNotify_{wxPayNotice.OutTradeNo}";
                        if (string.IsNullOrWhiteSpace(distributedCache.Get(key)))
                        {
                        await _lifePayService.LifePaySuccessHandler(wxPayNotice.OutTradeNo, wxPayNotice.TransactionId);
                        // 插入收支流水
@@ -67,6 +75,12 @@
                            ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses,
                            Amount = wxPayNotice.Amount.Total
                        });
                            distributedCache.Set(key, data, new DistributedCacheEntryOptions
                            {
                                AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10)
                            });
                        }
                    }
                }
            }