收藏
回答

小程序消息推送配置一直失败


一直提示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;
       }
   }


最后一次编辑于  2018-04-08
回答关注问题邀请回答
收藏

2 个回答

  • luffy730
    luffy730
    2018-04-25

    ob_clean(); 加上这行

    2018-04-25
    有用
    回复
  • 零号台风
    零号台风
    2018-04-18

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

    2018-04-18
    有用
    回复
登录 后发表内容