hsy 2 天之前
父節點
當前提交
341dd8ed76
共有 2 個文件被更改,包括 33 次插入6 次删除
  1. 1 1
      src/views/promotion/components/PaymentDialog.vue
  2. 32 5
      src/views/promotion/goods.vue

+ 1 - 1
src/views/promotion/components/PaymentDialog.vue

@@ -132,7 +132,7 @@ const handleConfirm = async () => {
     return;
   }
 
-  // props.onConfirm?.();
+  props.onConfirm?.(phone.value, verificationCode.value);
 };
 </script>
 

+ 32 - 5
src/views/promotion/goods.vue

@@ -97,10 +97,35 @@ const showDialog = ref(false);
 const handleClose = () => {
   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");
   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 = () => {
   showDialog.value = true;
@@ -134,7 +159,8 @@ const wxConfig = async () => {
     console.log(res);
   });
 };
-
+const appId = ref(localStorage.getItem("appId"));
+const openId = ref("ozZpI7OTqj9cNlHfzAxcJ9MH41V8");
 const getWeChatAuth = async () => {
   const { appId, errMsg, paymentSettingId } = await preCheck();
   if (errMsg) {
@@ -142,6 +168,7 @@ const getWeChatAuth = async () => {
   }
   if (appId) {
     //缓存信息
+    localStorage.setItem("appId", appId);
     localStorage.setItem("paymentSettingId", paymentSettingId);
     //跳转微信授权
 
@@ -165,7 +192,7 @@ const getOpenId = async () => {
       },
     }
   );
-
+  openId.value = data.openId;
 };
 const init = async () => {
   const { code } = route.query;
@@ -173,7 +200,7 @@ const init = async () => {
   if (!code || !paymentSettingId) {
     return getWeChatAuth();
   }
-  getOpenId()
+  // getOpenId()
   wxConfig();
 };
 onMounted(() => init());