mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-04-26 03:07:56 +08:00
65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
|
|
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)
|
|||
|
|
{
|
|||
|
|
throw new AlipayException($"支付宝支付,验签失败");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return Task.CompletedTask;
|
|||
|
|
}
|
|||
|
|
}
|