sunpengfei
2025-06-09 6cc1fae81a73188769943615806ff11c4c0f8553
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>
@@ -47,25 +52,35 @@
        {
            try
            {
                _logger.LogError($"生活管家微信充值回调通知:进入微信回调");
                _logger.LogError($"生活管家微信充值回调通知:进入微信回调:");
                var data = _wxPayApi.AesGcmDecrypt(input.Resource.AssociatedData, input.Resource.Nonce, input.Resource.Ciphertext);
                _logger.LogError($"生活管家微信充值回调通知data:" + data);
                var wxPayNotice = JsonConvert.DeserializeObject<WxPayNotice>(data);
                if (wxPayNotice.OutTradeNo.Contains("JF") )
                {
                    if (wxPayNotice.TradeState == LifePaymentConstant.WxPayStatus.支付成功)
                    {
                        await _lifePayService.LifePaySuccessHandler(wxPayNotice.OutTradeNo, wxPayNotice.TransactionId);
                        // 插入收支流水
                        await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput()
                        var key = $"WxRechargeNotify_{wxPayNotice.OutTradeNo}";
                        if (string.IsNullOrWhiteSpace(distributedCache.Get(key)))
                        {
                            OrderNo = wxPayNotice.OutTradeNo,
                            OutOrderNo = wxPayNotice.TransactionId,
                            LifePayType = LifePayTypeEnum.WxPay,
                            ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses,
                            Amount = wxPayNotice.Amount.Total
                        });
                            await _lifePayService.LifePaySuccessHandler(wxPayNotice.OutTradeNo, wxPayNotice.TransactionId);
                            // 插入收支流水
                            await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput()
                            {
                                OrderNo = wxPayNotice.OutTradeNo,
                                OutOrderNo = wxPayNotice.TransactionId,
                                LifePayType = LifePayTypeEnum.WxPay,
                                ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses,
                                Amount = wxPayNotice.Amount.Total
                            });
                            distributedCache.Set(key, data, new DistributedCacheEntryOptions
                            {
                                AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10)
                            });
                        }
                    }
                }
            }
@@ -98,32 +113,29 @@
            {
                _logger.LogError($"微信退款回调通知:进入微信回调");
                var data = _wxPayApi.AesGcmDecrypt(input.Resource.AssociatedData, input.Resource.Nonce, input.Resource.Ciphertext);
                _logger.LogError($"微信退款回调通知data:"+ data);
                var wxPayNotice = JsonConvert.DeserializeObject<WxPayDomesticRefundsNotice>(data);
                if (wxPayNotice.OutTradeNo.Contains("JF"))
                {
                    if (wxPayNotice.RefundStatus == LifePaymentConstant.WxPayRefundStatus.退款成功)
                    {
                    }
                    switch (wxPayNotice.RefundStatus)
                    {
                        case LifePaymentConstant.WxPayRefundStatus.退款成功:
                        case LifePaymentConstant.WxPayRefundStatus.退款关闭:
                            await _lifePayService.LifePayRefundsHandler(wxPayNotice.OutTradeNo, LifePayRefundStatusEnum.已退款);
                            // 插入收支流水
                            await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput()
                            {
                                OrderNo = wxPayNotice.OutTradeNo,
                                OutRefundNo = wxPayNotice.OutRefundNo,
                                OutOrderNo = wxPayNotice.TransactionId,
                                LifePayType = LifePayTypeEnum.WxPay,
                                ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts,
                                Amount = wxPayNotice.Amount.Total
                            });
                            break;
                        case LifePaymentConstant.WxPayRefundStatus.退款关闭:
                        case LifePaymentConstant.WxPayRefundStatus.退款处理中:
                            await _lifePayService.LifePayRefundsHandler(wxPayNotice.OutTradeNo, LifePayRefundStatusEnum.退款中);
                            break;
                        case LifePaymentConstant.WxPayRefundStatus.退款异常:
                            await _lifePayService.LifePayRefundsHandler(wxPayNotice.OutTradeNo, LifePayRefundStatusEnum.退款中);
                            break;