wxml页面:
<button type="primary"
open-type="getUserInfo"
lang="zh_CN"
bindgetuserinfo="getUserInfo">获取用户信息</button>
解释:
- 使用button实现授权 open-type="getUserInfo"
- open-type="share" 实现分享
- 授权之后可以在onLoad()中使用wx.getUserInfo()获取用户信息
js页面:
onLoad(){
wx.getUserInfo({
success: function(res){
console.log(res)
}
})
}
判断用户是否授权
onLoad(){
wx.getSetting({
success: res=>{
/* 为真则表示授权 */
if(res.authSetting["scope.userInfo"]){
}else{
}
}
});
}