lingling
2025-03-20 4cb523bee320f335100c63df4c8f51ed09fca9eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using LifePayment.Application.Contracts;
using LifePayment.Domain;
using LifePayment.Domain.Shared;
using Microsoft.AspNetCore.Mvc;
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.Uow;
 
namespace LifePayment.HttpApi
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [IgnoreAntiforgeryToken]
    // [Authorize(AuthenticationSchemes = WxPaySignAuthenticationDefaults.AuthenticationScheme)]
    public class WxPayNotifyController : AbpController
    {
 
        private readonly IWxPayApi _wxPayApi;
        private readonly ILifePayService _lifePayService;
        private readonly ILogger<WxPayNotifyController> _logger;
 
        public WxPayNotifyController(
               IWxPayApi wxPayApi,
               ILogger<WxPayNotifyController> logger,
               ILifePayService lifePayService)
        {
            _wxPayApi = wxPayApi;
            _logger = logger;
            _lifePayService = lifePayService;
        }
 
        /// <summary>
        /// 微信支付回调通知
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        public async Task<WxRechargeNotifyResult> WxRechargeNotify(WxRechargeNotifyInput input)
        {
            try
            {
                _logger.LogError($"生活管家微信充值回调通知:进入微信回调");
                var data = _wxPayApi.AesGcmDecrypt(input.Resource.AssociatedData, input.Resource.Nonce, input.Resource.Ciphertext);
                var wxPayNotice = JsonConvert.DeserializeObject<WxPayNotice>(data);
 
                if (wxPayNotice.OutTradeNo.Contains("JF") )
                {
                    if (wxPayNotice.TradeState == LifePaymentConstant.WxPayStatus.支付成功)
                    {
                        await _lifePayService.LifePaySuccessHandler(wxPayNotice.OutTradeNo, wxPayNotice.TransactionId);
                    }
                }
            }
            catch (Exception ex)
            {
                await CurrentUnitOfWork.RollbackAsync();
                return new WxRechargeNotifyResult
                {
                    Code = "FAIL",
                    Message = ex.Message,
                };
            }
 
            return new WxRechargeNotifyResult
            {
                Code = "SUCCESS",
            };
        }
    }
}