diff --git a/app/api/pay/route.ts b/app/api/pay/route.ts index 091fe8b..4a01579 100644 --- a/app/api/pay/route.ts +++ b/app/api/pay/route.ts @@ -114,9 +114,9 @@ export async function POST(request: NextRequest) { } } const return_url = String(body?.return_url || "").trim(); - const total_fee = Number(body?.total_fee) || 180; + const total_fee = Number(body?.total_fee) || 8800; const type = String(body?.type || "vip"); - const channel = String(body?.channel || "alipay"); + const channel = String(body?.channel || "wxpay"); const device = String(body?.device || "pc"); if (!user_id) { @@ -178,10 +178,65 @@ export async function POST(request: NextRequest) { if (redirectRes.status >= 301 && redirectRes.status <= 308) { const location = redirectRes.headers.get("location"); if (location) { - const res = NextResponse.redirect(location); const orderId = redirectRes.headers.get("x-pay-order-id")?.trim() || String(params?.out_trade_no || "").trim(); + if (device === "h5") { + const returnUrl = finalReturnUrl.replace( + /[&<>"']/g, + (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c] || c + ); + const payUrl = location.replace( + /[&<>"']/g, + (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c] || c + ); + const isWx = ["wxpay", "wx", "wechat"].includes(channel.toLowerCase()); + const title = isWx ? "微信支付" : "支付宝支付"; + const hint = isWx + ? "点击下方按钮跳转至支付页面,支付完成后将自动返回" + : "点击下方按钮跳转至支付页面,支付完成后将自动返回"; + const esc = (s: string) => + s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c] || c); + const html = ` +
+${esc(hint)}
+跳转支付 +支付成功后将自动跳转,1 分钟内未支付将返回首页
+ +`; + const res = new NextResponse(html, { + status: 200, + headers: { "Content-Type": "text/html; charset=utf-8" }, + }); + if (orderId) setPayOrderCookie(res, orderId); + return res; + } + const res = NextResponse.redirect(location); if (orderId) setPayOrderCookie(res, orderId); return res; } @@ -229,7 +284,7 @@ export async function POST(request: NextRequest) {${esc(hint)}
支付成功后将自动跳转...
+支付成功后将自动跳转,1 分钟内未支付将返回首页