微信开发 token验证失败 200302 报错 err_msg: "verify token fail" ret: 200302

 

微信接入事件回调的时候,用的是微信官方的代码,但是就是无法通过验证,实在是想骂骂腾讯写文档的人

我的代码如下:

//回调鉴权
    public function check_signature()
    {
        $param = $this->request->get();
        $signature = $param["signature"];
        $timestamp = $param["timestamp"];
        $nonce = $param["nonce"];
        $token = config('wx_trade_plugin')['token'];
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode($tmpArr);
        $tmpStr = sha1($tmpStr);
        $param['tmpStr'] = $tmpStr;
        if ($tmpStr == $signature ) {
            echo $param["echostr"]);
        } else {
            echo 'error';
        }
    }

思来想去还是觉得没毛病,于是我自己用postman测试,也看不出任何问题

终于在试了很多次之后,我将代码改成这样子,神奇的通过了,心中万马奔腾!!!

//回调鉴权
    public function check_signature()
    {
        $param = $this->request->get();
        $signature = $param["signature"];
        $timestamp = $param["timestamp"];
        $nonce = $param["nonce"];
        $token = config('wx_trade_plugin')['token'];
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode($tmpArr);
        $tmpStr = sha1($tmpStr);
        $param['tmpStr'] = $tmpStr;
        //重点
        header("Content-type: text/html; charset=utf-8");
        if ($tmpStr == $signature ) {
        	//重点
            echo htmlspecialchars($param["echostr"]);
        } else {
            echo 'error';
        }
    }

 

posted @ 2021-10-11 11:13  山上小和尚  阅读(1065)  评论(0编辑  收藏  举报