微信自动回复不了

WBOY
Release: 2016-06-20 12:28:32
Original
2106 people have browsed it


define("TOKEN", "Leo2012");
$wechatObj = new Test;
if (isset($_GET['echostr'])) {
    $wechatObj->valid();
}else{
    $wechatObj->responseMsg();
}

class Test
{
    public function valid()
    {
        $echoStr = $_GET["echostr"];
        if($this->checkSignature()){
            echo $echoStr;
            exit;
        }
    }

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

        $token = TOKEN;
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );

        if( $tmpStr == $signature ){
            return true;
        }else{
            return false;
        }
    }



    public function responseMsg()
    {
        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

        if (!empty($postStr)){
            $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
            $fromUsername = $postObj->FromUserName;
            $toUsername = $postObj->ToUserName;
            $keyword = trim($postObj->Content);
            $time = time();
            $textTpl = "
                        
                        
                        %s
                        
                        
                        0
                        
";
            if($keyword == "qqq" || $keyword == "ccc")
            {
                $msgType = "text";
                $contentStr = date("Y-m-d H:i:s",time())."aaaaa";
                $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
                echo $resultStr;
            }
        }else{
            echo "";
            exit;
        }
    }
}
?>

上面是代码,输入ccc或qqq后没有自动回复,这是为什么?


回复讨论(解决方案)

你在else下面的echo 输出一个字符串调试就明白了。

 $wechatObj->valid();
}else{
    $wechatObj->responseMsg();
}

class Test   {}
兄弟! 你这个程序在哪里copy的,能不能仔细的看看  你的微信类和测试类 是什么鬼。。。。。。。。两个类都不一样 你怎么调方法

我看错了 不好意思 是我没仔细看。。。。。。。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!