0
点赞
收藏
分享

微信扫一扫

uniapp uni.getUserProfile的使用

钟罗敏 2022-03-11 阅读 48

小程序登录、用户信息相关接口调整说明:链接地址

考虑到近期开发者对小程序登录、用户信息相关接口调整的相关反馈,为优化开发者调整接口的体验,回收wx.getUserInfo接口可获取用户授权的个人信息能力的截止时间由2021年4月13日调整至2021年4月28日24时;

最近再用uniapp做一款小程序,使用**uni.getUserInfo()**一直获取不到数据,在官网上看到了上面的公告

一、使用方法

html中:

<button @click="goLogin" class="bottom-btn" type="default" size="mini">登入</button>

js中

      goLogin() {
            //判断缓存中是否有用户数据,没有则获取
			if (!uni.getStorageSync('encryptedData')) {
				uni.getUserProfile({
					desc: '獲取您的昵稱、頭像、地區及性別',
					success: infoRes => {
						if (infoRes.errMsg === 'getUserProfile:ok') {
                            // 获取到的当前数据存入缓存
							uni.setStorageSync('encryptedData', infoRes.encryptedData);
							uni.setStorageSync('iv', infoRes.iv);
							uni.setStorageSync('rawData', infoRes.rawData);
							uni.setStorageSync('signature', infoRes.signature);
							uni.setStorageSync('securityStatus', 1);
                            // 选择版本
							uni.navigateTo({
								url: '/platforms/mp-weixin/register/registerVersion'
							});
						} else {
							uni.showToast({
								title: '授權失敗',
								icon: 'error'
							});
						}
					},
					fail: err => {
						console.log('userInfo-err', JSON.stringify(err));
					}
				});
			} else {
				uni.navigateTo({
					url: '/platforms/mp-weixin/register/registerVersion'
				});
			}
		}
举报

相关推荐

0 条评论