微信多图文foreach验证失败-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

微信多图文foreach验证失败

小旋风柴进 2016-03-10 11:08:35 1488

请问这段代码哪里有错?

 $newsArr = array(
         array("Title"=>"this is first item",
            "Description"=>"this is first item description",
            "PicUrl"=>"http://img4.imgtn.bdimg.com/it/u=2943793272,3641314298&fm=21&gp=0.jpg",
            "Url"=>"http://www.baidu.com"
         ),
         array("Title"=>"this is second item",
             "Description"=>"this is second item description",
             "PicUrl"=>"http://img2.imgtn.bdimg.com/it/u=945726929,542696667&fm=21&gp=0.jpg",
             "Url"=>"http://www.baidu.com"
         ),
         array("Title"=>"this is thired",
            "Description"=>"this is thired",
            "PicUrl"=>"http://img1.imgtn.bdimg.com/it/u=2783016379,35786742&fm=21&gp=0.jpg",
            "Url"=>"http://www.baidu.com"
         )
);

foreach ($newsArr as $key => $value) {
   $itemstr .= "
         <item>
         <Title><![CDATA[".$value['Title']."]]></Title>
         <Description><![CDATA[".$value['Description']."]]></Description>
         <PicUrl><![CDATA[".$value['PicUrl']."]]></PicUrl>
         <Url><![CDATA[".$value['Url']."]]></Url>
         <item>";
}

   $result = "<xml>
         <ToUserName><![CDATA[%s]]></ToUserName>
         <FromUserName><![CDATA[%s]]></FromUserName>
         <CreateTime>%s</CreateTime>
         <MsgType><![CDATA[news]]></MsgType>
         <ArticleCount>".count($newsArr)."</ArticleCount>
         <Articles>".$itemstr."</Articles>
         </xml>";
   $newsInfo = sprintf($result, $fromUser , $toUser , time());
   echo $newsInfo;
info失败 失败for weixin失败
分享到
取消 提交回答
全部回答(1)
  • 小旋风柴进
    2019-07-17 18:57:12

    item 标签错了

     foreach ($newsArr as $key => $value) {
       $itemstr .= "
             <item>
             <Title><![CDATA[".$value['Title']."]]></Title>
             <Description><![CDATA[".$value['Description']."]]></Description>
             <PicUrl><![CDATA[".$value['PicUrl']."]]></PicUrl>
             <Url><![CDATA[".$value['Url']."]]></Url>
             </item>";
    }
    0 0
云计算
使用钉钉扫一扫加入圈子
+ 订阅

时时分享云计算技术内容,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。

最新问题