h5微信支付,支付宝支付

2021-09-15  本文已影响0人  IssunRadiance
// 去支付
      goPayFun() {
        var data = {
          pathway: 'h5',
          out_trade_no: this.orderMessage.order_code,
          total_amount: (this.orderMessage.total_amount / 100).toFixed(2)
        }
        if (this.type == 1) { // 微信支付
          data.pay_method = 'wechat'
        }
        if (this.type == 2) {
          data.pay_method = 'alipay'
        }
        wxPay(data).then(res => {
            if (this.type == 1) { // 微信支付
              this.wxpayFun(res)
            }
            if (this.type == 2) {
              this.alipayFun(res)
            }
        })
      },
// 微信支付
      wxpayFun(res) {
        const _html = res.data.html;
        const div = document.createElement("div");
        div.innerHTML = _html;
        document.body.appendChild(div);
      },
// 支付宝支付
      alipayFun(res) {
        const form = res.data.html;
        const div = document.createElement("div");
        div.id = "alipay";
        div.innerHTML = form;
        document.body.appendChild(div);
        document.querySelector("#alipay").children[0].submit();
      },
上一篇下一篇

猜你喜欢

热点阅读