一、登陆相关
1、wx.login
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})
获得的结果可以使用res.code
取出此code值,可以根据code获取对应的openId, sessionKey, unionId,详见官方文档。
2、wx.getUserInfo
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
获取微信用户基本信息。