diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Pay/CreateOrderOutput.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Pay/CreateOrderOutput.cs
index 6edc4efe..6cab28bd 100644
--- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Pay/CreateOrderOutput.cs
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Pay/CreateOrderOutput.cs
@@ -18,5 +18,5 @@ public class CreateOrderOutput
///
/// 支付页面HTML内容
///
- public string PaymentPageHtml { get; set; }
+ public object PaymentPageHtml { get; set; }
}
\ No newline at end of file
diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs
index c95cdfe0..ef69039d 100644
--- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs
@@ -1,3 +1,4 @@
+using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Services;
@@ -40,6 +41,7 @@ public class PayService : ApplicationService, IPayService
///
/// 创建订单输入
/// 订单创建结果
+ [Authorize]
[HttpPost("pay/Order")]
public async Task CreateOrderAsync(CreateOrderInput input)
{
@@ -48,8 +50,8 @@ public class PayService : ApplicationService, IPayService
// 2. 通过AlipayManager发起页面支付
var paymentPageHtml = await _alipayManager.PaymentPageAsync(
- order.OutTradeNo,
order.GoodsName,
+ order.OutTradeNo,
order.TotalAmount);
// 3. 返回结果
@@ -57,7 +59,7 @@ public class PayService : ApplicationService, IPayService
{
OrderId = order.Id,
OutTradeNo = order.OutTradeNo,
- PaymentPageHtml = JsonConvert.SerializeObject(paymentPageHtml)
+ PaymentPageHtml = paymentPageHtml.Body
};
}
@@ -67,16 +69,17 @@ public class PayService : ApplicationService, IPayService
/// 表单数据
///
[HttpPost("pay/AlipayNotify")]
+ [AllowAnonymous]
public async Task AlipayNotifyAsync([FromForm] IFormCollection form)
{
- // 1. 将表单数据转换为字典
+ // 1. 将表单数据转换为字典,保持原始顺序
var notifyData = new Dictionary();
foreach (var item in form)
{
notifyData[item.Key] = item.Value.ToString();
}
- _logger.LogInformation("收到支付宝回调通知:{NotifyData}", System.Text.Json.JsonSerializer.Serialize(notifyData));
+ _logger.LogInformation($"收到支付宝回调通知:{System.Text.Json.JsonSerializer.Serialize(notifyData)}");
// 2. 验证签名
await _alipayManager.VerifyNotifyAsync(notifyData);
@@ -97,6 +100,10 @@ public class PayService : ApplicationService, IPayService
_logger.LogInformation("订单状态更新成功,订单号:{OutTradeNo},状态:{TradeStatus}", outTradeNo, tradeStatus);
}
+ else
+ {
+ throw new AlipayException($"回调格式错误");
+ }
return "success";
}
@@ -107,6 +114,7 @@ public class PayService : ApplicationService, IPayService
/// 查询订单状态输入
/// 订单状态信息
[HttpGet("pay/OrderStatus")]
+ [Authorize]
public async Task QueryOrderStatusAsync([FromQuery] QueryOrderStatusInput input)
{
// 通过PayManager查询订单
diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/TokenService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/TokenService.cs
index e08cbc50..65d30166 100644
--- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/TokenService.cs
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/TokenService.cs
@@ -47,7 +47,7 @@ public class TokenService : ApplicationService
{
if (!CurrentUser.IsAiVip())
{
- throw new UserFriendlyException("充值成为Vip,畅想第三方token服务");
+ throw new UserFriendlyException("充值成为Vip,畅享第三方token服务");
}
await _tokenManager.CreateAsync(CurrentUser.GetId());
diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/GoodsTypeEnum.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/GoodsTypeEnum.cs
index 082e35e0..6d674456 100644
--- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/GoodsTypeEnum.cs
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/GoodsTypeEnum.cs
@@ -36,20 +36,24 @@ public class DisplayNameAttribute : Attribute
///
public enum GoodsTypeEnum
{
+ [Price(0.01)]
+ [DisplayName("YiXinVip Test")]
+ YiXinVipTest = 0,
+
[Price(29.9)]
- [DisplayName("意心Vip会员1个月")]
+ [DisplayName("YiXinVip 1 month")]
YiXinVip1 = 1,
[Price(80.7)]
- [DisplayName("意心Vip会员3个月")]
+ [DisplayName("YiXinVip 3 month")]
YiXinVip3 = 3,
[Price(143.9)]
- [DisplayName("意心Vip会员6个月")]
+ [DisplayName("YiXinVip 6 month")]
YiXinVip6 = 6,
[Price(199.9)]
- [DisplayName("意心Vip会员10个月")]
+ [DisplayName("YiXinVip 10 month")]
YiXinVip10 = 10
}
diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Alipay/AlipayManager.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Alipay/AlipayManager.cs
index 01fbf483..007d2b37 100644
--- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Alipay/AlipayManager.cs
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Alipay/AlipayManager.cs
@@ -20,7 +20,8 @@ public class AlipayManager : DomainService
///
///
///
- public Task PaymentPageAsync(string productName, string orderNumber, decimal totalAmount)
+ public Task PaymentPageAsync(string productName, string orderNumber,
+ decimal totalAmount)
{
try
{
@@ -54,12 +55,16 @@ public class AlipayManager : DomainService
///
public Task VerifyNotifyAsync(Dictionary 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;
}
}
\ No newline at end of file
diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/PayManager.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/PayManager.cs
index d6d67f94..58c91afa 100644
--- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/PayManager.cs
+++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/PayManager.cs
@@ -82,8 +82,6 @@ public class PayManager : DomainService
{
order.TradeNo = tradeNo;
}
- order.LastModificationTime = DateTime.Now;
-
await _payOrderRepository.UpdateAsync(order);
}