小刺猬1
2017-08-23 15:34
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://www.imooc.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 $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);
你对比下,我这个是对的
$toUser=$postObj->FromUserName;
$fromUser=$postObj->ToUserName;
$arr =array(
array( //二维数组变成多维数组
'title'=>'imooc',
'description'=>"imooc is very cool",
'picUrl'=>'http://www.imooc.com/static/img/common/logo.png',
'url'=>'http://www.imooc.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> ";
echo sprintf($template, $toUser, $fromUser, time(), 'news');
$msgType =‘news’
PHP实现微信公众平台开发—提升篇
64923 学习 · 258 问题
相似问题