微信小程序登录流程登录代码
<button open-type="getUserInfo" @tap="getUserProfile" class="weixin-btn mt-4" type="default">微信登录</button>
// methods 方法
getUserProfile(e){
uni.getUserProfile({
desc: 'weixin', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
console.log(res);
console.log(res.userInfo.avatarUrl);//获取用户微信头像
console.log(res.userInfo.nickName);//获取用户微信名
this.getUserInfoLogin(res)
}
})
},
getUserInfoLogin(uInfo){
uni.login({
provider: 'weixin',
success: (loginRes)=> {
console.log(loginRes,'openID>>>>>>>>>>')
this.code = loginRes.code
// 获取用户信息
this.login(uInfo.userInfo.nickName,uInfo.userInfo.avatarUrl)
}
})
},
// 登录接口
login(){
//登录的逻辑
}