I simple implementation of the example, using any QR Code tool to open the QR code corresponding link
Http://www.vincentguo.cn/demo/scan
Principle Introduction:
The first step: Visit the login page, generate a unique key, such as mkhjdfl=, and save this key to the cache with a value of-1, 1 means not logged in
, the key is valid for 5 minutes, it will regenerate the two-dimensional code image
The second step: Generate two-dimensional code, I use the library (https://github.com/2amigos/yii2-qrcode-helper), two-dimensional code corresponding to the link
http://www.vincentguo.cn/demo/qrcode?key=MkhjDFL=
The Third step: login page, JS loop request an interface, I interface Http://www.vincentguo.cn/demo/dologin
Fourth step: Use any app to open the two-dimensional code to drink the link. You should use the app you developed here, and the app is logged in, then use your app to scan the QR code, then the app requests a link to the QR code, so that the key can correspond to the login uid, at this time to modify the cache key corresponding value is the login UID
Fifth step: Since the third step in the duplicate request interface, this interface if the key value in the cache is checked to the UID of the login, it will return the login information and save the login state
PS: The algorithm to generate unique key, you can generate based on time information
Examples are as follows:
I can play: Http://www.vincentguo.cn/demo/scan
Text Address: PHP implementation of QR code scan login
PHP implementation of QR code scan login