uniapp实现APP微信登录流程

1、注册微信开放平台

 

1、注册账号

https://open.weixin.qq.com/

 

2、企业认证 (微信登录必须认证)

 

3、创建应用填写信息

 

 

4、等待审核

 

5、获取appid和秘钥(开通APP支付绑定商户即可)

 

 

2、用户端代码中进入manifest.json设置

 

3、登录界面代码实现

写一个登录按钮

<button  class="confirm-btn" @click="weixinLo">微信登录</button>

实现点击登录方法代码以及说明

weixinLo() {
				let that = this;
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						that.$queue.showLoading('正在登录中...');
						console.error(loginRes.authResult);
//获取登录的token
that.$queue.setData('weixinToken',loginRes.authResult.access_token);
//获取登录的unionid 这个还是在开放平台做了 公众号 小程序 微信登录app关联才会有
						that.$queue.setData('unionid', loginRes.authResult.unionid);
//获取openid
						that.$queue.setData('weixinOpenid', loginRes.authResult.openid);
//这里吧数据全部提交给后台核验,有没有注册 注册了 后台代码会请求接口String s = HttpClient.doGet("https://api.weixin.qq.com/sns/userinfo?access_token=" + loginInfo.getToken() + "&openid=" + loginInfo.getOpenid()); 获取头像和昵称
						that.$Request
							.postJson('/user/loginApp', {
								token: loginRes.authResult.access_token,
								unionid: loginRes.authResult.unionid,
								openid: loginRes.authResult.openid
							})
							.then(res => {
								if (res.status === 0) {

									//绑定手机号直接登录
									that.getUserInfo(res.data.userId, res.data.uuid);
								} else {
									//没有绑定手机号让绑定手机号
									uni.navigateTo({
										url: '/pages/public/wxmobile'
									});
								}
							});
					}
				});
			},

 

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值