编写自动回复,针对用户不同消息类型做出回复,程序怎么调都有问题额。
问题:无论我发送什么消息,文本也好,图片也好,语音也好,都只回复“我只接收图片消息”,也就是说程序似乎不执行
if(strtolower($msgType) =="image"){..............}这一判断.
求各位大神看一下~~~~
GetImageMsg();//这个要调用自动回复消息!!$wechatObj->valid();class wechatCallbackapiTest{//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>接口验证>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> public function valid() { $echoStr = $_GET["echostr"]; //valid signature , option if($this->checkSignature()){ header('content-type:text');//在微信样本代码上添加了如此语句,因而接口接成功 echo $echoStr; exit; } } private 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; } }//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>自动回复消息>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> public function GetImageMsg()//自动回复消息 { $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; if (!empty($postStr)) { libxml_disable_entity_loader(true); $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $msgType=$postObj->$MsgType; $picUrl=trim($postObj->PicUrl); $mediaId=trim($postObj->MediaId); $time = time(); $textTpl = ""; if(strtolower($msgType) =="image") { if(!empty($picUrl)){ $msgType ="text"; $contentStr = "图片链接:".$picUrl."\n"; $contentStr =$contentStr."媒体ID:".$mediaId; }else{ $contentStr = "请发送图片哦"; } }else{ $msgType ="text"; $contentStr = "我只接收图片消息"; } $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; } else { echo ""; exit; } } }?> %s 0
可能65行应该是$msgType=$postObj->MsgType;这个吧
多了个$???
可能65行应该是$msgType=$postObj->MsgType;这个吧
多了个$???