's'
This commit is contained in:
@@ -238,18 +238,40 @@ const Book = () => {
|
||||
setTimeout(() => document.body.removeChild(form), 1000);
|
||||
};
|
||||
|
||||
// 参考 nomadvip 解锁 VIP:微信内必须 xorpay,PC/手机浏览器 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 uid = getOrCreateUserId();
|
||||
const returnUrl = typeof window !== "undefined" ? `${window.location.origin}${window.location.pathname || "/book"}` : "";
|
||||
const { device, provider } = getDeviceAndProvider();
|
||||
Taro.request({
|
||||
method: "POST",
|
||||
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" },
|
||||
success: (res) => {
|
||||
if (res.data?.status === "ok" && res.data?.xorpay_params) {
|
||||
submitPayForm(res.data.xorpay_url, res.data.xorpay_params);
|
||||
const data = res.data || {};
|
||||
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 {
|
||||
Taro.showToast({ title: "支付发起失败", icon: "none" });
|
||||
Taro.showToast({ title: data?.detail || data?.msg || "支付发起失败", icon: "none" });
|
||||
}
|
||||
},
|
||||
fail: () => Taro.showToast({ title: "网络错误", icon: "none" }),
|
||||
@@ -316,13 +338,7 @@ const Book = () => {
|
||||
type="primary"
|
||||
size="normal"
|
||||
className="joinSalon"
|
||||
onClick={() => {
|
||||
if (isWeChat) {
|
||||
payh5("book", 4900);
|
||||
} else {
|
||||
window.location.href = "https://mp.weixin.qq.com/s/PBbnS8qC_kqhL9HJO5m-Iw";
|
||||
}
|
||||
}}
|
||||
onClick={() => payh5("book", 4900)}
|
||||
>
|
||||
阅读更多
|
||||
</AtButton>
|
||||
|
||||
Reference in New Issue
Block a user