1、通过wx.login获取code值,再使用wx.getUserInfo传递code值获取用户信息,下面看代码太多了
<button class="dgq-btn" size="mini" open-type="getUserInfo" type="primary" bindgetuserinfo="yx">允许</button>
yx(e){
console.log(e)
wx.login({
success: res => {
// console.log(res)
let {code}=res
wx.getUserInfo({
success:res=>{
console.log(res)
let {encryptedData,iv}=res
wx.login({
complete: (res) => {
let {code}=res
wx.request({
//注册用户信息
url: 'https://api.it120.cc/dgq/user/wxapp/register/complex',
method:"POST",
header:{
'content-type':'application/x-www-form-urlencoded'
},
data:{
iv,
encryptedData,
code
},
success:res=>{
console.log(res)
}
})
},
})
}
})
// 登录
getdl(code).then(res=>{
console.log(res)
let token=res.data.token
wx.setStorageSync('token', token)
})
wx.showToast({
title: '登录成功',
icon:'success',
duration:1000
})
},
})
},
登录接口我是进行了一个封装,如何封装api接口可以看我的博客