问答详情
源自:5-4 验证多图文

多图文显示 ,只显示第一条数据?不知道为什么,下载老师的源码也是这样,求助大佬!

多图文显示 ,只显示第一条数据?不知道为什么,下载老师的源码也是这样,求助大佬!

 if(trim($postObj->Content)=="tuwen2"){
                //返回的数据类型位 news ,图文类型
                $msgType="news";
//                组装单条图文信息
                $arr=[
                    array(
                        //文章标题
                        'Title'=>'baidu',
                        //文章描述
                        'Description'=>'百度是个好地方啊',
                        //文章图片链接
                        'PicUrl'=>'https://www.baidu.com/img/bd_logo1.png',
                        //点击图文后的跳转地址
                        'Url'=>'https://www.baidu.com/',
                    ),
                    array(
                        //文章标题
                        'Title'=>'imooc',
                        //文章描述
                        'Description'=>'慕课是个好地方啊',
                        //文章图片链接
                        'PicUrl'=>'http://106.14.173.104/static/images/people.jpg',
                        //点击图文后的跳转地址
                        'Url'=>'https://www.imooc.com/',
                    ),

                ];
                echo $this->getNewsTemplate($toUser,$fromUser,$time,$msgType,$arr);
//组合 图文回复 XML格式数据
public function getNewsTemplate($ToUserName,$FromUserName,$CreateTime,$MsgType,$arr){
    //组装消息模板
    $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>";
    $result=sprintf($template,$ToUserName,$FromUserName,$CreateTime,$MsgType);
    return $result;
}


提问者:qq_用微笑来接纳_0 2018-11-09 11:54

个回答