javascript - Technical issues regarding WeChat scan
PHPz
PHPz 2017-05-17 10:05:28
0
1
824

Now I know through understanding that the WeChat QR code contains a uid. You can get this UID by scanning the QR code on the client. The web page constantly requests whether this Uid is authorized, and it will only log in after being authorized. I don't understand it. The question is, how can the client let the web page know that the request for authorization and login has been obtained. How does the web page get this authorization after sending it to the server? It must be very simple if it is obtained through the database, but I think it is definitely not obtained through the database. I would like to ask if there is any other technology in this that can allow the web page to get the instructions sent by the client! ! Please give me some advice

PHPz
PHPz

学习是最好的投资!

reply all(1)
phpcn_u1582

In addition to returning the unique uid, when this page is actually opened, the browser and the server also create a long connection to request the scanning record of the uid. If not, you will receive status code 408 (request timeout) after a specific period of time (currently about 27 seconds), indicating that you should continue with the next request; if you receive status code 201 (the server successfully created a new resource), it means that the client scanned the QR code.

Request timeout: return 408

Scan code successfully: return 201

Query code

 function _poll(_asUUID) {
     $.ajax({
       type: "GET",
       url: "https://login." + _sBaseHost + "/cgi-bin/mmwebwx-bin/login?uuid=" + _asUUID + "&tip=" + show_tip,
       dataType: "script",
       cache: false,
       timeout: _nAjaxTimeout,
       success: function(data, textStatus, jqXHR) {
         switch (_aoWin.code) {
           case 200:
             // ....
             break;
           case 201:
             // ....
             break;
           case 408:
             // ....
             break;
           case 400:
           case 500:
             // ....
             break;
         }
       },
       error: function(jqXHR, textStatus, errorThrown) {
         // ....
       }
     });
 }

When the user scans the QR code using WeChat after logging in, the uid will be bound to the token generated by WeChat on the mobile phone and uploaded to the server. At this time, the browser queries the uid scanning record through long polling, immediately gets the 201 response code, and then notifies the server. The client also enters a new page (the one that requires you to click the confirmation button). After the client clicks to confirm, it obtains the server's credit token and proceeds with the subsequent information exchange process.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template