小程序消息推送配置一直失败
发布于 6 年前 作者 rma 18351 次浏览 来自 问答

一直提示token验证失败,但是接口有返回

代码如下

 public function isValid()//验证微信接口,如果确认是微信就返回它传来的echostr参数
   {
       //1. 将timestamp , nonce , token 按照字典排序
       $timestamp = $_GET['timestamp'];
       Log::info('微信传递的时间戳' . $timestamp);
       $nonce = $_GET['nonce'];
       Log::info('微信传递的nonce' . $nonce);
       $token = "yuanhuan2018";
       $signature = $_GET['signature'];
       Log::info('微信传递的签名' . $signature);
       $array = array($timestamp, $nonce, $token);
       $newArr = sort($array);
       Log::info('排序前的数组' . json_encode($array));
       Log::info('排序后的数组' . json_encode($newArr));
//2.将排序后的三个参数拼接后用sha1加密
       $tmpstr = implode('', $array);
       $tmpstr = sha1($tmpstr);
       Log::info('临时的字符串' . $tmpstr);
//3. 将加密后的字符串与 signature 进行对比, 判断该请求是否来自微信
       if ($tmpstr == $signature) {
           Log::info('最后的匹配一致输出字符串echostr' . $_GET['echostr']);
           echo $_GET['echostr'];
           exit;
       }
   }
2 回复

ob_clean(); 加上这行

请问一下,问题解决了吗?我也是这个问题很头疼,想问下是什么原因?

回到顶部