In this public platform development tutorial, we will introduce how to use open platform interfaces to implement the QR code logon function. In this public platform development tutorial, we will introduce how to use open platform interfaces to implement the QR code logon function.
Preparations
Website application logon is an OAuth2.0 authorized logon system based on OAuth2.0 protocol standards.
Before OAuth2. performs authorized OAuth2.0 login and access, register a developer account on the open platform, have a verified website application, and obtain the corresponding AppID and AppSecret, after applying for logon and passing the review, you can start the access process.
《script》 var obj = new WxLogin({ id: "login_container", appid: "wxed782be999f86e0e", scope: "snsapi_login", redirect_uri: encodeURIComponent("http://" + window.location.host + "/login.php"), state: Math.ceil(Math.random()*1000), style: "black", href: ""}); 《script》
Parameter description
Parameters |
Required? |
Description |
Id |
Yes |
Container id of the QR code displayed on the third-party page |
Appid |
Yes |
Unique Application ID, obtained after the application is submitted to the open platform for application review |
Scope |
Yes |
Application authorization scope. multiple scopes are separated by commas (,). Currently, only snsapi_login can be entered for web applications. |
Redirect_uri |
Yes |
Redirection address, which requires UrlEncode |
State |
No |
It is used to maintain the request and callback status, and the authorization request is taken back to a third party as is. This parameter can be used to prevent csrf attacks (Cross-Site Request Forgery attacks). it is recommended that a third party carry this parameter and set it to a simple random number and a session for verification. |
Style |
No |
"Black" and "white" are available. the default value is black text description. See the FAQ at the bottom of the document. |
Href |
No |
Custom style links. third parties can overwrite the default style as needed. See the FAQ at the bottom of the document. |
The complete code is as follows: