Recently in a Web instant messaging, there is a scan code login function. Have not done before, ask the experts to talk about.
such as QR code how to come, the web side if listening to the phone scan code success, and the server sent the data
Reply content:
Recently in a Web instant messaging, there is a scan code login function. Have not done before, ask the experts to talk about.
such as QR code how to come, the web side if listening to the phone scan code success, and the server sent the data
步骤 WEB平台 手机第1步 生成二维码第2步 (ajax监控后台) 扫码第3步 (ajax监控后台) 确定(后台异步通知WEB平台)第4步 AJAX发现状态改变,登陆成功
The process of Ajax monitoring backstage: After generating the QR code,
setTimeout(function(){ //AJAX请求,检测状态},5000);
The upstairs words are right. Let me Add.
Consider an example
Solve two problems,<1> the computer from the server to get someone to sweep my computer and authorize login.
Then the app, to solve is to sweep the after, know who swept the person who, the person to tell the information to the server.
Objects <1> Websites <2> mobile Phones Open
Process
<1>web generate links, links made into two-dimensional code, generally using local cookies or SessionID as the only parameter.
<2>app sweep, in fact, is to authorize the operation, crawl user information, the user information and the request contained in the cookie or SessionID stored in the library
<3>web every few seconds Ajax request backstage, query the current cookie or sessionid whether there is a corresponding login information, there is the login operation.
1. Front-end call backend generate QR Code API, get to QR code picture and the information contained (usually a unique ID)
2. Front-end detection (by polling or websock, choose) whether there is a mobile phone scan code, by invoking the background interface API, the parameter is the above unique ID
3. Mobile phone scanning QR code login, mobile phone can get to the QR code information ID, with the current login user ID and the ID of the QR code to call the background interface.
Background store this QR code data, plus login user information, the current station call API, to return login success.
4. Front-end acquisition to login successful, to jump