首页 新闻 会员 周边

为什么微信验证一直提示token验证是失败找不到原因。。下面贴出代码。

0
悬赏园豆:20 [待解决问题]

 //在这里调用下面给出类代码

   $weixin = new Wechat($this->token);

<?php
class Wechat{
    private $data = array();
    public function __construct($token)
    {
        $this->auth($token) || exit;
        if (IS_GET) {
            echo($_GET['echostr']);
            exit;
        } else {
            $xml = file_get_contents("php://input");
            $xml = new SimpleXMLElement($xml);
            $xml || exit;
            foreach ($xml as $key => $value) {
                $this->data[$key] = strval($value);
            }
        }
    }

    public function request()
    {
        return $this->data;
    }

    public function response($content, $type = 'text', $flag = 0)
    {
        $this->data = array('ToUserName' => $this->data['FromUserName'], 'FromUserName' => $this->data['ToUserName'], 'CreateTime' => NOW_TIME, 'MsgType' => $type,);
        $this->$type($content);
        $this->data['FuncFlag'] = $flag;
        $xml = new SimpleXMLElement('<xml></xml>');
        $this->data2xml($xml, $this->data);
        exit($xml->asXML());
    }

    private function text($content)
    {
        $this->data['Content'] = $content;
    }

    private function music($music)
    {
        list($music['Title'], $music['Description'], $music['MusicUrl'], $music['HQMusicUrl']) = $music;
        $this->data['Music'] = $music;
    }

    private function news($news)
    {
        $articles = array();
        foreach ($news as $key => $value) {
            list($articles[$key]['Title'], $articles[$key]['Description'], $articles[$key]['PicUrl'], $articles[$key]['Url']) = $value;
            if ($key >= 9) {
                break;
            }
        }
        $this->data['ArticleCount'] = count($articles);
        $this->data['Articles'] = $articles;
    }

    private function data2xml($xml, $data, $item = 'item')
    {
        foreach ($data as $key => $value) {
            is_numeric($key) && $key = $item;
            if (is_array($value) || is_object($value)) {
                $child = $xml->addChild($key);
                $this->data2xml($child, $value, $item);
            } else {
                if (is_numeric($value)) {
                    $child = $xml->addChild($key, $value);
                } else {
                    $child = $xml->addChild($key);
                    $node = dom_import_simplexml($child);
                    $node->appendChild($node->ownerDocument->createCDATASection($value));
                }
            }
        }
    }

    private function auth($token)
    {
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];

        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );
        if( $tmpStr == $signature ){
            return true;
        }else{
            return false;
        }
    }
}

?>

代码没看出问题。求指教。之前是可以的,但是现在就不行了。看日志代码走到了

           echo($_GET['echostr']);
            exit;

但是还是提示token验证失败。。。

先问后学的主页 先问后学 | 初学一级 | 园豆:127
提问于:2014-11-19 10:50
< >
分享
所有回答(2)
0

有可能是过期了,token调用有限制的,一天貌似是1000次。

大楚打码人 | 园豆:4313 (老鸟四级) | 2014-11-19 11:30

今天。。一次没调过我是在配置url的时候出现的。。不是调用的时候

支持(0) 反对(0) 先问后学 | 园豆:127 (初学一级) | 2014-11-19 11:31
0

试试用这两个来调试一下:
http://mp.weixin.qq.com/wiki/10/e5f772f4521da17fa0d7304f68b97d7e.html

https://mp.weixin.qq.com/debug/

************** | 园豆:124 (初学一级) | 2016-08-24 12:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册