Scan the QR code to enable one-click logon and one-click Logon
The first time I wrote a blog, I was very excited. I didn't know how to write it, so I could easily express it ......
Some time ago, I received a request saying that I would like to add a scan code login function on our project. Just like QQ and QQ, I immediately checked some information online, I felt that it was not the same as our system. After some guidance from some great gods, I finally realized this function.
1. Use your bound account to log on.
Scan the QR code to jump to the page bound to the account. Note that you can only use the scan. to authorize the scan, you need to pass two parameters. One is guid, another one is the id of the account you want to bind. The meanings of these two parameters are: guid can be used to find the computer to bind, because our system, one account can log on to multiple computers at the same time. Id is used to find the account you want to bind. Click "OK" to insert a piece of data to the database. After successful, the account is successfully bound.
2. start logging on
Add a timer to the logon page.
$ (Function () {var interval; // click to display the QR code $ (". login-2wm "). click (function () {$ (". login_formdiv "). toggle (); $ (". A login-2wm span "). toggle (); $ (". login_title p. login_title_p "). toggle (); if (interval = undefined) {interval = setInterval (Qrcode, "3000") ;}); // monitoring function Qrcode () {$. get ('/WxWeb/QRCodeLogin/check', // The link to be verified {guid:' <% = guid %> '// prevents logon errors}, function (res) {if (res. code) {$. post ('.. /tools/QrLogin. ashx', // simulate User Logon for verification {mid: res. MId, // The id guid: res. guid}, function (testData) {if (testData. agentLevel ==- 1000) {$. dialog. alert (testData. description);} else if (testData. agentLevel> 0) {window. location. href = "xxx. aspx ";} else {window. location. href = "xxx. aspx ";}}," JSON ") ;}," JSON ") ;}; </script>
The timer indicates the page for real-time monitoring and verification. After the authentication page is authorized to obtain the openid, It is matched in the database. After the matching is successful, the account id is returned, after I get the parameters I need, I post another request to simulate user logon. This will make the login successful. Is it very easy? The first write is not good. Don't like it!