f
This commit is contained in:
@@ -26,10 +26,10 @@
|
|||||||
活动价:2折优惠
|
活动价:2折优惠
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- 支付方式选择:任意环境均展示微信+支付宝;推广场景 hideWechat 仅支付宝 -->
|
<!-- 支付方式:微信内仅微信(推广 hideWechat 时仅支付宝);非微信仅支付宝 -->
|
||||||
<div class="">
|
<div class="">
|
||||||
<van-cell-group inset>
|
<van-cell-group inset>
|
||||||
<van-cell v-if="!hideWechat" title="微信支付" clickable @click="selectedPaymentMethod = 'wechat'">
|
<van-cell v-if="showWechatPay" title="微信支付" clickable @click="selectedPaymentMethod = 'wechat'">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<van-icon size="24" name="wechat-pay" color="#1AAD19" class="mr-2" />
|
<van-icon size="24" name="wechat-pay" color="#1AAD19" class="mr-2" />
|
||||||
</template>
|
</template>
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</van-cell>
|
</van-cell>
|
||||||
|
|
||||||
<van-cell title="支付宝支付" clickable @click="selectedPaymentMethod = 'alipay'">
|
<van-cell v-if="showAlipayPay" title="支付宝支付" clickable @click="selectedPaymentMethod = 'alipay'">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<van-icon size="24" name="alipay" color="#00A1E9" class="mr-2" />
|
<van-icon size="24" name="alipay" color="#00A1E9" class="mr-2" />
|
||||||
</template>
|
</template>
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, watch, onMounted } from "vue";
|
import { ref, watch, onMounted, computed } from "vue";
|
||||||
import { showConfirmDialog, showToast } from "vant";
|
import { showConfirmDialog, showToast } from "vant";
|
||||||
|
|
||||||
const isDev = import.meta.env.DEV;
|
const isDev = import.meta.env.DEV;
|
||||||
@@ -92,10 +92,22 @@ const props = defineProps({
|
|||||||
});
|
});
|
||||||
const show = defineModel();
|
const show = defineModel();
|
||||||
|
|
||||||
|
function isWechatBrowser() {
|
||||||
|
if (typeof navigator === "undefined") return false;
|
||||||
|
return /MicroMessenger/i.test(navigator.userAgent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 推广强制隐藏微信;非微信环境不展示微信支付 */
|
||||||
|
const showWechatPay = computed(() => !props.hideWechat && isWechatBrowser());
|
||||||
|
|
||||||
|
/** 微信内不展示支付宝;推广 hideWechat 时在微信内只能走支付宝,仍展示 */
|
||||||
|
const showAlipayPay = computed(() => !isWechatBrowser() || props.hideWechat);
|
||||||
|
|
||||||
function defaultPaymentMethod() {
|
function defaultPaymentMethod() {
|
||||||
if (isDev) return "test";
|
if (isDev) return "test";
|
||||||
if (props.hideWechat) return "alipay";
|
if (props.hideWechat) return "alipay";
|
||||||
return "wechat";
|
if (isWechatBrowser()) return "wechat";
|
||||||
|
return "alipay";
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedPaymentMethod = ref(defaultPaymentMethod());
|
const selectedPaymentMethod = ref(defaultPaymentMethod());
|
||||||
@@ -107,7 +119,7 @@ function syncSelectedPaymentMethod() {
|
|||||||
onMounted(syncSelectedPaymentMethod);
|
onMounted(syncSelectedPaymentMethod);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
[() => props.hideWechat, show],
|
[() => props.hideWechat, showWechatPay, showAlipayPay, show],
|
||||||
() => {
|
() => {
|
||||||
if (show.value) {
|
if (show.value) {
|
||||||
syncSelectedPaymentMethod();
|
syncSelectedPaymentMethod();
|
||||||
@@ -248,21 +260,6 @@ async function getPayment() {
|
|||||||
|
|
||||||
const payload = extractWechatJsApiPayload(inner);
|
const payload = extractWechatJsApiPayload(inner);
|
||||||
if (!payload) {
|
if (!payload) {
|
||||||
const ua = typeof navigator !== "undefined" ? navigator.userAgent : "";
|
|
||||||
console.warn("[Payment] 微信支付 JSAPI 参数解析失败 — 原始响应 data 如下(展开 inner)");
|
|
||||||
console.warn("[Payment] inner:", inner);
|
|
||||||
console.warn("[Payment] 详情:", {
|
|
||||||
pay_method: selectedPaymentMethod.value,
|
|
||||||
pay_type: props.type,
|
|
||||||
order_id: props.id,
|
|
||||||
order_no: orderNoFromApi,
|
|
||||||
prepay_id: inner.prepay_id ?? inner.prepayId,
|
|
||||||
prepay_data: inner.prepay_data ?? inner.prepayData,
|
|
||||||
inner_keys: inner && typeof inner === "object" ? Object.keys(inner) : [],
|
|
||||||
response_code: data.value?.code,
|
|
||||||
response_msg: data.value?.msg,
|
|
||||||
user_agent_snippet: ua.slice(0, 120),
|
|
||||||
});
|
|
||||||
showToast(
|
showToast(
|
||||||
"未获取到微信支付参数。请确认:1)后端已部署最新支付接口;2)请求头含 X-Platform: wxh5;3)用户已绑定微信网页授权 openid。"
|
"未获取到微信支付参数。请确认:1)后端已部署最新支付接口;2)请求头含 X-Platform: wxh5;3)用户已绑定微信网页授权 openid。"
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user