uniapp uni.getUserProfile的使用

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

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

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

一、使用方法

       html中:

        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'
				});
			}
		}

你可能感兴趣的:(uni-app)