$indexModel = new IndexModel;
$indexModel->responseMsg($postObj);
<?php
class IndexModel extends Model{
public function responseMsg($postObj){
$toUser = $postObj->FromUserName;
$FromUser = $postObj->ToUserName;
$time = time();
$MsgType = 'news';
$arr = array(
array(
'title'=>'百度',
'Description'=>'百度非常棒',
'PicUrl'=>'https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png',
'Url'=>'https://www.baidu.com/',
),
array(
'title'=>'腾讯',
'Description'=>'qq非常棒',
'PicUrl'=>'http://img3.redocn.com/20130821/20130817_2bc2c708243ecd0f59ccqU6c3AgCIYt1.jpg',
'Url'=>'http://www.qq.com/',
),
array(
'title'=>'hao123',
'Description'=>'hao123非常好',
'PicUrl'=>'http://img1.imgtn.bdimg.com/it/u=2829392212,3986743237&fm=21&gp=0.jpg',
'Url'=>'https://www.hao123.com/',
),
);
$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>";
$info = sprintf($template,$toUser,$FromUser,$time,$MsgType);
echo $info;
}
}