//不验证,输出即可,微信平台和服务器握手
ob_clean();//核心就是这句 大概作用就是清除前面的输出缓冲区
echo $_GET["echostr"];
exit;
//验证这样写
class Check{
public $token="";//这里自己写自己配置的token
//接收参数并验证
public function check()
{
$echoStr = $_GET["echostr"];
if($this->checkSignature()){
ob_clean();
echo $echoStr;
exit;
}
}
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = $this->token;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
}