wx.login({
success: function (res) {
var vcode = res.code;
console.log('login code:' + vcode);
console.log(that.data.canIUseGetUserProfile)
if (vcode) {
console.log(11)
wx.getUserProfile({
desc:'用于获取头像昵称',
success: function (resp) {
console.log('getUserInfo successd........');
var encryptedData = encodeURIComponent(resp.encryptedData);
me.ajaxPost('/user/login', {
tuiuid: me.appQuery.shareuid,
code: vcode,
encryptData: resp.encryptedData,
iv: resp.iv,
}, function (ret) {
wx.hideLoading();
console.log(ret.sdata);
console.log(ret);
if (ret.errcode == 0) {
try {
me.gUser = ret.sdata
me.cache().set('loginUser', ret.sdata)
cb && cb(true)
} catch (e) {
cb && cb(false)
console.log(e)
}
} else {
console.log(ret.msg)
}
})
},
fail: function (res) {
wx.hideLoading()
console.log('getUserInfo fail:未授权');
console.log(res);
}
})
}
1、小程序用户头像昵称获取规则调整公告https://developers.weixin.qq.com/community/develop/doc/00022c683e8a80b29bed2142b56c01
2、
wx.getUserProfile 即将收回,请参考 https://developers.weixin.qq.com/community/develop/article/doc/00042614f28d6074adeda7e9651c13