微信小程序获取用户信息

获取用户信息

wx.getUserInfo在2021年4月13日后,不再弹出弹窗,并且返回的值变为匿名的个人信息

旧版本写法(wx.getUserInfo)

<!-- index.wxml -->
<button open-type="getUserInfo" bindgetuserinfo="handleGetUserInfo">登录</button>
// index.js
Page({
  handleGetUserInfo(e) {
    console.log(e.detail.userInfo)
  }
 })

现在的方法(wx.getUserProfile)

<!-- index.wxml -->
<button bindtap="handleGetUserInfo"></button>
// index.js
Page({
  handleGetUserInfo(e) {
    wx.getUserProfile({
      desc: '用途说明', // 会在弹窗上显示
      success: res => { // 点击确认的回调,返回个人信息
         console.log(res) 
      }
  }
})
原文地址:https://www.cnblogs.com/miao91/p/15733782.html