Settings page ("Settings" >> "Development Settings"):
For example: https://hosts.com
Note the difference between http and https protocols.
2.1 Add server to your server
Interfacetest.php, the content of the test.php interface is mainly to verify whether the message is through token Sent from WeChat, the code refers to the official example:
define("TOKEN","xxxxx");/ The token filled in in the background$wechatObj = <br>new<a href="http://www.php.cn/wiki/165.html" target="_blank"> wechatAPI(); </a>$wechatObj->isValid();<br><br>class<a href="http://www.php.cn/wiki/164.html" target="_blank"> wechatAPI</a>{<br>public function isValid()//Verify the WeChat interface, if it is confirmed to be WeChat, return it The <br>echo<a href="http://www.php.cn/wiki/1343.html" target="_blank">str parameter</a>{<br> $echoStr = $_GET["echostr"];<br> <br>if<a href="http://www.php.cn/wiki/109.html" target="_blank"> ($this->checkSignature()) {</a> echo $echoStr;<br> exit;<br> }<br>}<br>private function checkSignature() //Official verification <br> function<a href="http://www.php.cn/wiki/145.html" target="_blank"></a>{<br> $signature = $ _GET["signature"];<br> $<br>time<a href="http://www.php.cn/wiki/1268.html" target="_blank">stamp = $_GET["timestamp"];</a> $nonce = $_GET["nonce"];<br> $token = TOKEN; <br> $tmpArr = <br>array<a href="http://www.php.cn/wiki/58.html" target="_blank">($token, $timestamp, $nonce);</a> <br>sort<a href="http://www.php.cn/wiki/1087.html" target="_blank">($tmpArr, SORT_</a>STRING<a href="http://www.php.cn/wiki/57.html" target="_blank">);</a> $tmpStr = <br>implode<a href="http://www.php.cn/wiki/1336.html" target="_blank">( $tmpArr );</a> $tmpStr = <br>sha1<a href="http://www.php.cn/wiki/1366.html" target="_blank">( $tmpStr );</a> if( $tmpStr == $signature ){<br> <br>return<a href="http://www.php.cn/wiki/135.html" target="_blank"> true;</a> }<br>else<a href="http://www.php.cn/wiki/111.html" target="_blank">{</a> return false;<br> }<br>}<br>};<br>
2.2 Setup Mini Program Background message push related information
URL (server address): https://hosts.com/xx/test.php
Token: Any
string that conforms to the specification, as defined above" xxxxx"EncodingAES
Key(message encryption key): (randomly generated, just save it yourself, this is only used for encryption and decryption)Message encryption method: select plaintext for the time being, don’t think about it Encryption and decryption issues.
Data format: Select according to needs.
Submit, if there are no problems, it will be successful. (If there is a problem you can use fake data to pass the browser test)
The above is the detailed content of WeChat applet message push php server verification. For more information, please follow other related articles on the PHP Chinese website!