验证服务器地址的有效性,加密/校验流程如下:
<?php //将timestamp,nonce,toke按照字典序排序 $timestamp = $_GET[‘timestamp‘]; $nonce = $_GET[‘nonce‘]; $token = $_GET[‘xiaomayi‘]; $signature = $_GET[‘signature‘]; $array = array($timestamp,$nonce,$token); sort($array); //将排序后的三个参数拼接之后用,sha1 加密 $tmpstr = implode(‘‘,$array); $tmpstr = sha1($tmpstr); //将加密后的字符串与$signature进行对比,判断该请求是否来自微信。 if($tmpstr==$signature){ echo $_GET[‘echostr‘]; } ?>