php΢ÐŹ«ÖÚƽ̨½»»¥Óë½Ó¿ÚÏê½â

5年以前  |  阅读数:937 次  |  编程语言:PHP 

±¾ÎÄÖΪÈý´o²¿ÖΪ´o¼Ò½øÐнeÉÜ£¬¾ßÌaÄÚÈÝÈçÏÂ

1¡¢Î¢ÐÅÓû§¡¢Î¢ÐÅþÎñÆ÷ºÍºǫþÎñÆ÷µÄ½»»¥

Àý£ºÎ¢ÐÅÓû§Ïo¹«ÖںŢËÍÒ»ÌoÎı¾ÏuÏ¢£¬ÕaÌoÏuÏ¢»aÊ×ÏÈ´«¸ø΢ÐÅþÎñÆ÷£¬Î¢ÐÅþÎñÆ÷´¦ÀiÕaÌoÐÅÏ¢²¢½«ÆaÒÔxmlÊý¾Ý¸ñʽ´«µÝ¸øºǫþÎñÆ÷£¬ºǫþÎñÆ÷½ÓÊܵ½Êý¾Ýºo»a¶ÔÊý¾Ý½øÐд¦Ài£¬ÔÙÏiÓ¦Êý¾ÝÒÔxmlÊý¾Ý¸ñʽ´«µÝ¸ø΢ÐÅþÎñÆ÷£¬Î¢ÐÅþÎñÆ÷ÔÙÏiÓ¦µ½Óû§Î¢ÐŽçÃae¡£
΢ÐÅÓû§Óe΢Ðźǫ
þÎñÆ÷Ö®¼aµÄ½»»¥¹ý³Ì¾ÍÊÇÊý¾Ý´«µÝ¹ý³Ì£¬Ö»²»¹ýÐeÒªÐeҪͨ¹ý΢ÐÅ*þÎñÆ÷Õa¸oÖÐתվ¡£

*ÄÇô΢ÐÅþÎñÆ÷Õa¸oÖÐתվµ½µ×ÓÐʲôÓã¿ **
¶ÔxmlÊý¾Ý½øÐмӹ¤°u×°ºoÕ¹ÏÖÔÚÊÖ»uÆÁÄ»ÉÏ¡£ÎÒÃǽÓÊܵÄͼÎÄÏuÏ¢,ÈçÏ£º

µ¥Í¼ÎÄ£º

¶aͼÎÄ

Äa»a¢ÏÖ΢ÐÅÉϼ¸ºoËuÓеÄͼÎĶ¼ÊÇÕaÖÖ¸ñʽ£¬°aʽ¡¢´oС¶¼ÊÇÒ»Ñu£¬Õa¾ÍÊǾ­¹ý΢ÐÅþÎñÆ÷°u×°ºoµÄ½a¹u¡£

2¡¢½»»¥µÄÊý¾ÝÀaÐÍ

΢ÐÅÓû§¿ÉÒÔ*¢Ë͵ÄÊý¾ÝÀaÐÍ
1¡¢Îı¾ÐÍ£¨text£(C)


    <xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[text]]></MsgType>
    <Content><![CDATA[%s]]></Content>
    </xml>";

2¡¢ÓiÒo£¨voice£(C)


    <xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[voice]]></MsgType>
    <Format><![CDATA[amr]]></Format>
    <MsgId>5836982871638042400</MsgId>
    <MediaId><![CDATA[PGKsO3LAgbVTsFYO7FGu51KUYa07D0C_Nozz2fn1z6VYtHOsF59PTFl0vagGxkVH]]></MediaId>
    <Recognition><![CDATA[]]></Recognition>//recognition±iʾÓiÒoʶ±ðµÄ½a¹u
    </xml>

