接入微信的时候TOKEN验证失败

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    
    public function index(){
       
}
 
  public function check()
{                  
                /**
                  * wechat php test
                  */
                
                //define your token
                define("TOKEN", "weixin");
      $this->valid();
}
                 public function valid()
                    {
                        $echoStr = $_GET["echostr"];
                
                        //valid signature , option
                        if($this->checkSignature()){
                            echo $echoStr;
                            exit;
                        }
                    }
                
                        
                    public function checkSignature()
                    {
                        // you must define TOKEN by yourself
                        if (!defined("TOKEN")) {
                            throw new Exception('TOKEN is not defined!');
                        }
                        
                        $signature = $_GET["signature"];
                        $timestamp = $_GET["timestamp"];
                        $nonce = $_GET["nonce"];
                                
                        $token = TOKEN;
                        $tmpArr = array($token, $timestamp, $nonce);
                        // use SORT_STRING rule
                        sort($tmpArr, SORT_STRING);
                        $tmpStr = implode( $tmpArr );
                        $tmpStr = sha1( $tmpStr );
                        
                        if( $tmpStr == $signature ){
                            return true;
                        }else{
                            return false;
                        }
                    }
}
?>

微信公众平台那边填写是没有错的,我怀疑是代码的问题,我用的是thinkphp,服务器用新浪云。一直提示验证失败。大家能帮我看下是什么问题吗,非常感谢!

qq_学渣君_0
浏览 1238回答 1
1回答

喏_

代码没有问题,我也是这样写的
打开App,查看更多内容
随时随地看视频慕课网APP