我用的官方代码,但是一直获取不到unionid,代码如下:
// 登录
login: function(that) {
wx.login({
success: res => {
wx.request({
url: ‘https://api.weixin.qq.com/sns/jscode2session’,
data: {
appid: ‘(本程序)’,
secret: ‘(本程序)’,
js_code: res.code,
grant_type: ‘authorization_code’
},
success: function(response) {
wx.getUserInfo({
withCredentials: true,
success: re => {
that.globalData.userInfo = re.userInfo;
wx.request({
url: that.serverUrl + ‘login/EncryptedUnionId’,
data: {
encryptedData: re.encryptedData,
iv: re.iv,
sessionKey: response.data.session_key
},
header: {
‘content-type’: ‘application/json’
},
success: function® {
//把unionid存到本地
}
});
}
});
}
});
}
});
},