微信token验证失败

浏览:484 发布日期:2017/07/28 分类:求助交流 关键字: 维信 token 消息回复
做了个消息回复,验证token的时候总是失败,我在日志里面把微信访问的链接在浏览器上打开可以输出这个值echostr,然后我又把微信的访问写在日志里面,也可以输出这个值echostr.
同样的代码在另一套程序里面没有问题.求大神解惑,在线等.谢谢

代码:
public function WXMain()
{

if (isset($_GET['echostr'])) {
$this->valid();
} else {
$this->responseMsg();
}
}

public function valid()
{
$echoStr = $_GET["echostr"];
if($this->checkSignature()){
\Think\Log::write($echoStr);
echo $echoStr;
exit;
}

}

private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];

$token = C('TOKEN');

\Think\Log::write('token=>'.$token);

$tmpArr = array(
$token,
$timestamp,
$nonce
);
sort($tmpArr);
$tmpStr = implode($tmpArr);
$tmpStr = sha1($tmpStr);
\Think\Log::write('tmpStr=>'.$tmpStr);
\Think\Log::write('signature=>'.$signature);

if ($tmpStr == $signature) {
return true;
} else {
return false;
}
}
最佳答案
评论( 相关
后面还有条评论,点击查看>>