您好,欢迎访问一九零五行业门户网

PHP获取QQ邮箱好友的具体代码讲解_PHP教程

目前,大家都在使用qq,并且还将qq附带的一些其他软件当做自己的日常使用工具。今天我们就向大家介绍有关如何运用具体的php获取qq邮箱好友的代码如下:
php /**   * @file class.qqhttp.php  * qq邮箱登陆获取类  * @author wccao8222@gmail.com> * @date 2009-04-27   */   class qqhttp {       var $cookie = '';       function __cunstrut() {      }       function makeform() {          $form = array(              'url' => http://mail.qq.com/cgi-bin/loginpage,          );          $data = $this->curlfunc($form);          preg_match('/name=tssvalue=(d+)/',$data['html'], $tspre);          $ts = $tspre[1];          preg_match('/action=http://(md+).mail.qq.com/',$data['html'], $server);          $server_no = $server[1];           /*  login.html 载入 */          $html = file_get_contents(dirname(__file__).'/login.htm');          $html = str_replace('{_ts_}',$ts, $html);          $html = str_replace('{_server_no_}',$server_no, $html);          return $html;      }       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;      }       /**        * 获取验证码图片和cookie       * @param null       *        * @return array('img'=>string, 'cookie'=>string)       */      function getvfcode ()       {          $vfcode = array(              'header' => true,              'cookie' => false,              'url'=>'http://ptlogin2.qq.com/getimage?aid='.$_get['aid'].'&'.@$_get['t'],          );           $r = $this->curlfunc($vfcode);          if ($r['http_code'] != 200 ) return false;          $data = split(n, $r['html']);          preg_match('/verifysession=([^;]+);/',$data[5], $temp);          $cookie = trim($temp[1]);          $img = $data[9];          return  array('img'=>$img,'cookie'=>$cookie);      }       /**        * 登陆qq邮箱       *        * @param $cookie getvfcode中生成的cookie       *        * @return array(       *   sid=>string , //用户认证的唯一标示       *   login => boolean, //true 登陆成功 ,false 登陆失败       *   server_no => string // 服务器编号       *   active => boolean //true 已开通 ,false 未开通 邮箱       *   cookie => string // 获取数据cookie       *       * );       */      function login($cookie)       {          /* 生成参数字符串 */          $post = array();          foreach($_post as $k => $v) {              $post[] = $k.'='.urlencode($v);          }          $poststr = implode('&',$post);          $r['server_no'] = $_get['server_no'];           $login = array(              'url'=>'http://'.$r['server_no'].'.mail.qq.com/cgi-bin/login?sid=0,2,zh_cn',              'header' => true,              'cookie' => 'verifysession='.$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;          }           /* 测试数据 */          //$data['html'] =file_get_contents('./r.txt');          $r['uin'] = $_post['uin'];          /* 登陆错误的判断 */          if (preg_match('|errtype=(d)|', $data['html'], $temp_err)) {              $r['login'] = false;              if ($temp_err[1] == 1) {                  $r['msg'] = '账号和密码错误';              } elseif ($temp_err[1] == 2) {                  $r['msg'] = '验证码错误';              }              return $r;          }          /* 登陆成功 */          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;          }          /* 登录后cookie的获取 ,在后续操作中用到 */          if (preg_match_all('|set-cookie:([^=]+=[^;]+)|i', $data['html'], $new_cookies) ) {              $cookiestr = implode('; ', $new_cookies[1]);              $cookiestr .= '; verifysession='.$cookie;          }           $r['login'] = true;          $r['cookie'] = $cookiestr;          return $r;      }       function openemail($param)       {          $openemail = array(              'url'=>'http://'.$param['server_no'].'.mail.qq.com/cgi-bin/autoactivation?actmode=6&sidsid='.$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,              ),          );           $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;      }       /**        *        * 获取friends数据        *        * @param $param = array(       *   sid=>string , //用户认证的唯一标示       *   login => boolean, //true 登陆成功 ,false 登陆失败       *   server_no => string // 服务器编号       *   active => boolean //true 已开通 ,false 未开通 邮箱       *   cookie => string // 获取数据cookie       *       * );       * @return array(       *   key=>value, // key:qq号,value: nickname       * );       */      function getfriends($param)      {           $friend = array(              'url'=>'http://'.$param['server_no'].'.mail.qq.com/cgi-bin/addr_listall?type=user&&category=all&sidsid='.$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>img class=l_q name=qqplusimg key=(d+)[^>]+/> ([^]+)span>p>|i', $data, $temp_list);          if ($preg == 0) return array();          $list = array_combine($temp_list[1],$temp_list[2]);          return $list;      }       /**        * 错误显示       *        * @param $str array       *        * @return        */      function error($str) {          $str['html'] = str_replace('script','', $str['html']);          var_dump($str);          exit;      }  }   ?> 
怎么样,通过以上对于php获取qq邮箱好友的代码的介绍,大家是否已经完全掌握了呢?
http://www.bkjia.com/phpjc/446439.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/446439.htmltecharticle目前,大家都在使用qq,并且还将qq附带的一些其他软件当做自己的日常使用工具。今天我们就向大家介绍有关如何运用 具体的php获取qq邮箱...
其它类似信息

推荐信息