注册页面使用了
wx.login 获取code
<button class=“weui-btn” bindgetuserinfo=“getUserInfoFun” open-type=“getUserInfo” type=“primary”>
授权微信公开信息
</button>
<button class=“weui-btn” open-type=“getPhoneNumber” bindgetphonenumber=“getPhoneNumber” type=“primary”>
微信快捷领取
</button>
getUserInfoFun: function (e) {
let s = this;
if(e.detail.userInfo){
s.userInfo(e.detail.userInfo);
let avatarUrl = e.detail.userInfo.avatarUrl;
let nickName = e.detail.userInfo.nickName;
wx.setStorageSync(‘avatarUrl’, avatarUrl);
wx.setStorageSync(‘nickName’, nickName);
}
s.setData({
getUserInfoTrue: true
})
}
在其他函数里掉用
const user = this.data.userInfo || {};
let s = this;
let image = user.avatarUrl || wx.getStorageSync(‘avatarUrl’) || ‘’,
nickname = user.nickName || wx.getStorageSync(‘nickName’) || ';
开发工具、开发版、体验版,都可以获取到用户的头像与昵称,发布到正式版用户头像与昵称就获取不到