elseif(strtolower($postObj->MsgType)=='text'?&&?trim($postObj->Content)?==?'單圖文'){//單圖文
$toUser=$postObj->FromUserName;
$fromUser=$postObj->toUserName;
$time=time();
$msgType='news';
$arr=?array(
????array(
??? 'title'=>'小刺猬',
'description'=>'我是一只小刺猬',
'picUrl'=>'http://localhost/tlweixin/public/images/rabbit.jpg',
'url'=>'http://idcbgp.cn',
????),
);
$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?$key=>$value){
$template?.="<item>
<Title><![CDATA[".$value['title']."]]></Title>?
<Description><![CDATA[".$value['description']."]]></Description>
<PicUrl><![CDATA[".$value['picUrl']."]]></PicUrl>
<Url><![CDATA[".$value['url']."]]></Url>
</item>";
}
$template?.="</Articles>
</xml>";
????echo?sprintf($template,$toUser,$fromUser,$time,$msgType);
2017-08-23
你對(duì)比下,我這個(gè)是對(duì)的
$toUser=$postObj->FromUserName;
$fromUser=$postObj->ToUserName;
$arr =array(
? ? ? ?array( ? ? ? //二維數(shù)組變成多維數(shù)組
? ? ? ? ? ?'title'=>'imooc',
? ? ? ? ? ?'description'=>"imooc is very cool",
? ? ? ? ? ?'picUrl'=>'http://idcbgp.cn/static/img/common/logo.png',
? ? ? ? ? ?'url'=>'http://idcbgp.cn',
? ? ? ? ? ?),
);
$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');
2019-08-18
$msgType =‘news’