PHP實現QQ空間自動回複說說的方法_php技巧

來源:互聯網
上載者:User

本文執行個體講述了PHP實現QQ空間自動回複說說的方法。分享給大家供大家參考,具體如下:

<?php header("Content-type: text/html; charset=utf-8"); $qq = '';//QQ號 $sid = '';//填寫sid的值 $con = '';//自訂內容,留空則使用simsimi $qzone = new qzone($qq,$sid); class qzone{   private $sid ='';   public function __construct($qq,$sid){     $this->sid = $sid;     $url = "http://ish.z.qq.com/infocenter_v2.jsp?B_UID={$qq}&sid={$sid}&g_ut=2";     $re = $this->fetch($url);     $this->getsaying($re);   }   private function fetch($url,$postdata=null){     $ch = curl_init();//www.oicqzone.com     curl_setopt($ch, CURLOPT_URL,$url);     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 820)");     if($postdata!=null) curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);     curl_setopt($ch, CURLOPT_TIMEOUT, 20);     $re = curl_exec($ch);     curl_close($ch);     return $re;   }   private function getsaying($html){     preg_match_all('/<\/a>:(.*?)評論\(\d\)<\/a>/',$html,$match);     foreach($match[0] as $k){       if(strstr($k,'評論(0)')){         $k = str_replace(PHP_EOL, '', $k);         $k = str_replace('
', '', $k);         $k = html_entity_decode($k);         preg_match('/<\/a>:(.*?)<span class="txt-fade">/',$k,$content);//www.oicqzone.com         preg_match('/myfeed_mood.jsp\?sid=.*&B_(.*?)&t1_source/',$k,$data);         $content = preg_replace('/<img[^>]+>/', '', $content[1]);         echo '找到一條說說:'.$content.' 機器人的回複是:';         $data = 'B_'.$data[1];         $content = talk($content);         echo $content.'<br />';         $this->postcomment($content,$data);         sleep(3);       }     }   }   private function postcomment($content,$data){     $postdata = "content={$content}&{$data}&t1_source=1&feedcenter_pn=1&flag=1&type=all&channel=0&back=false&offset=0&ic=false&dl=null&to_tweet=0&submit=%E8%AF%84%E8%AE%BA";     $this->fetch("http://blog30.z.qq.com/mood/mood_reply.jsp?sid={$this->sid}&g_ut=2",$postdata);     } } function talk($content){     global $con;     if($con) return $con;   $content = str_replace(' ', '', $content);     $ch = curl_init();   curl_setopt($ch,CURLOPT_URL,'http://www.simsimi.com/talk.htm');   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   curl_setopt($ch, CURLOPT_HEADER,1);   curl_setopt($ch, CURLOPT_NOBODY, false);   $rs = curl_exec($ch);   preg_match_all('/Set-Cookie: (.+)=(.+)$/m', $rs, $regs);   foreach($regs[1] as $i=>$k);   $cc=str_replace(' Path','' ,$k);   $cc='simsimi_uid=507454034223;'.$cc;   $re = HTTPClient('http://www.simsimi.com/func/reqN?lc=ch&ft=1.0&req='.$content.'&fl=http%3A%2F%2Fwww.simsimi.com%2Ftalk.htm',$cc);   $re = json_decode($re,true);   return $re['sentence_resp']; } function HTTPClient($url,$cookie){   $ch = curl_init();   curl_setopt($ch, CURLOPT_URL,$url);   curl_setopt($ch, CURLOPT_COOKIE,$cookie);   curl_setopt($ch, CURLOPT_HEADER, 0);   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   curl_setopt($ch, CURLOPT_TIMEOUT, 30);   $re = curl_exec($ch);   curl_close($ch);   return $re; } ?>

希望本文所述對大家PHP程式設計有所協助。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.