|
@@ -97,10 +97,35 @@ const showDialog = ref(false);
|
|
const handleClose = () => {
|
|
const handleClose = () => {
|
|
showDialog.value = false;
|
|
showDialog.value = false;
|
|
};
|
|
};
|
|
-
|
|
|
|
-const handleConfirm = () => {
|
|
|
|
|
|
+function onBridgeReady(paySign) {
|
|
|
|
+ WeixinJSBridge.invoke(
|
|
|
|
+ "getBrandWCPayRequest",
|
|
|
|
+ {
|
|
|
|
+ appId: appId.value, //公众号ID,由商户传入
|
|
|
|
+ ...paySign
|
|
|
|
+ },
|
|
|
|
+ function (res) {
|
|
|
|
+ console.log(res)
|
|
|
|
+ if (res.err_msg == "get_brand_wcpay_request:ok") {
|
|
|
|
+ // 使用以上方式判断前端返回,微信团队郑重提示:
|
|
|
|
+ //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠,商户需进一步调用后端查单确认支付结果。
|
|
|
|
+ console.log("支付成功");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+}
|
|
|
|
+const handleConfirm = async (mobile, captcha) => {
|
|
console.log("Payment confirmed");
|
|
console.log("Payment confirmed");
|
|
showDialog.value = false;
|
|
showDialog.value = false;
|
|
|
|
+ const { data } = await request.post(`/archivesService/member/promotionGoods/paymentParams`, {
|
|
|
|
+ promotionGoodsId: route.query.promotionGoodsId,
|
|
|
|
+ promotionSiteId: route.query.promotionSiteId,
|
|
|
|
+ mobile,
|
|
|
|
+ captcha,
|
|
|
|
+ openId: openId.value,
|
|
|
|
+ });
|
|
|
|
+ console.log(data.paymentParams);
|
|
|
|
+ data.paymentParams?.paySign && onBridgeReady(data.paymentParams.paySign)
|
|
};
|
|
};
|
|
const buy = () => {
|
|
const buy = () => {
|
|
showDialog.value = true;
|
|
showDialog.value = true;
|
|
@@ -134,7 +159,8 @@ const wxConfig = async () => {
|
|
console.log(res);
|
|
console.log(res);
|
|
});
|
|
});
|
|
};
|
|
};
|
|
-
|
|
|
|
|
|
+const appId = ref(localStorage.getItem("appId"));
|
|
|
|
+const openId = ref("ozZpI7OTqj9cNlHfzAxcJ9MH41V8");
|
|
const getWeChatAuth = async () => {
|
|
const getWeChatAuth = async () => {
|
|
const { appId, errMsg, paymentSettingId } = await preCheck();
|
|
const { appId, errMsg, paymentSettingId } = await preCheck();
|
|
if (errMsg) {
|
|
if (errMsg) {
|
|
@@ -142,6 +168,7 @@ const getWeChatAuth = async () => {
|
|
}
|
|
}
|
|
if (appId) {
|
|
if (appId) {
|
|
//缓存信息
|
|
//缓存信息
|
|
|
|
+ localStorage.setItem("appId", appId);
|
|
localStorage.setItem("paymentSettingId", paymentSettingId);
|
|
localStorage.setItem("paymentSettingId", paymentSettingId);
|
|
//跳转微信授权
|
|
//跳转微信授权
|
|
|
|
|
|
@@ -165,7 +192,7 @@ const getOpenId = async () => {
|
|
},
|
|
},
|
|
}
|
|
}
|
|
);
|
|
);
|
|
-
|
|
|
|
|
|
+ openId.value = data.openId;
|
|
};
|
|
};
|
|
const init = async () => {
|
|
const init = async () => {
|
|
const { code } = route.query;
|
|
const { code } = route.query;
|
|
@@ -173,7 +200,7 @@ const init = async () => {
|
|
if (!code || !paymentSettingId) {
|
|
if (!code || !paymentSettingId) {
|
|
return getWeChatAuth();
|
|
return getWeChatAuth();
|
|
}
|
|
}
|
|
- getOpenId()
|
|
|
|
|
|
+ // getOpenId()
|
|
wxConfig();
|
|
wxConfig();
|
|
};
|
|
};
|
|
onMounted(() => init());
|
|
onMounted(() => init());
|