wx.getUserInfo(OBJECT)只能获取nickName,avatarUrl,gender这些
A:openid两种获取方法。
1.login获得code。在用code换openid和一个密匙
2.userinfo有个加密的data。解密获得openid
- onLoad: function () {
- var that = this
- wx.login({
- success: function (res) {
- console.log("res.code====="+res.code);
- if (res.code) {
- //发起网络请求
- wx.request({
- url: 'https://api.weixin.qq.com/sns/jscode2session?appid=wxaasdf22we1sdffe3&secret=83ebdsdfsdfa7sdfsdf3448ff3f71&js_code=' + res.code + '&grant_type=authorization_code',
- method: "POST",
- success: function (res) {
-
- that.setData({
- openid: res.data.openid
- })
- }
- })
- } else {
- console.log('获取用户登录态失败!' + res.errMsg)
- }
- }
- });
- }