lingling
2025-03-19 b525fe659614934f253ed9c8b59c38cfebb3bc15
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using LifePayment.Application.Contracts;
using LifePayment.Domain.Shared;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Uow;
 
namespace LifePayment.HttpApi
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [IgnoreAntiforgeryToken]
    public class ACOOLYNotifyController : AbpController
    {
        private readonly ILifePayService _lifePayService;
        private readonly ILogger<ACOOLYNotifyController> _logger;
 
        public ACOOLYNotifyController(
               ILogger<ACOOLYNotifyController> logger,
               ILifePayService lifePayService)
        {
            _logger = logger;
            _lifePayService = lifePayService;
        }
 
        /// <summary>
        /// ACOOLY回调通知
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [UnitOfWork]
        [AllowAnonymous]
        public async Task ACOOLYNotify()
        {
            _logger.LogError("ACOOLY回调通知开始进入");
            var body = string.Empty;
            using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
            {
                body = await reader.ReadToEndAsync();
            }
            if (body.IsNullOrEmpty())
            {
                _logger.LogError("ACOOLY回调通知Input为null");
                throw new UserFriendlyException("ACOOLY回调通知Input为null");
            }
            var baseInfo = JsonConvert.DeserializeObject<ACOOLYRequestBaseResponse>(body);
            var orderNo = string.Empty;
            var status = LifePayOrderStatusEnum.待确认;
            var acoolyOrderNo = string.Empty;
            _logger.LogError("ACOOLY回调通处理类型:" + baseInfo.Service);
            _logger.LogError("ACOOLY回调内容:" + body);
            switch (baseInfo.Service)
            {
                case ACOOLYConstant.Sevice.ConfirmElectricOrder:
                    var confirmElectricOrderResponse = JsonConvert.DeserializeObject<ConfirmElectricOrderResponse>(body);
                    orderNo = confirmElectricOrderResponse.ElectricChargeOrder.OutOrderNo;
                    acoolyOrderNo = confirmElectricOrderResponse.ElectricChargeOrder.BusiOrderNo;
                    _logger.LogError("ACOOLY回调通处理结果状态:" + confirmElectricOrderResponse.ElectricChargeOrder.Status);
 
                    /// TODO 状态不正确
                    if (!confirmElectricOrderResponse.Success
                    || (confirmElectricOrderResponse.Code != ACOOLYConstant.Code.SUCCESS && confirmElectricOrderResponse.Code != ACOOLYConstant.Code.PROCESSING))
                    {
                        status = LifePayOrderStatusEnum.已失败;
                    }
                    else
 
                    if (confirmElectricOrderResponse.ElectricChargeOrder.Status == ACOOLYConstant.Code.SUCCESS)
                    {
                        status = LifePayOrderStatusEnum.已完成;
                    }
                    else
 
                    if (confirmElectricOrderResponse.ElectricChargeOrder.Status == ACOOLYConstant.Code.PROCESSING)
                    {
                        status = LifePayOrderStatusEnum.待确认;
                    }
                    else
                    {
                        status = LifePayOrderStatusEnum.已失败;
                    }
 
                    break;
                case ACOOLYConstant.Sevice.ConfirmPhoneOrder:
                    var confirmPhoneOrderResponse = JsonConvert.DeserializeObject<ConfirmPhoneOrderResponse>(body);
                    orderNo = confirmPhoneOrderResponse.PhoneChargeOrder.OutOrderNo;
                    acoolyOrderNo = confirmPhoneOrderResponse.PhoneChargeOrder.BusiOrderNo;
                    _logger.LogError("ACOOLY回调通处理结果状态:" + confirmPhoneOrderResponse.PhoneChargeOrder.Status);
                    if (!confirmPhoneOrderResponse.Success
                    || (confirmPhoneOrderResponse.Code != ACOOLYConstant.Code.SUCCESS && confirmPhoneOrderResponse.Code != ACOOLYConstant.Code.PROCESSING))
                    {
                        status = LifePayOrderStatusEnum.已失败;
                    }
                    else
 
                    if (confirmPhoneOrderResponse.PhoneChargeOrder.Status == ACOOLYConstant.Code.SUCCESS)
                    {
                        status = LifePayOrderStatusEnum.已完成;
                    }
                    else
 
                    if (confirmPhoneOrderResponse.PhoneChargeOrder.Status == ACOOLYConstant.Code.PROCESSING)
                    {
                        status = LifePayOrderStatusEnum.待确认;
                    }
                    else
                    {
                        status = LifePayOrderStatusEnum.已失败;
                    }
                    break;
 
                default:
                    break;
            }
 
            await _lifePayService.ACOOLYOrderNotifyHandler(orderNo, acoolyOrderNo, status);
        }
    }
}