注册 登录
编程论坛 PHP技术论坛

初学微信开发,多图文回复咋就不行捏

哒哒哒啦啦啦 发布于 2016-09-16 00:41, 3726 次点击
  case'多图文':
                                          
       $newsArr=array(
          array('Title'->"约吗?",
          'Description'->"等你哦",
          'PicUrl'->"http://jhbdeserves-img.stor.,
          'Url'->"https://www.
           )
         array('Title'->"约吗?",
           'Description'->"等你哦",
           'PicUrl'->"http://jhbdeserves-img.stor.,
           'Url'->"https://www.
           )
         );
                    
        foreach(  $newsArr as $item)
        {
          $itemtmpl="<item>
            <Title><![CDATA[%s]]></Title>
            <Description><![CDATA[%s]]></Description>
            <PicUrl><![CDATA[%s]]></PicUrl>
            <Url><![CDATA[%s]></Url>
            </item>";
           $itemstr .=sprintf($itemtmpl,$item['Title'],$item['Description'],$item['PicUrl'],$item['Url']);   
          }
            $replyNewsMsg="<xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[news]]></MsgType>         //news为图文消息意思
                <ArticleCount>2</ArticleCount>            
                <Articles>".$itemstr."</Articles>
               </xml>";
          echo sprintf($replyNewsMsg,$fromuserName,$touserName,time());
          break;
         


[此贴子已经被作者于2016-9-16 00:44编辑过]

6 回复
#2
哒哒哒啦啦啦2016-09-16 00:42
求大神给看看
#3
哒哒哒啦啦啦2016-09-16 00:44
完整的程序,屏蔽掉多图文部分是能用的
<?php


define("TOKEN","weixin");
$signature=$_GET['signature'];   
$timestamp=$_GET['timestamp'];
$nonce=$_GET['nonce'];
$echostr=$_GET['echostr'];  


$tmpArr=array(TOKEN,$timestamp,$nonce);           
 sort($tmpArr,SORT_STRING);   


$tmpstr=implode($tmpArr);

$tmpstr=sha1($tmpstr);

if($tmpstr==$signature)
{
     header('content-type:text');
   echo $echostr;        //echo 为直接输出
}
else
{
   echo "Error";
}




$postData=$HTTP_RAW_POST_DATA;
//echo "嗯呢1";
//2.将xml字符串转化成一个对象(处理xml数据包)
$xmlObj=simplexml_load_string($postData,"SimpleXMLElement",LIBXML_NOCDATA);
$touserName=$xmlObj->ToUserName;    //获取开发者微信号
$fromuserName=$xmlObj->FromUserName; //获取用户openid
$msgtype=$xmlObj->MsgType;    //消息的类型text



/*switch($msgtype)   
        {
        //判断消息类型
        case'text':*/
            $content=trim($xmlObj->Content); //获取文本消息内容
    // echo "嗯呢";
                switch($content)
                      {

                    case'单图文':   
                                                 $replyNewsMsg="<xml>
                                                            <ToUserName><![CDATA[%s]]></ToUserName>
                                                            <FromUserName><![CDATA[%s]]></FromUserName>
                                                            <CreateTime>%s</CreateTime>
                                                            <MsgType><![CDATA[news]]></MsgType>         //news为图文消息意思
                                                            <ArticleCount>1</ArticleCount>            
                                                            <Articles>
                                                            <item>
                                                                    <Title><![CDATA[%s]]></Title>
                                                                    <Description><![CDATA[%s]]></Description>
                                                                    <PicUrl><![CDATA[%s]]></PicUrl>
                                                                    <Url><![CDATA[%s]></Url>
                                                
                                                            </item>
                                                            </Articles>
                                                            </xml>";
                                            $title="是妹子吗";
                                            $description="是就回复一下";
                                            $picurl="http://jhbdeserves-img.stor.
                                            $url="https://www.google.co.jp/search?q=%E5%A6%B9%E5%AD%90&safe=strict&biw=1366&bih=643&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjDq8nHjI_PAhUBnJQKHVTEDk8Q_AUIBigB#safe=strict&tbm=isch&q=%E6%9F%B3%E5%B2%A9";               
                           echo sprintf($replyNewsMsg,$fromuserName,$touserName,time(),$title,$description,$picurl,$url);
                           break;
           /*这里*****                       
                    case'多图文':
                                          
                                $newsArr=array(
                                    array('Title'->"约吗?",
                                          'Description'->"等你哦",
                                          'PicUrl'->"http://jhbdeserves-img.stor.,
                                          'Url'->"https://www.
                                          )
                                    array('Title'->"约吗?",
                                          'Description'->"等你哦",
                                          'PicUrl'->"http://jhbdeserves-img.stor.,
                                          'Url'->"https://www.
                                    )
                                );
                    
                            foreach(  $newsArr as $item)
                            {
                            $itemtmpl="<item>
                                            <Title><![CDATA[%s]]></Title>
                                            <Description><![CDATA[%s]]></Description>
                                            <PicUrl><![CDATA[%s]]></PicUrl>
                                            <Url><![CDATA[%s]></Url>
                        
                                     </item>";
                                $itemstr .=sprintf($itemtmpl,$item['Title'],$item['Description'],$item['PicUrl'],$item['Url']);   
                            }
                $replyNewsMsg="<xml>
                                            <ToUserName><![CDATA[%s]]></ToUserName>
                                            <FromUserName><![CDATA[%s]]></FromUserName>
                                            <CreateTime>%s</CreateTime>
                                            <MsgType><![CDATA[news]]></MsgType>         //news为图文消息意思
                                            <ArticleCount>2</ArticleCount>            
                                            <Articles>".$itemstr."</Articles>
                                            </xml>";
                                                              
                                          
                                                  
                                        echo sprintf($replyNewsMsg,$fromuserName,$touserName,time());
                                        break;
               */         
                                    default:
                                    break;
                                    
                   }
   
?>
#4
tlliqi2016-09-17 18:01
慢慢看
#5
哒哒哒啦啦啦2016-09-18 21:23
回复 4楼 tlliqi
蛤?
#6
哒哒哒啦啦啦2016-09-18 21:54
求大婶们给看看。。
#7
哒哒哒啦啦啦2016-09-18 23:25
解决了。。。
数组用"=>"而不是"->"赋值!
1