微信版本8.0.17 基础库2.21.4 button getphoneNumber登录,页面初始化获取了code然后我操作登录授权是页面初始化10分钟左右,然后提示我1005
<button
type="default"
:loading="loginLoading"
open-type="getPhoneNumber"
@getphonenumber="decryptPhoneNumber"
class="login__wx"
>授权登录</button>
getWxcode () {
wx.login({
provider: 'weixin',
success: (loginRes) => {
this.code = loginRes.code
uni.setStorageSync('tyycode', loginRes.code)
}
})
},
decryptPhoneNumber (e) {
if (this.loginLoading) return
if (e.detail.errMsg === 'getPhoneNumber:ok') {
uni.showLoading({
title: '登录中...'
})
const encryptedData = e.detail.encryptedData
const iv = e.detail.iv
wx.checkSession({
success: (res) => {
console.log(res)
this.phoneLogin(encryptedData, iv)
},
fail: (err) => {
uni.login({
provider: 'weixin',
success: (res) => {
this.code = res.code
this.phoneLogin(encryptedData, iv)
}
})
}
})
}
},
async phoneLogin (encryptedData, iv) {
let _this = this
this.loginLoading = true
const resData = await api.login.wxLogin({
encryptedData,
iv,
code: this.code
})
const { errcode = '', data = {}, message = '登录失败' } = resData
uni.hideLoading()
if (errcode === 0) {
// "is_need_login": 2 // 是否需要重新登陆:0不需要,1需要
const {
api_token = ''
} = data
uni.showToast({
title: '登录成功',
icon: 'success',
duration: 1500,
success: () => {
uni.setStorageSync('api_token', api_token)
_this.$store.commit(IS_NEED_LOGIN, 0)
_this.loginLoading = false
uni.reLaunch({
url: `/pages/index/index`
})
}
})
} else if (errcode === 1500) {
this.$refs['popup'].open()
this.getWxcode()
this.loginLoading = false
} else {
this.loginLoading = false
this.getWxcode()
uni.showToast({
title: message,
icon: 'none'
})
}
},
popupClick () {
this.$refs['popup'].close()
}
},
errcode 后端返回的,找后端定位问题啊,前后端不沟通的吗
这个问题和我之前遇到的问题好像,
当时我是在onLoad那里获取code传给后台就不出现这个问题了