1 <?php 2 namespace HomeModel; 3 use ThinkModel; 4 5 class IndexModel{ 6 //回复多图文类型的微信消息 7 public function responseNews($postObj,$arr){ 8 $toUser=$postObj->FromUserName; 9 $fromUser=$postObj->ToUserName; 10 $template = "<xml> 11 <ToUserName><![CDATA[%s]]></ToUserName> 12 <FromUserName><![CDATA[%s]]></FromUserName> 13 <CreateTime>%s</CreateTime> 14 <MsgType><![CDATA[%s]]></MsgType> 15 <ArticleCount>".count($arr)."</ArticleCount> 16 <Articles>"; 17 foreach($arr as $k=>$v){ 18 $template .="<item> 19 <Title><![CDATA[".$v['title']."]]></Title> 20 <Description><![CDATA[".$v['description']."]]></Description> 21 <PicUrl><![CDATA[".$v['picUrl']."]]></PicUrl> 22 <Url><![CDATA[".$v['url']."]]></Url> 23 </item>"; 24 } 25 $template.="</Articles> 26 </xml>"; 27 echo sprintf($template, $toUser, $fromUser, time(), 'news'); 28 }//responseNews end 29 // 回复单文本 30 public function responseText($postObj,$content){ 31 $template="<xml> 32 <ToUserName><![CDATA[%s]]></ToUserName> 33 <FromUserName><![CDATA[%s]]></FromUserName> 34 <CreateTime>%s</CreateTime> 35 <MsgType><![CDATA[%s]]></MsgType> 36 <Content><![CDATA[%s]]></Content> 37 </xml>"; 38 $fromUser=$postObj->ToUserName;//开发者,公众号的 39 $toUser=$postObj->FromUserName;//用户,订阅公众号的人 40 $time=time(); 41 $msgType='text'; 42 // $content='imooc is very good'; 43 echo sprintf($template,$toUser,$fromUser,$time,$msgType,$content); 44 } //responseText end 45 //回复微信用户的关注事件 46 public function responseSubscribe($postObj, $arr){ 47 48 $this->responseNews($postObj,$arr); 49 } 50 51 }
以上内容是【/gzh/Wx/Home/Model/IndexModel.class.php】页面的代码