Home  >  Q&A  >  body text

WeChat public platform - thinkphp5 WeChat server configuration problem, why the token cannot be verified

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;
        }
        
    }
}
高洛峰高洛峰2700 days ago928

reply all(1)I'll reply

  • typecho

    typecho2017-06-17 09:17:26

    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.

    reply
    0
  • Cancelreply