Now that the verification has passed, the only thing left is to return it to WeChat. If I return echostr or true, WeChat says my token verification failed
<?php
namespace app\index\controller;
use think\Request,think\Db;
use think\Cache;
class Autoreply extends RestBase{
// 获取微信数据
public function checktoken(){
$request = Request::instance();
$get = $request->param();
$timestamp = $get['timestamp'];//timestamp其实就是一个时间戳
$nonce = $get['nonce'];//nonce是一个随机参数
$token = "";//这个token填写你在微信公众平台上写的那个值
$signature = $get['signature'];//这个signature其实就是在微信公众平台已经加密好的字符串
$echostr = $get['echostr'];
$array = array();
$array = array($token,$timestamp,$nonce);
sort($array);
$tmpstr = sha1(implode('',$array));
if($tmpstr == $signature){
echo $get['echostr'];
}else{
return false;
}
}
}
When you carefully look at the code and can't find any problems, it's more important to learn simple debugging, such as seeing what the WeChat parameters are, and seeing whether the results you processed are the same as you expected.