How can the WeChat public platform become a developer?
After logging on to the WeChat public platform, click "Advanced Function =" development mode = "become Developer =" and enter the interface configuration information. Submit the information and wait for our staff to review it.
1. Developer authentication
This is the simplest. The code of the previous ultra-simple version is as follows:
| The code is as follows: |
Copy code |
|
Exit ($ _ GET ['echostr']); |
Just write the above sentence in the PHP file. Fill in the token on the WeChat public platform, write the url of the PHP file, and then verify the code. Super simple? Official authentication is not necessary at all, because the signature verification is not used in the subsequent steps, so this place can be easily verified by directly outputting the return value for the convenience of graphs. Of course, the authentication code officially required is also provided below:
| The code is as follows: |
Copy code |
|
$ Token = '11 ';
$ Signarr = array ($ token, $ _ GET ['timestamp'], $ _ GET ['nonce ']);
If ($ this-& gt; signnature ($ signarr, $ _ GET ['signature']) {
Exit ($ _ GET ['echostr']);
}
Function signnature ($ arr, $ signature ){
Sort ($ arr );
If (sha1 (implode ($ arr) ==$ signature) return true;
Return false;
} |
Save the above code as a php file, set the same token on the WeChat public platform, and then verify the token to pass.
Note: urls can contain get parameters.
Website Access
After the public platform user submits the information, we will request the information to the Url filled in with a GET request with four parameters:
* Signature-WeChat encrypted signature
* Timestamp-timestamp
* Nonce-random number
* Echostr-random string
The developer verifies the validity of website access by verifying signature. If the GET request returns the content of the echostr parameter as is, the access takes effect. Otherwise, the access fails. The verification of signature will be combined with the token parameter and timestamp entered by the developer
Parameters and nonce parameters, encryption process:
* Sort the tokens, timestamp, and nonce in lexicographic order.
* Splice the three parameter strings into one string for sha1 encryption
* The encrypted string obtained by the developer can be compared with signature to identify that the request comes from WeChat.