首先做微信支付的话是需要code
加载的时候放下边代码
if (option.code != null && (this.openid == null || this.openid == '')) {
this.code = option.code
this.getOpenId()
}
if (url.indexOf('?code=') != -1 && (this.openid == null || this.openid == '')) {
this.code = url.substring(url.indexOf('?code=') + 6, url.indexOf('&state='));
this.getOpenId()
console.log(this.code)
} else {
console.log("不需要code切割")
}
这是触发方法,唤醒支付
// 这是H5微信支付
h5pay() {
let that = this
if (that.openid && that.openid !== '' && that.openid !== 'undefined') {
if (this.priceIndex == 0) {
this.getordinary()
} else if (this.priceIndex == 1 || this.priceIndex == 3) {
// 团购支付
this.getBuybuing()
}
} else {
if (that.code) {
console.log("33")
uni.request({
url: helper.api + '/app/wxPay/getTokenByCode',
method: 'GET',
header: {
'content-type': 'app