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); } } }