Home > Web Front-end > uni-app > body text

How to apply for WeChat login in uniapp

藏色散人
Release: 2023-01-13 00:44:30
Original
5413 people have browsed it

The method for uniapp to apply for WeChat login: first register for the WeChat open platform and conduct enterprise certification; then obtain the appid and secret key; then enter the "manifest.json" setting in the client code; finally implement the click login method code That’s it.

How to apply for WeChat login in uniapp

The operating environment of this tutorial: windows7 system, uni-app2.5.1 version, Dell G3 computer.

Recommended (free): uni-app tutorial

uniapp implements APP WeChat login process

1. Register for WeChat open platform

1, register account

https://open.weixin.qq.com

2, enterprise authentication (WeChat login must be authenticated)

3. Create an application and fill in the information

4. Waiting for review

5. Obtain the appid and secret key (just open the APP payment and bind the merchant)

2. Enter manifest.json settings in the client code

##3. Login interface code implementation

Write a login button

<button  class="confirm-btn" @click="weixinLo">微信登录</button>
Copy after login
Implement the click login method code and instructions


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'
									});
								}
							});
					}
				});
			},
Copy after login

The above is the detailed content of How to apply for WeChat login in uniapp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template