uniapp 开发小程序过程中,如何获取微信用户的昵称和头像信息,这个uniapp已经集成,通过getUserInfo即可获取到

loginUser(){
				let _this=this;
				uni.login({
				  provider: 'weixin',
				  success: function (loginRes) {
					console.log(loginRes.authResult);
					// 获取用户信息
					uni.getUserInfo({
					  provider: 'weixin',
					  success: function (infoRes) {
						console.log(infoRes.userInfo)
						console.log('用户昵称为:' + infoRes.userInfo.nickName);
						_this.userNickName=infoRes.userInfo.nickName;
						_this.userAvatar=infoRes.userInfo.avatarUrl;
					  },fail(e) {
					  	console.log(e)
					  }
					});
				  }
				});
微信接口返回如下信息:
nickName: "大帅哥", avatarUrl: "http://wx.qlogo.cn/*******", gender: 1, province: "Beijing", city: "Tongzhou"}
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