uniapp的微信小程序微信授权登录

一、授权用户公开信息

            // 授权公开信息
			authorization() {
				uni.getUserProfile({
					desc: '授权',
					success: (res) => {
						console.log('getUserProfile',res)
						this.information = true
					}
				});
			},

展示效果:

二、获取手机号授权

            // 绑定手机号码
			handePhoneNumber(e){
				var that = this
				console.log(e,'打印')
				this.userPhoneInfo = e.detail
				if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
					uni.showToast({
						title: '授权失败,请先确认授权手机号',
						icon: 'none',
						duration: 2000
					});
				} else {
					this.phoneNumber = true
					console.log(this.phoneNumber,'手机号授权状态')
				}
			}

 效果如下:

 

 三、调用后台的登录接口

                           uni.request({
								url: '后台接口',
								method: 'POST',
								dataType: 'json',
								data: {
									encryptedData:this.userPhoneInfo.encryptedData,
									iv:this.userPhoneInfo.iv,
									openId:this.openId,
									nickName:this.userInFo.nickName,
									unionId:'',									
									avatarUrl:this.userInFo.avatarUrl
								},
								success: res => {
									console.log(res,'用户注册返回')
								}
							});

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值