您的当前位置:首页正文

uniapp小程序实现微信登录

2024-11-27 来源:个人技术集锦
getWXname() {
				var that = this;
				uni.showLoading({ // 展示加载框
					title: '加载中',
				});
				uni.getUserProfile({ //获取到用户信息
					desc: '登录后可同步数据',
					success: async (obj) => {
						// console.log('obj', obj);
						that.nickName = obj.userInfo.nickName //用户名
						that.avatarUrl = obj.userInfo.avatarUrl //用户头像

						// 调用 action ,请求登录接口
						uni.login({
							provider: 'weixin',
							success: (res) => {
								console.log('res-login', res);
								//获取到code
								that.code = res.code;
								// console.log('code', res.code);

								//请求登录接口
								if (res.errMsg == 'login:ok') {
									var params = {
										code: that.code,
										nickname: that.nickName,
										avatar: that.avatarUrl
									}

									$http.request({
										url: "/api/member/user_center", 
										data: {
											user_id: 1
										}
						
显示全文