小程序获取用户信息

155 阅读1分钟

1.只用于展示自己的用户信息--开放能力open-data

https://developers.weixin.qq.com/miniprogram/dev/component/open-data.html

2.通过button open-type="getUserInfo"来获取用户信息

  1.先进行点击按钮授权

 2. 具体方法:先判断用户是否授权,授权过,再调用wx.getUserInfo()
  
   
    onLoad:functions(options){
        //先判断用户是否授权过
        wx.getSetting({//具体看手册
            seccess:res=>{
                console.log(res)
                if(res.authSetting['scopeUserInfo']){//授权过,调用wx.getUserInfo()
                    wx.getUserInfo({
                        success:res => {
                            console.log(res)
                        }
                    })
                }
            }
        })
    }