From 08371f70becf10a003005b79a33fc393ba4efaf3 Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期二, 10 六月 2025 11:14:06 +0800 Subject: [PATCH] feat:渠道订单导出接口实现 --- LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs | 44 +++++++++++++++++++++++++++++--------------- 1 files changed, 29 insertions(+), 15 deletions(-) diff --git a/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs b/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs index 5dc1ddd..d5bead3 100644 --- a/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs +++ b/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,6 +113,7 @@ { _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")) @@ -106,7 +122,6 @@ switch (wxPayNotice.RefundStatus) { case LifePaymentConstant.WxPayRefundStatus.閫�娆炬垚鍔�: - case LifePaymentConstant.WxPayRefundStatus.閫�娆惧叧闂�: await _lifePayService.LifePayRefundsHandler(wxPayNotice.OutTradeNo, LifePayRefundStatusEnum.宸查��娆�); // 鎻掑叆鏀舵敮娴佹按 await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() @@ -119,9 +134,8 @@ 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; -- Gitblit v1.9.1