有乎-价值、共享、信任

What you care about-value, sharing, trust

微信小程序解决getUserInfo出现微信用户的问题

| 阅读:1700 发表时间:2021-08-12 16:47:51 技术专栏

1、直接去掉原 接口

  open-type='getUserInfo'  bindgetuserinfo='onGetUserInfo'   //直接删除

2、修改为:

<button bindtap='getUserProfile'>授权用户信息</button>

3、添加方法:

getUserProfile:function(){
    wx.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
      success: (res) => {
        console.log("获取用户信息成功", res)
      },
      fail: res => {
        console.log("获取用户信息失败", res)
      }
})
}

接口返回数据如下所示: 

  kxpvwxynu0.png

4、此时就可以获取到用户的头像名称等

 wx.setStorageSync("_userInfo", res.userInfo)
*文章为作者独立观点,不代表【uuuho有乎】的立场
本文由【uuuho有乎】发表并编辑,转载此文章须经作者同意,并请附上出处及本页链接。如有侵权,请联系本站删除。

Who are we?