20161128微信小程序学习笔记-NO.2获取用户信息

wx.getUserInfo(OBJECT)

获取用户信息,需要先调用 wx.login接口。

  • 获取用户基本信息
wx.getUserInfo({ 
  success: function(res) { 
    var userInfo = res.userInfo 
    var nickName = userInfo.nickName 
    var avatarUrl = userInfo.avatarUrl 
    var gender = userInfo.gender 
    var province = userInfo.province 
    var city = userInfo.city 
    var country = userInfo.country 
    }
})
  • 获取用户的openid和unionID信息
{ 
  "openId": "OPENID", 
  "nickName": "NICKNAME", 
  "gender": GENDER, 
  "city": "CITY", 
  "province": "PROVINCE", 
  "country": "COUNTRY", 
  "avatarUrl": "AVATARURL", 
  "unionId": "UNIONID", 
  "watermark": { 
    "appid":"APPID", 
    "timestamp":TIMESTAMP
   }
}

从代码上可以看出,用户的所有信息都能从接口上获取到,可以用于给用户添加标签与后台数据结合,对目标用户进行分类

你可能感兴趣的:(20161128微信小程序学习笔记-NO.2获取用户信息)