token验证失败

微信公众平台后台配置的时候出现“token验证失败”,如图:
这里写图片描述

服务器程序如下:


    //检查签名
     public function checkSignature(Request $request)
     {
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];
        $echostr = $request->echostr;
        $token = config('wechat.token');
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode($tmpArr);
        $tmpStr = sha1($tmpStr);

        if($tmpStr == $signature){

            echo $echostr;
            exit();
            // return true;
        }else{

            return false;
        }
     }

后来从网上得知,需要使用ob_clean();,如下:


    //检查签名
     public function checkSignature(Request $request)
     {
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];
        $echostr = $request->echostr;
        $token = config('wechat.token');
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode($tmpArr);
        $tmpStr = sha1($tmpStr);

        if($tmpStr == $signature){

            ob_clean();
            echo $echostr;
            exit();
            // return true;
        }else{

            return false;
        }
     }

Author:leedaning
本文地址:http://blog.csdn.net/leedaning/article/details/71194645

猜你喜欢

转载自blog.csdn.net/leedaning/article/details/71194645