javascript - How to implement web code scanning login, please give me some ideas

WBOY
Release: 2016-09-23 11:31:04
Original
1597 people have browsed it

Recently I am working on a web instant messaging, which has a QR code login function. I've never done this before, so I'm looking for an expert to talk about it.
How did the QR code come from? If the web side monitors the mobile phone to scan the code successfully, and the server has sent the data

Reply content:

Recently I am working on a web instant messaging, which has a QR code login function. I've never done this before, so I'm looking for an expert to talk about it.
How did the QR code come from? If the web side monitors the mobile phone to scan the code successfully, and the server has sent the data

<code>步骤       WEB平台                手机
第1步      生成二维码
第2步     (ajax监控后台)          扫码
第3步     (ajax监控后台)          确定(后台异步通知WEB平台)
第4步      AJAX发现状态改变,登陆成功
</code>
Copy after login

Ajax monitoring background process: after generating the QR code,

<code>setTimeout(function(){
    //AJAX请求,检测状态
},5000);


</code>
Copy after login

What you said above is correct. Let me add something.
Take WeChat as an example
Solve two problems, <1> The computer obtains from the server whether someone has scanned my computer and authorized login.
Then the app needs to solve the problem of knowing who the person who scanned is and telling the server the information about this person.
Object<1>Website <2>Open WeChat on mobile phone

Process
<1>The web generates links, and the links are made into QR codes. Generally, local cookies or sessionid are used as the only parameters.

<2>After the app scans, it actually performs the authorization operation, captures the user information, and stores the user information and the cookies or sessionid included in the request into the library.
<3>The web makes an ajax request to the background every few seconds. Check whether the current cookie or sessionid has corresponding login information, and perform the login operation if it does.

1. The front-end calls the API that generates the QR code in the background to obtain the QR code image and the information it contains (usually a unique ID)
2. The front-end detects (through polling or websock, your choice) whether there is a mobile phone scan Code, by calling the backend interface API, the parameter is the unique ID above
3. Scan the QR code with your mobile phone to log in. The mobile phone can get the information ID in the QR code, and bring the current login user ID and the ID in the QR code. Call the background interface.
The data of this QR code is stored in the background, plus the logged-in user information. When the front-end calls the API, a successful login will be returned.
4. The front end gets the successful login and jumps

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!