fix(wxpay): 修复微信下单重入错误
out_trade_no 原格式 MJZ{order.id:012d} 在数据库重建后 ID 从 1 重新开始,
导致与微信支付缓存中的历史订单号冲突,触发 INVALID_REQUEST 重入错误。
新格式加入时间戳:MJZ{timestamp}{order.id:08d},确保全局唯一。
This commit is contained in:
@@ -160,8 +160,11 @@ async def create_recharge_order(
|
||||
db.add(order)
|
||||
await db.flush()
|
||||
|
||||
# 生成商户订单号
|
||||
out_trade_no = f"MJZ{order.id:012d}"
|
||||
# 生成商户订单号(加入时间戳避免数据库重建后 ID 复用导致微信重入错误)
|
||||
import time
|
||||
|
||||
timestamp = int(time.time())
|
||||
out_trade_no = f"MJZ{timestamp}{order.id:08d}"
|
||||
order.out_trade_no = out_trade_no
|
||||
|
||||
# 二维码有效期 2 分钟(与前端轮询对齐)
|
||||
|
||||
Reference in New Issue
Block a user