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 _logger; public ACOOLYNotifyController( ILogger logger, ILifePayService lifePayService) { _logger = logger; _lifePayService = lifePayService; } /// /// ACOOLY回调通知 /// /// [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(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(body); orderNo = confirmElectricOrderResponse.ElectricChargeOrder.OutOrderNo; acoolyOrderNo = confirmElectricOrderResponse.ElectricChargeOrder.BusiOrderNo; _logger.LogError("ACOOLY回调通处理结果状态:" + confirmElectricOrderResponse.ElectricChargeOrder.Status); 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(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); } } }