public functionindex(){//判断是否为认证
if (isset($_GET['echostr'])) {//如果认证去验证
$this->valid();
}else{//否则接收客户发送消息
$this->responseMsg();
}
}//验证前置方法
public functionvalid()
{$echoStr = $_GET["echostr"];if($this->checkSignature()){header('content-type:text');echo $echoStr;exit;
}else{echo $echoStr.'+++'.TOKEN;exit;
}
}//签名校验
private functioncheckSignature()
{//微信加密签名
$signature = $_GET["signature"];//时间戳
$timestamp = $_GET["timestamp"];//随机数
$nonce = $_GET["nonce"];//服务端配置的TOKEN
$token = '自己配置的TOKEN';//将token,时间戳,随机数进行字典排序
$tmpArr = array($token, $timestamp, $nonce);sort($tmpArr,SORT_STRING);//拼接字符串
$tmpStr = implode( $tmpArr);$tmpStr = sha1( $tmpStr);if( $tmpStr == $si