7. 用户授权-获取用户信息

wxml页面:


解释:

  1. 使用button实现授权 open-type="getUserInfo"
  2. open-type="share" 实现分享
  3. 授权之后可以在onLoad()中使用wx.getUserInfo()获取用户信息
    js页面:
onLoad(){
     wx.getUserInfo({
      success: function(res){
        console.log(res)
      }
    })
}

判断用户是否授权

wx.getSetting

onLoad(){
    wx.getSetting({
      success: res=>{
        /* 为真则表示授权 */
        if(res.authSetting["scope.userInfo"]){

        }else{

        }
      }
    });
}

你可能感兴趣的:(7. 用户授权-获取用户信息)