Files
Yi.Framework/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Alipay/AlipayManager.cs
chenchun 2b3fad16fd feat: 优化支付宝回调通知记录功能
- 新增SignStr字段记录支付宝回调的原始签名字符串
- 修改日志记录格式,使用键值对形式记录回调通知数据
- 更新PayManager.RecordPayNoticeAsync方法支持记录原始签名字符串
- 移除AlipayManager中冗余的注释说明
2025-08-13 18:21:05 +08:00

69 lines
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Alipay.EasySDK.Factory;
using Alipay.EasySDK.Kernel.Util;
using Alipay.EasySDK.Payment.Page.Models;
using Microsoft.Extensions.Logging;
using Volo.Abp.Domain.Services;
namespace Yi.Framework.AiHub.Domain.Alipay;
public class AlipayManager : DomainService
{
private readonly ILogger<AlipayManager> _logger;
public AlipayManager(ILogger<AlipayManager> logger)
{
_logger = logger;
}
/// <summary>
/// 统一Page支付
/// </summary>
/// <returns></returns>
/// <exception cref="AlipayException"></exception>
public Task<AlipayTradePagePayResponse> PaymentPageAsync(string productName, string orderNumber,
decimal totalAmount)
{
try
{
// 2. 发起API调用以创建当面付收款二维码为例
var response = Factory.Payment.Page()
.Pay(productName, orderNumber, totalAmount.ToString(), "https://ccnetcore.com/pay/sucess");
// 3. 处理响应或异常
if (ResponseChecker.Success(response))
{
_logger.LogInformation($"支付宝PaymentPage发起调用成功返回内容{response.Body}");
//插入数据库
return Task.FromResult(response);
}
else
{
throw new AlipayException($"支付宝PaymentPage发起调用失败原因{response.Body}");
}
}
catch (Exception ex)
{
throw new AlipayException($"支付宝PaymentPage发起调用错误原因{ex.Message}", innerException: ex);
}
}
/// <summary>
/// 通知验签
/// </summary>
/// <param name="form"></param>
/// <returns></returns>
/// <exception cref="AlipayException"></exception>
public Task VerifyNotifyAsync(Dictionary<string, string> form)
{
// 支付宝的验签需要保持原始参数顺序,排序会导致验签失败
var result = Factory.Payment.Common().VerifyNotify(form);
if (result == false)
{
_logger.LogError($"支付宝支付验签失败,回调参数:{System.Text.Json.JsonSerializer.Serialize(form)}");
throw new AlipayException($"支付宝支付,验签失败");
}
_logger.LogInformation("支付宝回调验签成功");
return Task.CompletedTask;
}
}