微信支付(关于h5支付与JSAPI支付)

设置order.vue页面:

pay.vue:

mounted() {
          
   
    this.initData();
},
async initData() {
          
   
    let {
          
    amount, tradeno, openid } = this.$route.query;
    this.amount = amount;
    let obj = {
          
   
        tradeno,
        paytype: this.isWeixin ? 1 : 0,
    };
    if (openid) {
          
   
        obj.openid = openid;
    }
    let res = await this.$http.post(this.$api.WXPAYPARAM, obj);
    this.url = res.url;
    this.timestamp = res.timeStamp || res.timestamp;
    this.nonceStr = res.nonceStr;
    this.package1 = res.package;
    this.signType = res.signType;
    this.paySign = res.paySign;
    this.appId = res.appId;
},
goToPage() {
          
   
    window.location.href = this.url;
},

通过上面的简单介绍,画个简单的图

贴上pay.vue完整代码

经验分享 程序员 微信小程序 职场和发展