From a7ba3b5375295f41c71ded333634abfac269f069 Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 17 Dec 2025 06:55:36 -0600 Subject: [PATCH] 's' --- config/index.js | 2 +- src/pages/book/index.tsx | 49 +++++++++++++++++++++++++++++++++++++-- src/pages/index/index.jsx | 25 +++++++++++++++++--- 3 files changed, 70 insertions(+), 6 deletions(-) diff --git a/config/index.js b/config/index.js index 9911967..255b181 100644 --- a/config/index.js +++ b/config/index.js @@ -101,7 +101,7 @@ const config = { changeOrigin: true, }, }, - allowedHosts: ["nomadro.com", "localhost", ".nomadro.com", "hackrobot.cn"], + allowedHosts: ["nomadro.com", "localhost", ".nomadro.com", "hackrobot.cn",".ngrok-free.app"], }, htmlPluginOption: { diff --git a/src/pages/book/index.tsx b/src/pages/book/index.tsx index 11242ea..0e850dd 100644 --- a/src/pages/book/index.tsx +++ b/src/pages/book/index.tsx @@ -99,7 +99,7 @@ const Book = () => { } }; - const payh5 = (type, total_fee = 1000) => { + const payh52222 = (type, total_fee = 1000) => { // console.log("111"); Taro.request({ method: "POST", @@ -142,6 +142,51 @@ const Book = () => { }); }; +const payh5 = (type, total_fee = 1000) => { + Taro.request({ + method: "POST", + url: `${process.env.TARO_API_API}/payh5`, + data: { + total_fee: total_fee, + type: type, + // callback_url 临时不传 + }, + header: { + "content-type": "application/json", + }, + success: (res) => { + if (res.data?.status === "ok" && res.data?.xorpay_params) { + // 创建隐藏 form POST 到 XorPay + const form = document.createElement("form"); + form.method = "POST"; + form.action = res.data.xorpay_url; + form.style.display = "none"; + + for (const key in res.data.xorpay_params) { + const input = document.createElement("input"); + input.type = "hidden"; + input.name = key; + input.value = res.data.xorpay_params[key]; + form.appendChild(input); + } + + document.body.appendChild(form); + form.submit(); + } else { + Taro.showToast({ + title: "支付发起失败", + icon: "none", + }); + } + }, + fail: () => { + Taro.showToast({ + title: "网络错误", + icon: "none", + }); + }, + }); +}; return ( <> @@ -237,7 +282,7 @@ const Book = () => { } else { if (!!isWeChat) { //198元 - payh5("book", 19800); + payh5("book", 10); } else { window.location.href = `https://mp.weixin.qq.com/s/16xcMIgxEEGBPY7fanNq0g`; } diff --git a/src/pages/index/index.jsx b/src/pages/index/index.jsx index ddb28d4..a8570f2 100644 --- a/src/pages/index/index.jsx +++ b/src/pages/index/index.jsx @@ -136,10 +136,29 @@ const Index = () => { }, }); } else { - let nowUrl = window.location.href; + // let nowUrl = window.location.href; + // window.localStorage.removeItem("openid"); + // // let payUrl = `https://payjs.cn/api/openid?mchid=1561724891&callback_url=${nowUrl}`; + // let payUrl = `https://xorpay.com/api/openid/8220&callback_url=${nowUrl}`; + // window.location.href = payUrl; + + // 清除旧 openid(可选,建议保留) window.localStorage.removeItem("openid"); - let payUrl = `https://payjs.cn/api/openid?mchid=1561724891&callback_url=${nowUrl}`; - window.location.href = payUrl; + + // 当前完整 URL(包括 ? 参数和 # hash) + let nowUrl = window.location.href; + + // 正确构造 XorPay openid 获取地址 + // 1. 参数名必须是 callback + // 2. 值必须 encodeURIComponent 编码 + let payUrl = `https://xorpay.com/api/openid/8220?callback=${encodeURIComponent( + nowUrl + )}`; + + console.log("跳转获取 openid 的 URL:", payUrl); + // 示例输出:https://xorpay.com/api/openid/8220?callback=http%3A%2F%2F192.168.31.222%3A10086%2F%23%2Fpay + + // window.location.href = payUrl; } };