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{
// 獲取微信數(shù)據(jù)
public function checktoken(){
$request = Request::instance();
$get = $request->param();
$timestamp = $get['timestamp'];//timestamp其實(shí)就是一個(gè)時(shí)間戳
$nonce = $get['nonce'];//nonce是一個(gè)隨機(jī)參數(shù)
$token = "";//這個(gè)token填寫(xiě)你在微信公眾平臺(tái)上寫(xiě)的那個(gè)值
$signature = $get['signature'];//這個(gè)signature其實(shí)就是在微信公眾平臺(tái)已經(jīng)加密好的字符串
$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;
}
}
}
擁有18年軟件開(kāi)發(fā)和IT教學(xué)經(jīng)驗(yàn)。曾任多家上市公司技術(shù)總監(jiān)、架構(gòu)師、項(xiàng)目經(jīng)理、高級(jí)軟件工程師等職務(wù)。 網(wǎng)絡(luò)人氣名人講師,...
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.