问答详情
源自:5-3 验证单图文

为什么我的老是回复不了

if (strtolower($postObj->MsgType) == 'text' && trim($postObj->Content) == 'tuwen1') {
    $toUser = $postObj->FromUserName;
    $fromUser = $postObj->ToUserName;
    $arr = array(
        array(
            'title' => 'niubi',
            'description' => 'niubihahahahaha',
            'picUrl' => 'http://www.w3school.com.cn/i/eg_tulip.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 $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');

}


提问者:奈斯涂咪涂u 2018-09-12 17:51

个回答

  • 奈斯涂咪涂u
    2018-09-12 17:52:56

    if (strtolower($postObj->MsgType) == 'text' && trim($postObj->Content) == 'tuwen1') {
        $toUser = $postObj->FromUserName;
        $fromUser = $postObj->ToUserName;
        $arr = array(
            array(
                'title' => 'niubi',
                'description' => 'niubihahahahaha',
                'picUrl' => 'http://www.w3school.com.cn/i/eg_tulip.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 $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');
    
    }