编写自动回复,针对用户不同消息类型做出回复,程序怎么调都有问题额。
问题:无论我发送什么消息,文本也好,图片也好,语音也好,都只回复“我只接收图片消息”,也就是说程序似乎不执行
if(strtolower($msgtype) =="image"){..............}这一判断.
求各位大神看一下~~~~
<?php// wechat php //define your token定义接口define("token", "weixin");$wechatobj = new wechatcallbackapitest();$wechatobj ->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 = "<xml> <tousername><![cdata[%s]]></tousername> <fromusername><![cdata[%s]]></fromusername> <createtime>%s</createtime> <msgtype><![cdata[%s]]></msgtype> <content><![cdata[%s]]></content> <funcflag>0</funcflag> </xml>"; 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;这个吧
多了个$???
微信是一款手机通信软件,支持通过手机网络发送语音短信、视频、图片和文字。微信可以单聊及群聊,还能根据地理位置找到附近的人,带给大家全新的移动沟通体验,有需要的小伙伴快来保存下载体验吧!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号