3¡¢Í¼Æ¬£¨ img£(C)


    <xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[image]]></MsgType>
    <PicUrl><![CDATA[http://mmbiz.qpic.cn/mmbiz/L4qjYtOibummHn90t1mnaibYiaR8ljyicF3MW7XX3BLp1qZgUb7CtZ0D]]></PicUrl>
    <MsgId>5836982871638042400</MsgId>
    <MediaId><![CDATA[PGKsO3LAgbVTsFYO7FGu51KUYa07D0C_Nozz2fn1z6VYtHOsF59PTFl0vagGxkVH]]></MediaId>
    </xml>

ÿһÌoÏuÏ¢´«¸ø΢ÐÅ*þÎñÆ÷ºo¶¼»a±»±e¼ÇÒ»¸oMsgId£¬ÉÏ´«µÄͼƬ¡¢ÊÓƵ¡¢ÓiÒoµÈÒ²»a±»±e¼ÇÒ»¸omediaId¡£

4¡¢ÊÓƵ£¨video£(C)


    <xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[vedio]]></MsgType>
    <MsgId>5836982871638042400</MsgId>
    <MediaId><![CDATA[PGKsO3LAgbVTsFYO7FGu51KUYa07D0C_Nozz2fn1z6VYtHOsF59PTFl0vagGxkVH]]></MediaId>
    <ThumbMediaId><![CDATA[mxUJ5gcCeesJwx2T9qsk62YzI
    clCP_HnRdfTQcojlPeT2G9Q3d22UkSLyBFLZ01J]]></ThumbMediald>;//ÊÓƵ¾²Ö¹Ê±ÏÔʾÄÇÕÅͼƬµØÖ*
    </xml>

5¡¢µØÀiλÖÃÏuÏ¢£¨location£(C)


    <xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[location]]></MsgType>
    <MsgId>5836982871638042400</MsgId>
    <Location_X>22.539968</Location_X>
    <Location_Y>113.954980</Location_Y>
    <Scale>16</Scale>
    <Label><![CDATA[Öйu¹a¶«Ê¡ÉiÛÚÊÐÄÏɽÇøÉiÄÏ´oµÀ9001ºÅ 
    ÓÊÕþ±aÂe: 518053]]></Label>
    </xml>

6¡¢Á´½ÓÏuÏ¢£¨link£(C)


    <xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[link]]></MsgType>
    <MsgId>5836982871638042400</MsgId>
    <Title><![CDATA[΢ÐŹ«ÖÚƽ̨¿ª*¢ÕߵĽ­ºþ]]></Title>
    <Description><![CDATA[³ÂÀ¤µÄ΢ÐŹ«ÖÚºÅÕa¶Îʱ¼a´o»ð£¬´o¼Ò...]]></Description>
    <Url><![CDATA[http://www.cnblogs.com/txw1958/]]></Url>
    <MsgId>5839907284805129867</MsgId>
    </xml>

ºǫ*þÎñÆ÷ÏiÓ¦µÄÏuÏ¢ÀaÐÍ
1¡¢Îı¾ÐÍ£¨text£(C)
2¡¢ÓiÒo£¨voice£(C)


    <xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[voice]]></MsgType>
    <MsgId>5836982871638042400</MsgId>
    <Voice>
    <MediaId><![CDATA[PGKsO3LAgbVTsFYO7FGu51KUYa07D0C_Nozz2fn1z6VYtHOsF59PTFl0vagGxkVH]]></MediaId>
    </Voice>
    </xml>

3¡¢Í¼Æ¬£¨ img£(C)


    <xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[image]]></MsgType>
    <MsgId>5836982871638042400</MsgId>
    <Image>
    <MediaId><![CDATA[PGKsO3LAgbVTsFYO7FGu51KUYa07D0C_Nozz2fn1z6VYtHOsF59PTFl0vagGxkVH]]></MediaId>
    </Image>
    </xml>

