From b9e2c8345c5c83581a7a57bcda316928b171f322 Mon Sep 17 00:00:00 2001 From: zhengyiming <540361168@qq.com> Date: 星期三, 16 四月 2025 17:18:34 +0800 Subject: [PATCH] fix: 修改微信支付回调通知 --- LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs | 79 ++++++++++++++++++++++++++++++++++++++- 1 files changed, 76 insertions(+), 3 deletions(-) diff --git a/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs b/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs index 54d3114..41be1d0 100644 --- a/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs +++ b/LifePayment/LifePayment.HttpApi/LifePay/WxPayNotifyController.cs @@ -21,16 +21,19 @@ private readonly IWxPayApi _wxPayApi; private readonly ILifePayService _lifePayService; + private readonly ILifePayOrderService _lifePayOrderService; private readonly ILogger<WxPayNotifyController> _logger; public WxPayNotifyController( IWxPayApi wxPayApi, ILogger<WxPayNotifyController> logger, - ILifePayService lifePayService) + ILifePayService lifePayService, + ILifePayOrderService lifePayOrderService) { _wxPayApi = wxPayApi; _logger = logger; _lifePayService = lifePayService; + _lifePayOrderService = lifePayOrderService; } /// <summary> @@ -44,15 +47,26 @@ { 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.StartsWith("JF") && Regex.IsMatch(wxPayNotice.OutTradeNo, @"^JF\d+$")) + if (wxPayNotice.OutTradeNo.Contains("JF") ) { if (wxPayNotice.TradeState == LifePaymentConstant.WxPayStatus.鏀粯鎴愬姛) { 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 + }); } } } @@ -71,5 +85,64 @@ Code = "SUCCESS", }; } + + /// <summary> + /// 寰俊閫�娆鹃�氱煡鍥炶皟 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [HttpPost] + [UnitOfWork] + public async Task<WxRechargeNotifyResult> WxPayDomesticRefundsNotify(WxRechargeNotifyInput input) + { + try + { + _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")) + { + + switch (wxPayNotice.RefundStatus) + { + 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.閫�娆惧鐞嗕腑: + case LifePaymentConstant.WxPayRefundStatus.閫�娆惧紓甯�: + await _lifePayService.LifePayRefundsHandler(wxPayNotice.OutTradeNo, LifePayRefundStatusEnum.閫�娆句腑); + break; + default : await _lifePayService.LifePayRefundsHandler(wxPayNotice.OutTradeNo, LifePayRefundStatusEnum.閫�娆句腑);break; + } + } + } + catch (Exception ex) + { + + return new WxRechargeNotifyResult + { + Code = "FAIL", + Message = ex.Message, + }; + } + + return new WxRechargeNotifyResult + { + Code = "SUCCESS", + }; + } } } \ No newline at end of file -- Gitblit v1.9.1