<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                測試頁面g1.php展示: ~~~ <?php define('TOKEN','zhangyouwu');//定義token $obj=new Weixin();//實例化函數 if(!isset($_GET['echostr'])){//如果隨機字符串不存在 $obj->receive(); }else{ $obj->checkSignature();//調用函數中的方法 } class Weixin{ public function checkSignature() { $signature = $_GET["signature"];//加密簽名 $timestamp = $_GET["timestamp"];//時間戳 $nonce = $_GET["nonce"];//隨機數 $token = TOKEN; $tmpArr = array($token,$timestamp, $nonce);//組成新數組 sort($tmpArr, SORT_STRING);//重新排序 $tmpStr = implode( $tmpArr );//轉換成字符串 $tmpStr = sha1( $tmpStr );//再將字符串加密 if( $tmpStr==$signature ){ echo $_GET['echostr']; }else{ return false; } } public function receive(){ $obj=$GLOBALS['HTTP_RAW_POST_DATA'];//接受消息 $postSql=simplexml_load_string($obj,'SimpleXMLElement',LIBXML_NOCDATA); $this->logger("接受:\n".$obj); if(!empty($postSql)){ switch(trim($postSql->MsgType)){ case "text": $result=$this->receiveText($postSql); break; case "event": $result=$this->receiveEvent($postSql); break; } if(!empty($result)){ echo $result; }else{ $xml="<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> </xml>"; echo $result=sprintf($xml,$postSql->FromUserName,$postSql->ToUserName,time(),$postSql->MsgType,"沒有這條文本信息(⊙o⊙)…"); } } } //自動回復文本 private function receiveEvent($postSql){ $xml="<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> </xml>"; $result=sprintf($xml,$postSql->FromUserName,$postSql->ToUserName,time(),"text","歡迎來到zyw微信測試"); $this->logger("自動回復消息:\n".$result); return $result; } //處理文本消息 private function receiveText($postSql){ $content=trim($postSql->Content); if(strstr($content,"你好")){//strstr模糊匹配 $xml="<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> </xml>"; $result=sprintf($xml,$postSql->FromUserName,$postSql->ToUserName,time(),$postSql->MsgType,"hello"); return $result; }else if(strstr($content,"單圖文")){ $result=$this->receiveImage($postSql); $this->logger("發送單圖文消息:\n".$result); return $result; } else if(strstr($content,"多圖文")){ $result=$this->receiveImages($postSql); $this->logger("發送多圖文消息:\n".$result); return $result; } else if(strstr($content,"圖片")){ $result=$this->receiveMedia($postSql); $this->logger("發送圖片消息:\n".$result); return $result; } } //圖片 private function receiveMedia($postSql){ $xml="<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Image><MediaId><![CDATA[%s]]></MediaId></Image></xml>"; $result=sprintf($xml,$postSql->FromUserName,$postSql->ToUserName,time(),"image","mtq3etLgLiGtMeCF0GX1QuKgpeK69SjUkkZFRxFvMipccv0QRjLnT1Kn7Ud9PC8I"); return $result; } //單圖文 private function receiveImage($postSql){ $xml="<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <ArticleCount>1</ArticleCount> <Articles> <item><Title><![CDATA[%s]]></Title> <Description><![CDATA[%s]]></Description> <PicUrl><![CDATA[%s]]></PicUrl> <Url><![CDATA[%s]]></Url></item> </Articles></xml>"; $result=sprintf($xml,$postSql->FromUserName,$postSql->ToUserName,time(),"news","zhangyouwu的微信開發","微信開發其實很簡單","http://pic.baike.soso.com/ugc/baikepic2/5494/20170825195528-1233831972_jpg_387_310_14279.jpg/0","http://www.baidu.com"); return $result; } //多圖文,最多8條 private function receiveImages($postSql){ $content=array(); $content[]=array("Title"=>"zhangyouwu的微信開發","Description"=>"微信開發其實很簡單","PicUrl"=>"http://pic.baike.soso.com/ugc/baikepic2/5494/20170825195528-1233831972_jpg_387_310_14279.jpg/0","Url"=>"http://www.baidu.com"); $content[]=array("Title"=>"zhangyouwu的微信開發","Description"=>"微信開發其實很簡單","PicUrl"=>"http://pic.baike.soso.com/ugc/baikepic2/5494/20170825195528-1233831972_jpg_387_310_14279.jpg/0","Url"=>"http://www.baidu.com"); $content[]=array("Title"=>"zhangyouwu的微信開發","Description"=>"微信開發其實很簡單","PicUrl"=>"http://pic.baike.soso.com/ugc/baikepic2/5494/20170825195528-1233831972_jpg_387_310_14279.jpg/0","Url"=>"http://www.baidu.com"); $content[]=array("Title"=>"zhangyouwu的微信開發","Description"=>"微信開發其實很簡單","PicUrl"=>"http://pic.baike.soso.com/ugc/baikepic2/5494/20170825195528-1233831972_jpg_387_310_14279.jpg/0","Url"=>"http://www.baidu.com"); $str="<item> <Title><![CDATA[%s]]></Title> <Description><![CDATA[%s]]></Description> <PicUrl><![CDATA[%s]]></PicUrl> <Url><![CDATA[%s]]></Url></item>"; $news=""; foreach($content as $newArray){ $news.=sprintf($str,$newArray['Title'],$newArray['Description'],$newArray['PicUrl'],$newArray['Url']); } $xml="<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <ArticleCount>%s</ArticleCount> <Articles> $news </Articles></xml>"; $result=sprintf($xml,$postSql->FromUserName,$postSql->ToUserName,time(),"news",count($content)); return $result; } //存儲日志 private function logger($content){//存儲日志 $logSize=100000;//定義日志大小 $log="log.txt";//定義日志名字 if(file_exists($log)&&filesize($log)>$logSize){//如果日志存在并且大于定義的大小 unlink($log);//刪除 } //文件寫入1.名字2.內容,+時間防止重復3.內容往后加而不是覆蓋 file_put_contents($log,date('H:i:s')." ".$content."\n",FILE_APPEND); } } ?> ~~~ 相關部分: ![](https://box.kancloud.cn/0a0ee293ca39c102c09dd772b7f20279_348x53.png) ![](https://box.kancloud.cn/d422cb7b3d6408aa08c8289d8beeff65_786x224.png) 注意: ![](https://box.kancloud.cn/0b7428cae51e31a49a7a78feee4abf59_1005x405.png) 結果展示: ![](https://box.kancloud.cn/af3095f049e601360ae9b0628f2f8649_345x187.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看