代码片段(wxml):
<view class="unlogin-body">
<view class="unlogin">
<image class="unlogin-image" src="../../images/mine02.png"></image>
<button class="unlogin-btn" open-type="getUserInfo" bindtap="toLogin"> 微信一键登录 </button>
</view>
代码片段(js):
toLogin() {
wx.getUserProfile({
desc: '获取信息并登录',
success:(res) =>{
console.log(res);
}
})
},
wx.getUserProfile 接口有调整,目前已经不能获取用户微信头像和昵称,默认返回的是灰色头像和“微信用户”,也没有授权弹窗了(除了旧版本微信[基础库版本低于2.27.1]和接口调整生效期前发布的小程序版本外),参考公告:https://developers.weixin.qq.com/community/develop/doc/00022c683e8a80b29bed2142b56c01
当前如果有头像和昵称获取的需要,只能让用户自己填写:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/userProfile.html