Personal website is unable to access wechat sweep a login, can only use the curve to save the country, the use of small program, small program is able to obtain the wechat user UnionID.

The first step is to register a small application, very simple, with the email application, click register

After the registration is completed, you can start the development. I use Node to write the background service

Generate a small program qr code

To do a scan login, two-dimensional code is indispensable, the official also provides several ways to generate two-dimensional code. Viewing the Generation Mode

I use interface A. For details, please check the official document.

 POST https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN
Copy the code

As can be seen from the API, calling this interface requires passing in an ACCESS_TOKEN, which is not generated by us and needs to be obtained by calling the service of the applet.

ACCESS_TOKEN

Example of getting an ACCESS_TOKEN

The token expiration time is controlled by the wechat service. Once you get it, you can save it in Redis. You don’t need to get a new one every time

After obtaining the token, you can call the method that generates the QR code

Invoke the sampleThe file name of the QR code is returned

Handles the login request and is called after the applet completes authorizationwebSocketThe service notification page is successfully authorized. Go to the home page

Page display TWO-DIMENSIONAL code

The login page invokes the server to generate the TWO-DIMENSIONAL code and display it on the page. In addition, the server connects to the webSocket service and waits for the server to confirm the login.

Small program

login.js login.wxml

github

Experience the address