微信自动回复不了

原创
2016-06-20 12:28:32 1787浏览


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的,能不能仔细的看看 你的微信类和测试类 是什么鬼。。。。。。。。两个类都不一样 你怎么调方法

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

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。