This commit is contained in:
eric
2026-03-10 12:20:16 -05:00
parent 613b3a2f6e
commit e37ee6b27f

View File

@@ -238,18 +238,40 @@ const Book = () => {
setTimeout(() => document.body.removeChild(form), 1000); setTimeout(() => document.body.removeChild(form), 1000);
}; };
// 参考 nomadvip 解锁 VIP微信内必须 xorpayPC/手机浏览器 zpay
const getDeviceAndProvider = () => {
const ua = typeof navigator !== "undefined" ? navigator.userAgent.toLowerCase() : "";
const inWeChat = ua.includes("micromessenger");
if (inWeChat) return { device: "wechat", provider: "xorpay" };
const isMobile = /mobile|android|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(ua);
return { device: isMobile ? "h5" : "pc", provider: "zpay" };
};
const payh5 = (type, total_fee = 1000) => { const payh5 = (type, total_fee = 1000) => {
const uid = getOrCreateUserId(); const uid = getOrCreateUserId();
const returnUrl = typeof window !== "undefined" ? `${window.location.origin}${window.location.pathname || "/book"}` : "";
const { device, provider } = getDeviceAndProvider();
Taro.request({ Taro.request({
method: "POST", method: "POST",
url: `${process.env.TARO_API_API}/payh5`, url: `${process.env.TARO_API_API}/payh5`,
data: { total_fee, type, user_id: uid }, data: {
user_id: uid,
return_url: returnUrl,
total_fee,
type,
channel: "wxpay",
device,
provider,
},
header: { "content-type": "application/json" }, header: { "content-type": "application/json" },
success: (res) => { success: (res) => {
if (res.data?.status === "ok" && res.data?.xorpay_params) { const data = res.data || {};
submitPayForm(res.data.xorpay_url, res.data.xorpay_params); const params = data.xorpay_params ?? data.params ?? {};
const payUrl = data.xorpay_url ?? data.pay_url ?? "";
if (params && Object.keys(params).length > 0 && payUrl) {
submitPayForm(payUrl, params);
} else { } else {
Taro.showToast({ title: "支付发起失败", icon: "none" }); Taro.showToast({ title: data?.detail || data?.msg || "支付发起失败", icon: "none" });
} }
}, },
fail: () => Taro.showToast({ title: "网络错误", icon: "none" }), fail: () => Taro.showToast({ title: "网络错误", icon: "none" }),
@@ -316,13 +338,7 @@ const Book = () => {
type="primary" type="primary"
size="normal" size="normal"
className="joinSalon" className="joinSalon"
onClick={() => { onClick={() => payh5("book", 4900)}
if (isWeChat) {
payh5("book", 4900);
} else {
window.location.href = "https://mp.weixin.qq.com/s/PBbnS8qC_kqhL9HJO5m-Iw";
}
}}
> >
</AtButton> </AtButton>