if (strtolower($postObj->MsgType) == 'text' && trim($postObj->Content) == '图文') { $arr = array( array( 'title' => 'hello world!', 'description' => '百度一下,你就知道', 'picurl' => 'https://www.baidu.com/img/bdlogo.png', 'url' => 'https://www.baidu.com' ), array( 'title' => '优酷', 'description' => '这世界很酷', 'picurl' => 'https://www.baidu.com/img/bdlogo.png', 'url' => 'https://www.youku.com' ), ); $indexModel = new IndexModel; $indexModel->responseNews($postObj,$arr); }else{ //如果用户发送文本信息 switch($postObj->Content) { case 'hi': $content = '你好啊!'; break; case '日期': $content = "你好!现在是\n".date("Y年m月d日 H点i分s秒"); break; default: $content = "您可以尝试输入 hi、今天日期、图文"; break; } $indexModel = new IndexModel; $indexModel->responseText($postObj,$content); }
在IndexController.class.php中,用new的方法调用 Model文件夹中建立的IndexModel.class.php中的 responseNews($postObj,$arr),不成功啊。是不是在哪里还要配置??TP3.2.3的Controller里调用默认指向本项目中的Model文件夹吗?? 搞了好几天,都没搞定
同问,我也很困惑。
class IndexModel{ //回复多图文 public function responseNews($postObj,$arr){ $toUser = $postObj->FromUserName; $fromUser = $postObj->ToUserName; $template = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <ArticleCount>".count($arr)."</ArticleCount> <Articles>"; foreach ($arr as $k => $v) { $template .= "<item> <Title><![CDATA[".$v['title']."]]></Title> <Description><![CDATA[".$v['description']."]]></Description> <PicUrl><![CDATA[".$v['picurl']."]]></PicUrl> <Url><![CDATA[".$v['url']."]]></Url> </item>"; } $template .= "</Articles> </xml>"; echo sprintf($template,$toUser,$fromUser,time(),'news'); } //回复单文本 public function responseText($postObj,$content){ $toUser = $postObj->FromUserName; $fromUser = $postObj->ToUserName; $time = time(); $msgtype = 'text'; $template = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> </xml>"; //把对应的值赋值到模板的%s字符串中 $info = sprintf($template,$toUser,$fromUser,$time,$msgtype,$content); echo $info; } }