WeChat Official Account Payment-Notes

 

1. Pull up WeChat login to get the code code https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxxxxx&redirect_uri=callback address of the client page & response_type = code & scope = snsapi_base & state = STATE # wechat_redirect

Note 1. The callback URL of the client page needs to use encodeURI (http: // xxxxxxxx)

        2. If it is vue's hash mode, perform step 1 and there will be a failure to pull up the login because two # appear on the url 

2. Get the code value in exchange for WeChat's openid

3. Initiate business payment process

payOrder () {
      let payDto = {
        'amount': this.amount,
        'payInfo': this.notice,
        'name': this.name,
        'idCardNum': this.idCardNum,
        'mobile': this.mobile
      }
      wxpayH5Create(payDto).then(result => {
        var resu = result.data.result
        this.onBridgeReady(resu)
      })
    },
onBridgeReady (resu) {
      WeixinJSBridge.invoke(
        'getBrandWCPayRequest', {
        'appId': resu.appid,
        'timeStamp': resu.timeStamp,
        'nonceStr': resu.nonceStr,
        'package': resu.package,
        'signType': resu.signType,
        'paySign': resu.paySign
      },
        (res)=> {if (res.err_msg.indexOf('ok') !== -1) {
            this.$router.push({
              path: 'reportIndex',
              query: {
                name: this.name,
                idCardNum: this.idCardNum,
                mobile: this.mobile
              }
            })
          }
        })
    }

Note: WeixinJSBridge is provided inside WeChat browser, other browsers cannot use this function to call payment

 

Guess you like

Origin www.cnblogs.com/caoruichun/p/12695382.html
Recommended