编写自动回复,针对用户不同消息类型做出回复,程序怎么调都有问题额。
问题:无论我发送什么消息,文本也好,图片也好,语音也好,都只回复“我只接收图片消息”,也就是说程序似乎不执行
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 = %s 0 ; 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; } } }?>
回复讨论(解决方案) 可能65行应该是$msgtype=$postobj->msgtype;这个吧
多了个$?
可能65行应该是$msgtype=$postobj->msgtype;这个吧
多了个$?
谢谢~~~~很有用!亏我搞了半天,原来是这个呀