打开页面首先要监测用户是否授权
根据openId 判断
如果没有openid 调后台接口获取
created () { /
document.title = configInfo.getFullName()
let oid = this.$route.query.oid
let bind = this.$route.query.bind
// bind = 'true'
if (oid) { // 监测是否授权
this.openId = Base64.decode(oid.toString())
this.bind = bind
VueCookie.set(OPEN_ID, this.openId) // 把oppenid存到cookie里面 后面大部分接口都需要用到
if (this.bind === 'true') {
this.get_default_bind_customer()
}
} else {
// 开发环境 把授权代码注释掉 openid写死
if (this.isWeixin()) {
this.oauth2Url() // 如果没有oid 也就是oppenid 调后台接口 获取 然后重定向 首页
} else {
this.openId = 'ouiWPjgXqa7TiTVSvy-TMyjPuxG0' // 这里用来测试 造的oppenid
VueCookie.set(OPEN_ID, this.openId)
if (this.bind === 'true') {
this.get_default_bind_customer()
}
}
}
},
methode () {
oauth2Url () {
this.$http(this, {
url: SERVICE_URLS.chargeApi.oauth2_url,
noTips: true,
noErrorTips: true,
success: (data) => {
window.location = data.body
}
})
},
}
充值界面
created () {
this.jssdkConf()
},
methode () {
jssdkConf () {
this.$http(this, {
url: SERVICE_URLS.chargeApi.jssdkConf,
noTips: true,
noErrorTips: true,
success: (data) => {
this.config = data.body
wx.config({
debug: false,
appId: this.config.appId,
timestamp: this.config.timestamp,
nonceStr: this.config.nonceStr,
signature: this.config.signature,
jsApiList: ['chooseWXPay']
})
}
})
},
chongZhi () { // 点击充值的时候调这个 方法
this.$http(this, {
url: SERVICE_URLS.chargeApi.wechatPrepay,
data: {
'openId': this.openId,
'amount': this.value, // 金额
'defaultUserId': this.data.customerId // 用户id
},
noTips: true,
noErrorTips: true,
success: (data) => {
wx.chooseWXPay({
timestamp: data.body.timeStamp,
nonceStr: data.body.nonceStr,
package: data.body.packageContent,
signType: data.body.signType,
paySign: data.body.paySign,
success: function (res) {
// 支付成功 重定向
window.location.href = 'https://chargeh5.jichuanzhongke.com/index' // 这种可行 要重新授权
// this.$router.push({ // 这种有时候可以 后面带上参数就不用重新授权了
// name: 'index',
// query: {
// oid: Base64.encode(this.openId.toString()),
// bind: 'true'
// }
// })
}
})
}
})
},
}
我是个混子,啥都做不好。。。。。