
微信小程序对于用户信息获取进行了接口调整。调用 wxgetUserInfo(Object object) 不会再由d窗授权提示。在已授权时,可以直接获取用户信息;否则则直接进入 fail 回调函数。
用户的授权状态可以用 wxgetSetting() 接口的请求的结果
resauthSetting['scopeuserInfo'] 来判断。
那么在接口调整后,再进行授权登录则需要通过 open-data 来实现。
注:如果用户微信版本不支持open-data,需要提示用户升级。这次接口的调整实际上使得按一次d窗中的授权按钮即可授权的 *** 作变成了需要按两次,并且需要额外设计授权页面或者在主页先进行一次d窗引导用户授权。实际上更加繁琐。
pageonload
判断pageonload 中是否定义了 thisuserInfoReadyCallback
❗️注:因为 wxgetUserInfo 是异步的,不知道异步先执行完毕还是pageonload先执行完毕
小程序所有新进用户的昵称全部变成了“微信昵称”,当时我就
吓得我赶紧爬起来翻文档(需要代码直接往后翻)
原因就像微信所说的,很多开发者在打开小程序时就通过组件方式唤起getUserInfod窗,如果用户点击拒绝,无法使用小程序,这种做法打断了用户正常使用小程序的流程,同时也不利于小程序获取新用户。
这里我会给出Uni-app的适配代码,针对CRMEB系统进行修复,各位同学举一反三(413号之前发布的正式包暂不影响)
1修改pages/users/wechat_login/indexvue中关于微信登录的按钮
<button span=""
class="bg-green btn1">微信登录
<button span=""
class="bg-green btn1">微信登录
2默认data中添加canUseGetUserProfile: false,然后在加载页面调用的方法里面增加unigetUserProfile的判断,是否显示新的按钮。
canUseGetUserProfile: false
if (unigetUserProfile) {
thiscanUseGetUserProfile = true
}
3方法中新增getUserProfile方法用户获取用户信息
//小程序授权api替换 getUserInfo
getUserProfile() {
unishowLoading({
title: '正在登录中'
});
let self = this;
RoutinegetUserProfile()
then(res => {
let userInfo = resuserInfo;
userInfocode = thiscode;
userInfospread_spid = appglobalDataspid; //获取推广人ID
userInfospread_code = appglobalDatacode; //获取推广人分享二维码ID
RoutineauthUserInfo(userInfo)
then(res => {
if (resdatakey !== undefined && resdatakey) {
unihideLoading();
selfauthKey = resdatakey;
selfisPhoneBox = true;
} else {
unihideLoading();
let time = resdataexpires_time - self$Cachetime();
self$storecommit('LOGIN', {
token: resdatatoken,
time: time
});
thisgetUserInfo()
}
})
catch(res => {
unihideLoading();
unishowToast({
title: resmsg,
icon: 'none',
duration: 2000
});
});
})
catch(res => {
unihideLoading();
});
},
4然后在libs/routinejs中增加getUserProfile方法
/
新版小程序获取用户信息 2021 413微信小程序开始正式启用
/
getUserProfile(code) {
return new Promise((resolve, reject) => {
unigetUserProfile({
lang: 'zh_CN',
success(user) {
if (code) usercode = code;
resolve({
userInfo: user,
islogin: false
});
},
fail(res) {
reject(res);
}
})
})
}
这里要注意
if (!isset($userInfoCong['openid'])) {
throw new ValidateException('openid获取失败');
}
if (!isset($userInfoCong['openid'])) {
throw new ValidateException('openid获取失败');
}
userInfo['unionId'] = isset( userInfo [′ unionId ′]= isset (userInfoCong['unionid']) $userInfoCong['unionid'] : '';
userInfo['openId'] = userInfo [′ openId ′]=openid = $userInfoCong['openid'];
修复完成之后重新编译小程序就可以解决授权之后微信用户的问题啦。
以上就是关于微信小程序用户信息获取接口的调整全部的内容,包括:微信小程序用户信息获取接口的调整、微信小程序:userInfoReadyCallback介绍、微信小程序getUserProfile详解,CRMEB系统修复流程等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)