PHP实现QQ空间自动回复说说的方法

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

本文实例讲述了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程序设计有所帮助。

 相关文章:
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分页类完整实例