{"id":1115,"date":"2010-07-14T11:39:00","date_gmt":"2010-07-14T03:39:00","guid":{"rendered":"\/?p=1115"},"modified":"2010-07-14T11:39:00","modified_gmt":"2010-07-14T11:39:00","slug":"1115","status":"publish","type":"post","link":"https:\/\/blog.vimge.com\/archives\/php\/1115.html","title":{"rendered":"PHP\u83b7\u53d6QQ\u90ae\u7bb1\u7528\u6237\u597d\u53cb\u7684\u65b9\u6cd5\u3010\u8f6c\u3011"},"content":{"rendered":"

\u6211\u7528php\u505a\u4e86\u6539\u5199\uff0c\u53ef\u80fd\u6709\u4e0d\u5b8c\u5584\u7684\u5730\u65b9\u3002 <\/p>\n

\u9644\u4ef6\u4e2d\u6709\u4ee3\u7801\uff0c<\/p>\n

\u4e3b\u8981\u7684\u7c7b\u4e3aclass.qqhttp.php<\/p>\n

<?php
\/**
* @file class.qqhttp.php
* qq\u90ae\u7bb1\u767b\u9646\u83b7\u53d6\u7c7b
* @author wc<cao8222@gmail.com<\/a>>
* @date 2009-04-27
*\/<\/p>\n

class QQHttp {<\/p>\n

   var $cookie = ”;<\/p>\n

   function __cunstrut() {
   }<\/p>\n

   function makeForm() {
       $form = array(
           ‘url’ => "
http:\/\/mail.qq.com\/cgi-bin\/loginpage<\/a>",
       );
       $data = $this->curlFunc($form);
       preg_match(‘\/name="ts"\\svalue="(\\d+)"\/’,$data[‘html’], $tspre);
       $ts = $tspre[1];
       preg_match(‘\/action="http:\\\/\\\/(m\\d+)\\.mail\\.qq\\.com\/’,$data[‘html’], $server);
       $server_no = $server[1];<\/p>\n

       \/*login.html \u8f7d\u5165 *\/
       $html = file_get_contents(dirname(__FILE__).’\/login.htm’);
       $html = str_replace(‘{_ts_}’,$ts, $html);
       $html = str_replace(‘{_server_no_}’,$server_no, $html);
       return $html;
   }<\/p>\n

   function curlFunc($array)
   {
       $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL, $array[‘url’]);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
       if( isset($array[‘header’]) && $array[‘header’] ) {
           curl_setopt($ch, CURLOPT_HEADER, 1);
       }
       if(isset($array[‘httpheader’])) {
           curl_setopt($ch, CURLOPT_HTTPHEADER, $array[‘httpheader’]);
       }
       if(isset($array[‘referer’])) {
           curl_setopt($ch, CURLOPT_REFERER, $array[‘referer’]);
       }
       if( isset($array[‘post’]) ) {
           curl_setopt($ch, CURLOPT_POST, 1 );
           curl_setopt($ch, CURLOPT_POSTFIELDS, $array[‘post’]);
       }
       if( isset($array[‘cookie’]) ){
           curl_setopt($ch, CURLOPT_COOKIE, $array[‘cookie’]);
       }
       $r[‘erro’] = curl_error($ch);
       $r[‘errno’] = curl_errno($ch);
       $r[‘html’] = curl_exec($ch);
       $r[‘http_code’] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
       curl_close($ch);
       return $r;
   }<\/p>\n

   \/**
    * \u83b7\u53d6\u9a8c\u8bc1\u7801\u56fe\u7247\u548ccookie
    * @param Null
    *
    * @return array(‘img’=>String, ‘cookie’=>String)
    *\/
   function getVFCode ()
   {
       $t = ‘http:\/\/m127.mail.qq.com\/cgi-bin\/getverifyimage?aid=23000101&0.8881121444410955’;
       $t = ‘ttp:\/\/mail.qq.com\/cgi-bin\/getinvestigate?t=loginpage&stat=verifyimg&verifyuser=49450402’;
       $vfcode = array(
           ‘header’ => true,
           ‘cookie’ => false,
           ‘url’=>’http:\/\/’.$_GET[‘server_no’].’.mail.qq.com\/cgi-bin\/getverifyimage?aid=’.$_GET[‘aid’].’&’.@$_GET[‘t’],
       );
       \/\/var_dump($vfcode);<\/p>\n

       $r = $this->curlFunc($vfcode);
       if ($r[‘http_code’] != 200 ) return false;
       $data = split("\\n", $r[‘html’]);
       \/\/var_dump($data);exit;
       preg_match(‘\/verifyimagesession=([^;]+);\/’,$data[7], $temp);
       $cookie = trim($temp[1]);
       $img = $data[11];
       returnarray(‘img’=>$img,’cookie’=>$cookie, ‘data’=>$data);
   }<\/p>\n

   \/**
    * \u767b\u9646qq\u90ae\u7bb1
    *
    * @param $cookie getvfcode\u4e2d\u751f\u6210\u7684cookie
    *
    * @return array(
    *  sid=>String , \/\/\u7528\u6237\u8ba4\u8bc1\u7684\u552f\u4e00\u6807\u793a
    *  login => Boolean, \/\/true \u767b\u9646\u6210\u529f \uff0cfalse \u767b\u9646\u5931\u8d25
    *  server_no => String \/\/ \u670d\u52a1\u5668\u7f16\u53f7
    *  active => Boolean \/\/true \u5df2\u5f00\u901a \uff0cfalse \u672a\u5f00\u901a \u90ae\u7bb1
    *  cookie => String \/\/ \u83b7\u53d6\u6570\u636ecookie
    *
    * );
    *\/
   function login($cookie)
   {
       \/* \u751f\u6210\u53c2\u6570\u5b57\u7b26\u4e32 *\/
       $post = array();
       foreach($_POST as $k => $v) {
           $post[] = $k.’=’.urlencode($v);
       }
       $poststr = implode(‘&’,$post);
       $r[‘server_no’] = $_GET[‘server_no’];<\/p>\n

       $login = array(
           ‘url’=>’http:\/\/’.$r[‘server_no’].’.mail.qq.com\/cgi-bin\/login?sid=0,2,zh_CN’,
           ‘header’ => true,
           ‘cookie’ => ‘verifyimagesession=’.$cookie,
           ‘referer’ => ‘http:\/\/mail.qq.com\/cgi-bin\/loginpage’,
           ‘httpheader’=>array(
               "Host: " . $r[‘server_no’] . ‘.mail.qq.com’,
               "User-Agent: Mozilla\/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.9) Gecko\/2009040821 Firefox\/3.0.9 FirePHP\/0.2.4",
               "Content-Type: application\/x-www-form-urlencoded",
           ),
           ‘post’ => $poststr ,
       );
       $data = $this->curlFunc($login);
       $data[‘html’] = iconv("gb2312", "UTF-8", $data[‘html’]);
       if ($data[‘http_code’] != 200) {
           $this->error($data);
           return false;
       }<\/p>\n

      \/\/ var_dump(str_replace(‘script’,”,$data));exit;
       \/* \u6d4b\u8bd5\u6570\u636e *\/
       \/\/$data[‘html’] =file_get_contents(‘.\/r.txt’);
       $r[‘uin’] = $_POST[‘uin’];
       \/* \u767b\u9646\u9519\u8bef\u7684\u5224\u65ad *\/
       if (preg_match(‘|errtype=(\\d)|’, $data[‘html’], $temp_err)) {
           $r[‘login’] = false;
           if ($temp_err[1] == 1) {
               $r[‘msg’] = ‘\u8d26\u53f7\u548c\u5bc6\u7801\u9519\u8bef’;
           } elseif ($temp_err[1] == 2) {
               $r[‘msg’] = ‘\u9a8c\u8bc1\u7801\u9519\u8bef’;
           }
           return $r;
       }
       \/* \u767b\u9646\u6210\u529f *\/
       preg_match(‘|urlHead="([^"]+)"|i’,$data[‘html’],$temp_url);
       $urlhead = $temp_url[1];
       if (preg_match(‘|frame_html\\?sid=([^"]+)"|i’,$data[‘html’],$temp_sid) ) {
           $r[‘sid’] = $temp_sid[1];
           $r[‘active’] = true;
       } elseif (preg_match(‘|autoactivation\\?sid=([^&]+)?&|i’,$data[‘html’],$temp_sid) ) {
           $r[‘sid’] = $temp_sid[1];
           $r[‘active’] = false;
       }
       \/* \u767b\u5f55\u540ecookie\u7684\u83b7\u53d6 \uff0c\u5728\u540e\u7eed\u64cd\u4f5c\u4e2d\u7528\u5230 *\/
       if (preg_match_all(‘|Set-Cookie:([^=]+=[^;]+)|i’, $data[‘html’], $new_cookies) ) {
           $cookiestr = implode(‘; ‘, $new_cookies[1]);
           $cookiestr .= ‘; verifyimagesession=’.$cookie;
       }<\/p>\n

       $r[‘login’] = true;
       $r[‘cookie’] = $cookiestr;
       return $r;
   }<\/p>\n

   function openEmail($param)
   {
       $openEmail = array(
           ‘url’=>’http:\/\/’.$param[‘server_no’].’.mail.qq.com\/cgi-bin\/autoactivation?actmode=6&sid=’.$param[‘sid’],
           ‘header’ => true,
           ‘cookie’ => $param[‘cookie’],
           ‘referer’ => ‘http:\/\/’.$param[‘server_no’].’mail.qq.com\/cgi-bin\/autoactivation?sid=’.$param[‘sid’].’&action=reg_activate&actmode=6′,
           ‘httpheader’=>array(
               "Host: " . $param[‘server_no’] . ‘.mail.qq.com’,
               ‘Accept-Charset: gb2312,utf-8;q=0.7,*;q=0.7’,
               "User-Agent: Mozilla\/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.9) Gecko\/2009040821 Firefox\/3.0.9 FirePHP\/0.2.4",
           ),
       );<\/p>\n

       $data =$this->curlFunc($openEmail);
       if (preg_match(‘|Set-Cookie:qqmail_activated=0|i’, $data[‘html’])) {
           $param[‘active’] = true;
           $param[‘cookie’] = $param[‘cookie’] .’; qqmail_activated=0; qqmail_alias=’;
       }
       return $param;
   }<\/p>\n

   \/**
    *
    * \u83b7\u53d6friends\u6570\u636e
    *
    * @param $param = array(
    *  sid=>String , \/\/\u7528\u6237\u8ba4\u8bc1\u7684\u552f\u4e00\u6807\u793a
    *  login => Boolean, \/\/true \u767b\u9646\u6210\u529f \uff0cfalse \u767b\u9646\u5931\u8d25
    *  server_no => String \/\/ \u670d\u52a1\u5668\u7f16\u53f7
    *  active => Boolean \/\/true \u5df2\u5f00\u901a \uff0cfalse \u672a\u5f00\u901a \u90ae\u7bb1
    *  cookie => String \/\/ \u83b7\u53d6\u6570\u636ecookie
    *
    * );
    * @return Array(
    *  key=>value, \/\/ key:qq\u53f7\uff0cvalue: nickname
    * );
    *\/
   function getFriends($param)
   {<\/p>\n

       $friend = array(
           ‘url’=>’http:\/\/’.$param[‘server_no’].’.mail.qq.com\/cgi-bin\/addr_listall?type=user&&category=all&sid=’.$param[‘sid’],
           ‘header’ => true,
           ‘cookie’ => $param[‘cookie’],
           ‘referer’ => ‘http:\/\/m151.mail.qq.com\/cgi-bin\/addr_listall?sid=’.$param[‘sid’].’&sorttype=null&category=common’,
           ‘httpheader’=>array(
               "Host: " . $param[‘server_no’] . ‘.mail.qq.com’,
               ‘Accept-Charset:utf-8;q=0.7,*;q=0.7’,
               "User-Agent: Mozilla\/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.9) Gecko\/2009040821 Firefox\/3.0.9 FirePHP\/0.2.4",
           ),
       );
       $r = $this->curlFunc($friend);
       if ($r[‘http_code’] != 200) {
           $this->error($r);
           return false;
       }
       $data =$r[‘html’];
       $preg = preg_match_all(‘|<p class="L_n"><span t="1" u="(\\d+)" n="([^"]+)" e="([^"]+)">|i’, $data, $temp_list);
       if ($preg == 0) return array();
       $list = array_combine($temp_list[1],$temp_list[2]);
       return $list;
   }<\/p>\n

   \/**
    * \u9519\u8bef\u663e\u793a
    *
    * @param $str array
    *
    * @return
    *\/
   function error($str) {
       $str[‘html’] = str_replace(‘script’,”, $str[‘html’]);
       var_dump($str);
       exit;
   }
}<\/p>\n

?><\/p>\n<\/p>\n

\u6e90\u7801\u4e0b\u8f7d\uff1ahttp:\/\/dl.javaeye.com\/topics\/download\/28cecf25-7c12-375d-8293-1897a8630543<\/a>
\u539f\u6587\u5f15\u7528\uff1a
http:\/\/www.javaeye.com\/topic\/375434<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

\u6211\u7528php\u505a\u4e86\u6539\u5199\uff0c\u53ef\u80fd\u6709\u4e0d\u5b8c\u5584\u7684\u5730\u65b9\u3002 <\/p>\n

\u9644\u4ef6\u4e2d\u6709\u4ee3\u7801\uff0c<\/p>\n

\u4e3b\u8981\u7684\u7c7b\u4e3aclass.qqhttp.php<\/p>\n

<?php
\/**
* @file class.qqhttp.php
* qq\u90ae\u7bb1\u767b\u9646\u83b7\u53d6\u7c7b
* @author wc<
cao8222@gmail.com<\/a>>
* @date 2009-04-27
*\/<\/p>\n

class QQHttp {<\/p>\n

   var $cookie = ”;<\/p>\n

   function __cunstrut() {
   }<\/p>\n

   function makeForm() {
 <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1115"}],"collection":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/comments?post=1115"}],"version-history":[{"count":0,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1115\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/media?parent=1115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/categories?post=1115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/tags?post=1115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}