微信开发自动回复功能,消息类型判断失败,PHP语言

php中文网
发布: 2016-06-20 12:38:20
原创
1587人浏览过

编写自动回复,针对用户不同消息类型做出回复,程序怎么调都有问题额。
问题:无论我发送什么消息,文本也好,图片也好,语音也好,都只回复“我只接收图片消息”,也就是说程序似乎不执行
 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;        }    }     }?>
登录后复制

云雀语言模型
云雀语言模型

云雀是一款由字节跳动研发的语言模型,通过便捷的自然语言交互,能够高效的完成互动对话

云雀语言模型 54
查看详情 云雀语言模型


回复讨论(解决方案)

可能65行应该是$msgType=$postObj->MsgType;这个吧
多了个$???

可能65行应该是$msgType=$postObj->MsgType;这个吧
多了个$???

谢谢~~~~很有用!亏我搞了半天,原来是这个呀
微信app下载
微信app下载

微信是一款手机通信软件,支持通过手机网络发送语音短信、视频、图片和文字。微信可以单聊及群聊,还能根据地理位置找到附近的人,带给大家全新的移动沟通体验,有需要的小伙伴快来保存下载体验吧!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号