为什么我的老是回复不了

来源:5-3 验证单图文

奈斯涂咪涂u

2018-09-12 17:51

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');

}


写回答 关注

1回答

  • 奈斯涂咪涂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');
    
    }


PHP实现微信公众平台开发—提升篇

本课程详细讲解了接收微信用户发送的消息和接收订阅关注的事件推送

64923 学习 · 258 问题

查看课程

相似问题