fix: 修复支付宝支付功能相关问题
- 修复支付接口参数顺序错误,调整商品名称和订单号参数位置 - 修复支付页面HTML返回格式,直接返回Body内容而非序列化字符串 - 添加支付相关接口的权限控制,支付回调接口允许匿名访问 - 优化支付宝回调验签逻辑,保持原始参数顺序避免验签失败 - 增加回调格式错误的异常处理 - 修复商品类型枚举显示名称为英文,新增测试商品类型 - 修正Token服务提示文案中的错别字 - 移除订单更新时不必要的时间字段设置
This commit is contained in:
@@ -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
|
||||
/// </summary>
|
||||
/// <param name="input">创建订单输入</param>
|
||||
/// <returns>订单创建结果</returns>
|
||||
[Authorize]
|
||||
[HttpPost("pay/Order")]
|
||||
public async Task<CreateOrderOutput> 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
|
||||
/// <param name="form">表单数据</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("pay/AlipayNotify")]
|
||||
[AllowAnonymous]
|
||||
public async Task<string> AlipayNotifyAsync([FromForm] IFormCollection form)
|
||||
{
|
||||
// 1. 将表单数据转换为字典
|
||||
// 1. 将表单数据转换为字典,保持原始顺序
|
||||
var notifyData = new Dictionary<string, string>();
|
||||
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
|
||||
/// <param name="input">查询订单状态输入</param>
|
||||
/// <returns>订单状态信息</returns>
|
||||
[HttpGet("pay/OrderStatus")]
|
||||
[Authorize]
|
||||
public async Task<QueryOrderStatusOutput> QueryOrderStatusAsync([FromQuery] QueryOrderStatusInput input)
|
||||
{
|
||||
// 通过PayManager查询订单
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user