编程语言
首页 > 编程语言> > ThinkPHP 微信小程序-消息推送配置 Token校验失败,请检查确认

ThinkPHP 微信小程序-消息推送配置 Token校验失败,请检查确认

作者:互联网

    public function valid() {
        if (isset($_GET["echostr"])) {
            $echoStr = $_GET["echostr"];
            //valid signature , option
            if (!$this->token) {
                throw new Exception('token is not defined!');
            }
            $signature = $_GET["signature"];
            $timestamp = $_GET["timestamp"];
            $nonce = $_GET["nonce"];
            $tmpArr = array($this->token, $timestamp, $nonce);
            // use SORT_STRING rule
            sort($tmpArr, SORT_STRING);
            $tmpStr = implode($tmpArr);
            $tmpStr = sha1($tmpStr);
            if ($tmpStr == $signature) {
                ob_clean();
                echo $_GET['echostr'];
            } else {
                echo 'xx';
            }
        } else {
            $this->responseMsg();
        }
    }

解决办法:在输出 echc $_GET['echostr']; 前,清空缓存区,即在echo 前放置“ob_clean();”代码即可。

官方解释:ob_clean(); 此函数是用来丢弃输出缓冲区中的内容;

完成以后,即可配置成功:

 

标签:nonce,GET,微信,echo,Token,echostr,signature,ThinkPHP,tmpStr
来源: https://www.cnblogs.com/Mishell/p/12618700.html