Vue H5微信瀏覽器外進行支付 H5支付

weixin_44079209發表於2020-11-13

主要思路是後端返回Url地址前端跳轉

前端利用window.location.href = res2.data.data.mweb_url;進行跳轉

// 點選按鈕購買會員 H5支付
    mobileZifuvip(i) {
      console.log(i);
      let that = this;
      this.axios(
        config +
          "/order/purchaseMember?userId=" +
          localStorage.getItem("userId") +
          "&commodityNumber=" +
          i,
        {
          sessionId: this.sessionId,
          userId: localStorage.getItem("userId"),
          spbillCreateIp: this.clientIp,
          method: "post",
          headers: {
            Authorization: localStorage.getItem("token")
          }
        }
      )
        .then(res => {
          // console.log(res, '支付資訊')
          that.closeFullScreen(that.openFullScreen()); // 取消載入
          // 獲取請求引數
          this.axios({
            url:
              config + "/pay?type=WX_MWEB&&orderNumber=" + res.data.orderNumber,
            headers: {
              Authorization: localStorage.getItem("token")
            },
            // data: {
            //   userId : localStorage.getItem("userId"),
            // },
            method: "post"
          })
            .then(res2 => {
              console.log(res2.data, "列印的請求引數");

              window.location.href = res2.data.data.mweb_url;
              if (res.status === 200) {
                // 2. 發起支付請求
                // 獲取引數後跳轉微信支付
                window.location.href = res2.data.data.mweb_url;
              }
            })
            .catch(err => {
              that.closeFullScreen(that.openFullScreen()); // 取消載入
              console.log(err);
            });
        })
        .catch(err => {
          that.closeFullScreen(that.openFullScreen()); // 取消載入
          console.log(err);
        });
    },

相關文章