using Alipay.AopSdk.F2FPay.Model; using Castle.Core.Internal; 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.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.Uow; using ZeroD.Util; namespace LifePayment.HttpApi { [Route("api/[controller]/[action]")] [ApiController] [IgnoreAntiforgeryToken] //[Authorize(AuthenticationSchemes = AliPaySignAuthenticationDefaults.AuthenticationScheme)] public class AliPayNotifyController : AbpController { private readonly ILifePayService _lifePayService; private readonly ILifePayOrderService _lifePayOrderService; private readonly ILogger _logger; public AliPayNotifyController( ILogger logger, ILifePayService lifePayService, ILifePayOrderService lifePayOrderService) { _logger = logger; _lifePayService = lifePayService; _lifePayOrderService = lifePayOrderService; } /// /// 支付宝充值回调通知 /// /// [HttpPost] [UnitOfWork] public async Task AliRechargeNotify() { _logger.LogError($"生活管家支付宝充值回调通知:进入支付宝回调"); var request = await this.HttpContext.Request.ReadFormAsync(); var requestToDic = request.ToDictionary(r => r.Key, r => r.Value.ToString()); var serializeRequest = JsonConvert.SerializeObject(requestToDic); _logger.LogError($"生活管家支付宝充值回调通知:{serializeRequest}"); //var serializeRequest = "{\"gmt_create\":\"2025-02-25 13:18:59\",\"charset\":\"UTF-8\",\"seller_email\":\"zfb1@818nb.com\",\"subject\":\"生活缴费-话费\",\"sign\":\"Sp06G1GxrAfDvoHPz9l3DJ20SxhvRzEGFeCGu4LHrSWmEG4OY7MHMx+iJi54ETbdXV0YsyDH9JZD7PWN3HCpEq/wGO4Wh4VSYSe7lqxD6r4f/HFiB0YlrdQoSzjZgYPzLjy6bcdlKRRHOeDkgs2i7TfvIsxWxHs9t0xuS0RlkpdZfb7d7m0EuZ/3v2Cbsj5AHjxb1S2PkO0oQyriYgGQdmkPqILZHwieST+tNEHS4dGFKYu2nkfctAGjWIDv/hKQNY7jEUxsEeG0SnK4TPU8zNplFR9/aKM0Wfwp1pdlaiP2u/d8vOtNh5q+emvaYbKrUkIEFBok8pDLNDta7ZjtVw==\",\"invoice_amount\":\"0.01\",\"buyer_open_id\":\"071xYXDfXBLAI9U11jg_WrH1K6hWq8HYGz0u85xBivf3Sce\",\"notify_id\":\"2025022501222131904087711494539601\",\"fund_bill_list\":\"[{\\\"amount\\\":\\\"0.01\\\",\\\"fundChannel\\\":\\\"ALIPAYACCOUNT\\\"}]\",\"notify_type\":\"trade_status_sync\",\"trade_status\":\"TRADE_SUCCESS\",\"receipt_amount\":\"0.01\",\"buyer_pay_amount\":\"0.01\",\"app_id\":\"2021004171602214\",\"sign_type\":\"RSA2\",\"seller_id\":\"2088050542042301\",\"gmt_payment\":\"2025-02-25 13:19:03\",\"notify_time\":\"2025-02-25 13:44:34\",\"merchant_app_id\":\"2021004171602214\",\"version\":\"1.0\",\"out_trade_no\":\"JF202502251318555214671\",\"total_amount\":\"0.01\",\"trade_no\":\"2025022522001487711401331043\",\"auth_app_id\":\"2021004171602214\",\"buyer_logon_id\":\"130****2238\",\"point_amount\":\"0.00\"}"; var input = JsonConvert.DeserializeObject(serializeRequest); if (input.OutTradeNo.Contains("JF")) { if (input.TradeStatus == LifePaymentConstant.AliPayStatus.支付成功 && input.OutBizNo.IsNullOrEmpty()) { await _lifePayService.LifePaySuccessHandler(input.OutTradeNo, input.TradeNo); // 插入收支流水 await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() { OrderNo = input.OutTradeNo, OutOrderNo = input.TradeNo ,LifePayType = LifePayTypeEnum.AliPay,ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses }); } else if((input.TradeStatus == LifePaymentConstant.AliPayStatus.支付成功 && input.OutBizNo.IsNotNullOrEmpty() && input.RefundFee.HasValue) || input.TradeStatus == LifePaymentConstant.AliPayStatus.超时关闭) { await _lifePayService.LifePayRefundsHandler(input.OutTradeNo, LifePayRefundStatusEnum.已退款); // 插入收支流水 await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() { OrderNo = input.OutTradeNo, OutRefundNo = input.OutBizNo, OutOrderNo = input.TradeNo, LifePayType = LifePayTypeEnum.AliPay, ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts }); } } else { _logger.LogError($"生活管家支付宝充值回调通知:订单号异常 "+ input.OutTradeNo); } return new ContentResult { Content = "success", }; } #if DEBUG [HttpGet] [UnitOfWork] [AllowAnonymous] public async Task TestAliRechargeNotify(string outTradeNo, string tradeNo, bool success) { if (outTradeNo.Contains("JF")) { if (success) { await _lifePayService.LifePaySuccessHandler(outTradeNo, tradeNo); } } return new ContentResult { Content = "success", }; } #endif /// /// 单笔转账到支付宝账户、单笔转账到银行卡、C2C现金红包、B2C现金红包单据状态变更后触发的通知 /// /// //[HttpPost] //[UnitOfWork] //public async Task NotifyOrderChanged() //{ // var request = await this.HttpContext.Request.ReadFormAsync(); // var requestToDic = request.ToDictionary(r => r.Key, r => r.Value.ToString()); // var serializeRequest = JsonConvert.SerializeObject(requestToDic); // _logger.LogError($"单笔转账回调:{serializeRequest}"); // if (requestToDic["msg_method"] == "alipay.fund.trans.order.changed") // { // var input = JsonConvert.DeserializeObject(serializeRequest); // if (input.BizContent != null) // { // if (input.BizContent.OutBizNo.Contains(RequestCode.AlipayCharge)) // { // await _walletService.FundTransOrderChangedForRecharge(input.BizContent); // } // else // { // await _walletService.FundTransOrderChangedForSingleTransfer(input.BizContent); // } // } // } // return new ContentResult // { // Content = "success", // }; //} } }