At present, there are two ways to realize WeChat login by scanning code: 1. Authorized login by scanning code on WeChat service number webpage; 2. Authorized login by OAuth2.0 on WeChat open platform

The above two ways without WeChat certification, are the need to pay 300 yuan certification before you can get the development ability. So I thought of WeChat small program, individual developers without authentication can also obtain user information, authorization login, you can simply achieve the same function.

We can use the Weauth platform to achieve it. Weauth provides API. We just need to launch login at the back end, scan the code by WeChat, and then Weauth will forward the user information to our server after authorization.

Request parameters

1, Domain name 2, SK (generated by yourself, up to 32 bits)

The initiating

https://wa.isdot.net/qrcode?str=yourdomain.com@sk

Note: yourdomain.com is yourdomain name (without HTTP) and sk is randomly generated by your back end.

/ / sample at https://wa.isdot.net/qrcode?str=www.qq.com@123456789

After the request is made, Base64’s applet code data is returned, and we need to display the applet authorization code (that is, the applet code).

Sweep WeChat yards

After the user opens WeChat scan and scans the login authorization code, the Weauth backend will issue a login request to your domain name, pay attention to the HTTPS protocol and fixed/Weauth path). The parameter User is the user’s WeChat information, and Sk is the login request verification code.

The Weauth backend will make a login request to your domain name at the following address:

https://yourdomain.com/weauth?user=uuu&sk=xxx

Create a weauth directory at the root of your server, create a new index. PHP directory, and call the above request address to receive the result of the request, such as user and sk for database validation and registration of users.

landing

After receiving the login request from the Weauth back-end, the application back-end identifies the authenticity of the login request according to SK, so as to choose whether to trust the login request or not, and complete the authorization login according to the user WeChat information in the current login request.

After logging in, the page suggests using Ajax polling to update the status in real time.

demo

https://www.likeyun.cn/weauth…

Due to the polling mechanism, a timeout is added in order to avoid the long time without scanning the code leading to the polling.



Author:TANKING

Date:2020-12-01

Web:http://www.likeyun.cn/

WeChat:face6009

Join my fan group and develop a learning exchange group

http://www.likeyun.cn/m/image…