// 检查URL中是否包含code参数
checkCode() {
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
const state = urlParams.get('state');
if (code && state) {
// 如果有code,则存起来
if (this.codeUsed) {
this.wxLogin()
} else {
this.wxCode = code
this.state = state
}
} else {
// 如果没有code,可能是授权失败,给出提示或处理
this.wxLogin()
}
},
// 通过type / 域名 获取code
wxLogin() {
getSocialRedirect({
type: 31, // 31:微信公众号 34:微信小程序
redirectUri: BASEURL, // BASEURL,
}).then(res => {
window.location.href = res.data // 去获取code
this.getUrlCode(res.data)
this.codeUsed = false
}).catch(err => {
uni.showToast({
title: err.msg,
icon: 'none'
})
})
},