4¡¢ÊÓƵ£¨video£(C)


    <xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[vedio]]></MsgType>
    <MsgId>5836982871638042400</MsgId>
    <video>
    <MediaId><![CDATA[PGKsO3LAgbVTsFYO7FGu51KUYa07D0C_Nozz2fn1z6VYtHOsF59PTFl0vagGxkVH]]></MediaId>
    <ThumbMediaId><![CDATA[mxUJ5gcCeesJwx2T9qsk62YzI
    clCP_HnRdfTQcojlPeT2G9Q3d22UkSLyBFLZ01J]]></ThumbMediald>;//ÊÓƵ¾²Ö¹Ê±ÏÔʾÄÇÕÅͼƬµØÖ*
    </video>
    </xml>

5¡¢ÒoÀÖ£¨music£(C)


    <xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[voice]]></MsgType>
    <MsgId>5836982871638042400</MsgId>
    <Music>
    <Title><![CDATA[×iiÅÃñ×a*ç]]></Title>
    <Description><![CDATA[*i»Ë´«Æae]]></Description>
    <MusicUrl><![CDATA[http://zj189.cn/zj/download/music/zxmzf.mp3]]></MusicUrl>
    <HQMusicUrl><![CDATA[http://zj189.cn/zj/dodownload/music/zxmzf.mp3]]></HQMusicUrl>
    </Music>
    </xml>

6¡¢Í¼ÎÄ£¨news£(C)


    <xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[news]]></MsgType>
    <MsgId>5836982871638042400</MsgId>
    <Content><![CDATA[]]></Content>
    <ArticleCount>%s</ArticleCount>
    <Articles>
    <item>
    <Title><![CDATA[ ¡¾ÉiÛÚ¡¿Êµ¿o ζȣº6¡ae ʪ¶È£º62(C)‡ *çËÙ£º¶«±±*ç2¼¶]]></Title>
    <Description><![CDATA[]]></Description>
    <PicUrl><![CDATA[http://www.doucube.com/weixin/weather/icon/banner.jpg]]></PicUrl>
    <Url><![CDATA[]]></Url>
    </item>
    <item>
    <Title><![CDATA[ ¡¾ÉiÛÚ¡¿Êµ¿o ζȣº6¡ae ʪ¶È£º62(C)‡ *çËÙ£º¶«±±*ç2¼¶]]></Title>
    <Description><![CDATA[]]></Description>
    <PicUrl><![CDATA[http://www.doucube.com/weixin/weather/icon/banner.jpg]]></PicUrl>
    <Url><![CDATA[]]></Url>
    </item>
    </Articles>
    </xml>

ÉÏÃae´uÂeÔÚÊý¾ÝÌiд*½ÃaeÖ»×o²ÎÕÕ¡£ÒÔÉÏ´uÂeÔÚÐeÒªµÄʱºoµ÷Óü´¿É£¬ÕaÀiÖ»ÊÇΪ´o¼ÒÕ¹ÏÖÒÔÏÂÊý¾Ý¸ñʽ¡£
CDATAÊÇÒ»¸o±e¼Ç£¬±»Æa±e¼ÇµÄÎı¾Êý¾ÝÖв»»a±»xml½aÎoÆ÷½øÐнaÎo¡£Ò»¸o CDATA ²¿¼þÒÔ£¢

ToUserName ½ÓÊÕ½ÕʺÅ
FromUserName
¢ËͽÕʺÅ
CreateTime
¢ËÍʼþ
MsgType Êý¾ÝÀaÐÍ
Content Îı¾ÄÚÈÝ
ArticleCount ͼÎÄÊýÁ¿
MsgId Êý¾Ýid
MediaId ý½eid
Title ±eÌa
Description ÃeÊo
MusicUrl ÒoÀÖÁ¬½ÓµØÖ
HQMusicUrl ¸ßÆ
ÖÊÒoÀÖÁ¬½ÓµØÖ*

2¡¢¾ßÌaµÄ½»»¥²½Öe¼´´uÂe

ÔÚÉÏÒ»ÕÂͼ2ÖУ¬ÎÒÃÇΪ²aÊԺŶ¨ÒaÁËurlºÍtoken¡£url¾ÍÊÇÓe΢ÐÅþÎñÆ÷½øÐÐͨÐŵĺǫþÎñÆ÷µØÖ£¬¶øtokenÒ»¸oÏaµ±ÓÚÒ»¸oÁiÅÆ¡£Î¢ÐÅþÎñÆ÷ÓeºǫþÎñÆ÷½øÐÐͨÐÅʱ»a³oʾ¸ÃÁiÅÆ£¬Èç¹uºǫþÎñÆ÷¢ÏÖ΢ÐÅþÎñÆ÷Óe×Ô¼ºÐ¯´øµÄÁiÅÆÏaͬ²Å»a½øÐÐͨÐÅ£¬²»ÏaͬÔo¾Ü¾øͨÐÅ ¡£Õa¸o¹ý³Ì½Ð×otokenÑeÖ¤£¨Õa¸oÁiÅƲ»ÊÇtokenµÄÖµ£(C)¡£
ÉÏÃae±È½ÏÐÎÏoµÄ˵»°£¬ÏÂÃaeÎÒͨ¹ý´uÂeÀ´½aÊÍ
ÀýÈ磺urlΪhttp://weixinceshi111111.applinzi.com/index2.php
token£ºweixin
index2.php´uÂe


    <?php
    //
    // ÏiÓ¦Óû§ÏuÏ¢
    // ΢ÐŹ«ÖÚÕ˺ÅÏiÓ¦¸øÓû§µÄ²»Í¬ÏuÏ¢ÀaÐÍ
    //΢ÐÅ*þÎñÆ÷ÒªºÍºǫ*þÎñÆ÷½øÐÐͨÐÅÊ×ÏÈÒª½øÐÐtokenÑeÖ¤£¬Î¢ÐÅ»aͨ¹ýget*½Ê½*¢ËÍsignature£¨Î¢ÐżÓÃÜÇ(C)Ãu£(C)¡¢nonce£¨Ëae»uÊý£(C)¡¢timestamp£¨Ê±¼a´Á£(C)¡¢echostr£¨Ëae»u×Ö*u´®£(C)¡£ºǫ*þÎñÆ÷»ñÈ¡Ö®ºo»a½«timestamp¡¢nonceÓe×ÔÉi¶¨ÒaµÄTOKEN°´ÕÕÒ»¶¨µÄ˳ÐoÆ´½Ó³É×Ö*u´®£¬Í¨¹ýshal¼ÓÃܺo»ñµÃµÄ½a¹uÓesignature½øÐжԱȣ¬Èç¹uÏaͬÔo°Ñechostr*µ»Ø¸ø΢ÐÅ*þÎñÆ÷¡£ ±iʾÑeÖ¤³É¹¦¡£
    header("content-type:text;charset=utf8");
    define("TOKEN", "weixin");
    //tokenÑeÖ¤ÊÇͨ¹ýget´«ÊaÊý¾Ý£¬Î¢ÐÅÓû§*¢Ë͵ÄÊý¾Ýͨ¹ýpost*½Ê½*¢ËÍ¡£ÏȽøÐÐgetÇeÇo£¬ÔÙ½øÐÐpostÇeÇo¡£
    $wechatObj = new wechatCallbackapiTest();
    //ÅжÏÊÇgetÇeÇo»¹ÊÇpostÇeÇo¡£$_GET['echostr']Èç¹u´aeÔÚ£¬±iʾÊǽøÐÐtokenÑeÖ¤µÄgetÇeÇo¡£*´Ö®ÊÇ´«ÊaÊý¾ÝµÄpostÇeÇo¡£
    if (!isset($_GET['echostr'])) {
     $wechatObj->responseMsg();//ÏiÓ¦Êý¾Ý
    }else{
     $wechatObj->valid();//ÏiÓ¦
    }

    class wechatCallbackapiTest
    {
     public function valid()
     {
     $echoStr = $_GET["echostr"];
     if($this->checkSignature()){
     echo $echoStr;
     exit;
     }
     }

     private function checkSignature()
     {
     $signature = $_GET["signature"];
     $timestamp = $_GET["timestamp"];
     $nonce = $_GET["nonce"];
     $token = TOKEN;
     $tmpArr = array($token, $timestamp, $nonce);
     sort($tmpArr);//¶ÔÊý×eÖеÄÔªËؽøÐÐÅÅÐo
     $tmpStr = implode($tmpArr);//½«Êý×eÖеÄÔªËØÁ¬½Ó³ÉÒ»¸o×Ö*u´®
     $tmpStr = sha1($tmpStr);//¶Ô×Ö*u´®½øÐмÓÃܲÙ×÷¡£

     if($tmpStr == $signature){
     return true;
     }else{
     return false;
     }
     }

     public function responseMsg()
     {
     $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];//»ñÈ¡*¢Ë͹ýÀ´µÄÊý¾Ý¡£
     if (!empty($postStr)){
     $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', );//°Ñxml×Ö*u´®ÔØÈeµ½Ò»¸oSimpleXMLelement¶ÔÏoÖС£simplexml_load_string()ÊÇÒ»ÖÖxml½aÎoÆ÷¡£
     $RX_TYPE = trim($postObj->MsgType);//trimÈ¥µo×Ö*u´®Á½¶Ëkongge¡£

     //Óû§*¢Ë͵ÄÏuÏ¢ÀaÐÍÅжÏ
     switch ($RX_TYPE)
     {
     case "text":
      $result = $this->receiveText($postObj);
      break;
     case "image":
      $result = $this->receiveImage($postObj);
      break;
     case "voice":
      $result = $this->receiveVoice($postObj);
      break;
     case "video":
      $result = $this->receiveVideo($postObj);
      break;
     default:
      $result = "unknow msg type: ".$RX_TYPE;
      break;
     }
     echo $result;
     }else {
     echo "";
     exit;
     }
     }

     private function receiveText($object)
     {
     $keyword = trim($object->Content);

     if($keyword == "Îı¾"){
     //»Ø¸´Îı¾ÏuÏ¢
     $content = "ÕaÊǸoÎı¾ÏuÏ¢";
     $result = $this->transmitText($object, $content);
     }
     else if($keyword == "ͼÎÄ" || $keyword == "µ¥Í¼ÎÄ"){
     //»Ø¸´µ¥Í¼ÎÄÏuÏ¢
     $content = array();
     $content[] = array("Title"=>"µ¥Í¼ÎıeÌa", 
      "Description"=>"µ¥Í¼ÎÄÄÚÈÝ", 
      "PicUrl"=>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg", 
      "Url" =>"http://m.cnblogs.com/?u=txw1958");
     $result = $this->transmitNews($object, $content);
     }
     else if($keyword == "¶aͼÎÄ"){
     //»Ø¸´¶aͼÎÄÏuÏ¢
     $content = array();
     $content[] = array("Title"=>"¶aͼÎÄ1±eÌa", "Description"=>"", "PicUrl"=>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg", "Url" =>"http://m.cnblogs.com/?u=txw1958");
     $content[] = array("Title"=>"¶aͼÎÄ2±eÌa", "Description"=>"", "PicUrl"=>"http://d.hiphotos.bdimg.com/wisegame/pic/item/f3529822720e0cf3ac9f1ada0846f21fbe09aaa3.jpg", "Url" =>"http://m.cnblogs.com/?u=txw1958");
     $content[] = array("Title"=>"¶aͼÎÄ3±eÌa", "Description"=>"", "PicUrl"=>"http://g.hiphotos.bdimg.com/wisegame/pic/item/18cb0a46f21fbe090d338acc6a600c338644adfd.jpg", "Url" =>"http://m.cnblogs.com/?u=txw1958");
     $result = $this->transmitNews($object, $content);

     }
     else if($keyword == "ÒoÀÖ"){
     //»Ø¸´ÒoÀÖÏuÏ¢
     $content = array("Title"=>"×iiÅÃñ×a*ç", 
     "Description"=>"¸eÊÖ£º*i»Ë´«Æae", 
     "MusicUrl"=>"http://121.199.4.61/music/zxmzf.mp3",
     "HQMusicUrl"=>"http://121.199.4.61/music/zxmzf.mp3");
     $result = $this->transmitMusic($object, $content);
     }

     return $result;
     }

     private function receiveImage($object)
     {
     //»Ø¸´Í¼Æ¬ÏuÏ¢ 
     $content = array("MediaId"=>$object->MediaId);
     $result = $this->transmitImage($object, $content);;
     return $result;
     }

     private function receiveVoice($object)
     {
     //»Ø¸´ÓiÒoÏuÏ¢ 
     $content = array("MediaId"=>$object->MediaId);
     $result = $this->transmitVoice($object, $content);;
     return $result;
     }

     private function receiveVideo($object)
     {
     //»Ø¸´ÊÓƵÏuÏ¢ 
     $content = array("MediaId"=>$object->MediaId, "ThumbMediaId"=>$object->ThumbMediaId, "Title"=>"", "Description"=>"");
     $result = $this->transmitVideo($object, $content);;
     return $result;
     } 

     /*
     * »Ø¸´Îı¾ÏuÏ¢£¬½«Òª»Ø¸´µÄxmlÏuÏ¢½øÐаu×°¡£
     */
     private function transmitText($object, $content)
     {
     $textTpl = "<xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[text]]></MsgType>
    <Content><![CDATA[%s]]></Content>
    </xml>";
     $result = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time(), $content);//sprintf£¨£(C)Õa¸oº¯ÊýµÄ×÷Óû¹ÊDZȽÏÓÐÒa˼µÄ£¬¿ÉÒÔËÑË÷¿´¿´¡£
     return $result;
     }

     /*
     * »Ø¸´Í¼Æ¬ÏuÏ¢
     */
     private function transmitImage($object, $imageArray)
     {
     $itemTpl = "<Image>
     <MediaId><![CDATA[%s]]></MediaId>
    </Image>";

     $item_str = sprintf($itemTpl, $imageArray['MediaId']);

     $textTpl = "<xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[image]]></MsgType>
    $item_str
    </xml>";

     $result = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time());
     return $result;
     }

     /*
     * »Ø¸´ÓiÒoÏuÏ¢
     */
     private function transmitVoice($object, $voiceArray)
     {
     $itemTpl = "<Voice>
     <MediaId><![CDATA[%s]]></MediaId>
    </Voice>";

     $item_str = sprintf($itemTpl, $voiceArray['MediaId']);

     $textTpl = "<xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[voice]]></MsgType>
    $item_str
    </xml>";

     $result = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time());
     return $result;
     }

     /*
     * »Ø¸´ÊÓƵÏuÏ¢
     */
     private function transmitVideo($object, $videoArray)
     {
     $itemTpl = "<Video>
     <MediaId><![CDATA[%s]]></MediaId>
     <ThumbMediaId><![CDATA[%s]]></ThumbMediaId>
     <Title><![CDATA[%s]]></Title>
     <Description><![CDATA[%s]]></Description>
    </Video>";

     $item_str = sprintf($itemTpl, $videoArray['MediaId'], $videoArray['ThumbMediaId'], $videoArray['Title'], $videoArray['Description']);

     $textTpl = "<xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[video]]></MsgType>
    $item_str
    </xml>";

     $result = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time());
     return $result;
     }

     /*
     * »Ø¸´Í¼ÎÄÏuÏ¢
     */
     private function transmitNews($object, $arr_item)
     {
     if(!is_array($arr_item))
     return;

     $itemTpl = " <item>
     <Title><![CDATA[%s]]></Title>
     <Description><![CDATA[%s]]></Description>
     <PicUrl><![CDATA[%s]]></PicUrl>
     <Url><![CDATA[%s]]></Url>
     </item>
    ";
     $item_str = "";
     foreach ($arr_item as $item)
     $item_str .= sprintf($itemTpl, $item['Title'], $item['Description'], $item['PicUrl'], $item['Url']);

     $newsTpl = "<xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[news]]></MsgType>
    <Content><![CDATA[]]></Content>
    <ArticleCount>%s</ArticleCount>
    <Articles>
    $item_str</Articles>
    </xml>";

     $result = sprintf($newsTpl, $object->FromUserName, $object->ToUserName, time(), count($arr_item));
     return $result;
     }

     /*
     * »Ø¸´ÒoÀÖÏuÏ¢
     */
     private function transmitMusic($object, $musicArray)
     {
     $itemTpl = "<Music>
     <Title><![CDATA[%s]]></Title>
     <Description><![CDATA[%s]]></Description>
     <MusicUrl><![CDATA[%s]]></MusicUrl>
     <HQMusicUrl><![CDATA[%s]]></HQMusicUrl>
    </Music>";

     $item_str = sprintf($itemTpl, $musicArray['Title'], $musicArray['Description'], $musicArray['MusicUrl'], $musicArray['HQMusicUrl']);

     $textTpl = "<xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime>%s</CreateTime>
    <MsgType><![CDATA[music]]></MsgType>
    $item_str
    </xml>";

     $result = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time());
     return $result;
     }
    }
    ?>

3.½Ó¿Ú

3.1 ½Ó¿ÚÊÇʲô

½Ó¿Ú¾ÍÏaµ±ÓÚÒ»¸o¹¤¾ß£¬¾ß±¸Ìض¨µÄ¹¦ÄÜ¡£±ÈÈçÄaÔÚ½¨Ôi*¿×ÓµÄʱºoÐeÒªÔÚǽÉÏ×e¿×£¬Äa¾Í»aʹÓÃ×e»u¹¤¾ßÀ´×e¿×¡£´Óµ÷À´¹¤¾ßµ½×e¿×Íe³É£¬ÄaÒªÍe³É²aµç¡¢Ð£×¼¡¢×e¿×µÈһϵÁв½Öe£¬×iÖÕʵÏÖÄaµÄÄ¿±e¡£×e»u¾ÍÊÇÎÒÃǵĽӿڣ¬²aµç¡¢Ð£×¼¡¢×e¿×¾ÍÊÇÎÒÃǵ÷Óù¤¾ßÍe³ÉÄ¿µÄ²½Öe¡£

΢ÐŵĴ´½¨²Ëµ¥½Ó¿Ú¾ÙÀý¡£

µ÷ÓýӿڵIJ½Öe£º
1¡¢»ñµÃ΢ÐŲ˵¥½Ó¿ÚµÄÁ¬½ÓµØÖ£¬Í¨¹ýcurlº¯ÊýÓeÕa¸o½Ó¿Ú½¨Á¢¶Ô»°¡£
2¡¢°Ñ´´½¨²Ëµ¥Êý¾Ý
¢Ë͸øÕa¸o½Ó¿Ú¡£
½Ó¿Úµ÷ÓÃÍe³É£¬Õa¸o½Ó¿Ú»a×Ô¶¯°ÑÕaÐ(C)Êý¾Ý½øÐд¦Ài²¢ÔÚ΢ÐŹ«ÖÚºÃÒ³ÃaeÉu³É²Ëµ¥¡£

΢ÐŽӿڵĵ÷ÓýʽÇe¿´ÏÂÒ»Õ£ºÎ¢ÐŹ«ÖÚƽ̨¿ª¢£¨Èý£(C)£ºÎ¢ÐŸ߼¶½Ó¿ÚµÄµ÷Óá£

ÒÔÉϾÍÊDZ¾ÎĵÄÈ«²¿ÄÚÈÝ£¬Ï£Íu¶Ô´o¼ÒµÄѧϰÓÐËu°iÖu£¬Ò²Ï£Íu´o¼Ò¶a¶aÖ§³Ö½Å±¾Ö®¼Ò¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例