为了账号安全,请及时绑定邮箱和手机立即绑定

接入微信的时候TOKEN验证失败

接入微信的时候TOKEN验证失败

PHP
qq_学渣君_0 2016-10-11 15:15:45
<?php namespace Home\Controller; use Think\Controller; class IndexController extends Controller {          public function index(){         }     public function check() {                                   /**                   * wechat php test                   */                                  //define your token                 define("TOKEN", "weixin");       $this->valid(); }                  public function valid()                     {                         $echoStr = $_GET["echostr"];                                          //valid signature , option                         if($this->checkSignature()){                             echo $echoStr;                             exit;                         }                     }                                                               public function checkSignature()                     {                         // you must define TOKEN by yourself                         if (!defined("TOKEN")) {                             throw new Exception('TOKEN is not defined!');                         }                                                  $signature = $_GET["signature"];                         $timestamp = $_GET["timestamp"];                         $nonce = $_GET["nonce"];                                                          $token = TOKEN;                         $tmpArr = array($token, $timestamp, $nonce);                         // use SORT_STRING rule                         sort($tmpArr, SORT_STRING);                         $tmpStr = implode( $tmpArr );                         $tmpStr = sha1( $tmpStr );                                                  if( $tmpStr == $signature ){                             return true;                         }else{                             return false;                         }                     } } ?>微信公众平台那边填写是没有错的,我怀疑是代码的问题,我用的是thinkphp,服务器用新浪云。一直提示验证失败。大家能帮我看下是什么问题吗,非常感谢!
查看完整描述

1 回答

?
喏_

TA贡献5条经验 获得超0个赞

代码没有问题,我也是这样写的

查看完整回答
反对 回复 2016-10-11
  • 1 回答
  • 3 关注
  • 1237 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信