vue history模式下的微信支付,及微信支付授权目录的填写,处理URL未注册

微信公众号配置网页授权域名:填写网址域名

微信开发者平台配置url:

访问url:http://www.baidu.com/pay/ment
支付授权目录:http://www.baidu.com/pay/

访问url:http://www.baidu.com/pay
支付授权目录:http://www.baidu.com/

访问url:http://www.baidu.com/pay/ment?id=123
支付授权目录:http://www.baidu.com/pay/

 / 记得加上

下面是微信支付页:

<template>
  <div id='wxPay'>
  </div>
</template>

<script>
export default {
  data () {
    return {
      name: '微信支付页',
      router: 'wxPay',
      payJson: {}
    }
  },
  methods: {
    get_jsapi_ticket () {
      let payJson = eval('(' + this.payJson + ')') // eslint-disable-line
      console.log(payJson)
      this.api.get_jsapi_ticket({ url: window.location.href }).then(res => {
        wx.config({ // eslint-disable-line
          debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
          appId: res.data.appId, // 必填,公众号的唯一标识
          timestamp: res.data.timestamp, // 必填,生成签名的时间戳
          nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
          signature: res.data.signature, // 必填,签名
          jsApiList: ['chooseWXPay'] // 必填,需要使用的JS接口列表
        })
        wx.ready(() => { // eslint-disable-line
          wx.chooseWXPay({ // eslint-disable-line
            timestamp: payJson.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
            nonceStr: payJson.nonceStr, // 支付签名随机串,不长于 32 位
            package: payJson.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
            signType: payJson.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
            paySign: payJson.paySign, // 支付签名
            success: function (res) {
              // 支付成功后的回调函数
              this.$router.push('/myIndex')
            },
            fail: function (res) {
              // 失败回调函数
              this.$router.push('/myIndex')
            }
          })
        })
        wx.error(err => { // eslint-disable-line
          alert(err)
        })
      })
    }
  },
  created () {
    document.title = '支付中'
    this.payJson = decodeURIComponent(this.$route.query.payJson)
    this.get_jsapi_ticket()
  }
}
</script>

  有问题可以加我QQ:412606846(微信同号)

原文地址:https://www.cnblogs.com/zlfProgrammer/p/11585663.html