要注意以下两点:
1、我这边token验证失败关键点就在于 header('content-type:text'); 和 ob_clean(); 这2个要加上!
2、URL指向的方法页要确保是UTF-8 无BOM格式,可以用Notepad更改编码格式
/**
* 验证token
*/
public function echostr(){
$signature=$_GET["signature"];
$timestamp=$_GET["timestamp"];
$nonce=$_GET["nonce"];
$echostr = $_GET['echostr'];
$token = 'aifFWSjhtu19ukNUmg6GzIxpDa46Ggi';
$tmpArr = array($token,$timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode('',$tmpArr);
$tmpStr = sha1($tmpStr);
if($tmpStr==$signature && $echostr){
header('content-type:text');
ob_clean();
echo $echostr;exit();
}else{
$this->reponseMsg();
}
}
如需转载请标记本文链接!