官方文檔中:
wx.getUserInfo(OBJECT)
注意:此接口有調整,使用該接口將不再出現授權彈窗,請使用 <button open-type="getUserInfo"></button> 引導用戶主動進行授權操作
- 當用戶未授權過,調用該接口將直接報錯
- 當用戶授權過,可以使用該接口獲取用戶信息
所以,以後不建議直接調用:
wx.getUserInfo({
success: function(res) {
console(res.userInfo)
}
})
建議改用:
wmxl:
<button wx:if="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授權登錄</button>
<view wx:else>請升級微信版本</view>
js:
data: {
canIUse: wx.canIUse("button.open-type.getUserInfo")
},
bindGetUserInfo: function (e) {
console.log(e)
}