From 2365bb9e1743988afa87368d0a026cff7497b8ae Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 13 Mar 2026 05:15:33 -0500 Subject: [PATCH] 'c1' --- app/api/pay/route.ts | 131 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 114 insertions(+), 17 deletions(-) diff --git a/app/api/pay/route.ts b/app/api/pay/route.ts index d48752d..0fb638a 100644 --- a/app/api/pay/route.ts +++ b/app/api/pay/route.ts @@ -68,36 +68,130 @@ function buildPayHtml( function buildQrHtml( imgSrc: string, returnUrl: string, - orderId: string + orderId: string, + opts?: { channel?: string; successDesc?: string; confirmUrl?: string } ): string { + const ch = (opts?.channel || "wxpay").toLowerCase(); + const isWx = ch === "wxpay" || ch === "wx" || ch === "wechat"; + const title = isWx ? "微信扫码支付" : "支付宝扫码支付"; + const hint = isWx ? "请使用微信扫描下方二维码完成支付" : "请使用支付宝扫描下方二维码完成支付"; + const successDesc = opts?.successDesc || "支付成功,即将跳转"; + const confirmUrl = opts?.confirmUrl || "/api/pay/confirm"; + const esc = (s: string) => + s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c] || c); return ` -扫码支付 - +${esc(title)} + -

请扫码支付

-

支付成功后将自动跳转

-支付二维码 +
+
+

${esc(title)}

+

${esc(hint)}

+
+
+ + + + +
+ 5:00 + +
+
+
+ 支付二维码 +
+
+

等待支付中...

+
+
+
+
支付成功
+
${esc(successDesc)}
+
3 秒后跳转
+
+
`; @@ -308,7 +402,10 @@ export async function POST(request: NextRequest) { ] || c) ); const rawOrderId = String(resData.order_id || created.orderId).trim(); - const html = buildQrHtml(imgSrc, safeReturnUrl, rawOrderId); + const html = buildQrHtml(imgSrc, safeReturnUrl, rawOrderId, { + channel: resData.channel || "wxpay", + successDesc: "支付成功,课程已解锁", + }); const response = new NextResponse(html, { status: 200, headers: { "Content-Type": "text/html; charset=utf-8" },