PHP模擬登入QQ信箱取得QQ好友清單的方法

WBOY
發布: 2016-07-25 08:53:02
原創
1970 人瀏覽過
  1. /**

  2. * @file class.qqhttp.php
  3. * qq郵箱登陸取得類別
  4. * @author wc
  5. * @site bbs.it-home.org
  6. */
  7. 類 QQHttp {

  8. var $cookie = '';
  9. function __cunstrut() {
  10. }
  11. function makeForm() {
  12. $form = array(
  13. 'url' => "http://mail.qqq .com/cgi-bin/loginpage",
  14. );
  15. $data = $this->curlFunc($form);
  16. preg_match('/name="ts"svalue="(d )"/',$data['html'], $tspre);
  17. $ts = $tspre[1];
  18. preg_match('/action="http://(md ).mail.qq.com/',$data['html'], $server);
  19. $server_no = $server[1];
  20. /* login.html 加载 */
  21. $html = file_get_contents(dirname(__FILE__).'/login.htm');
  22. $html = str_replace('{_ts_}', $ ts, $html);
  23. $html = str_replace('{_server_no_}',$server_no, $html);
  24. return $html;
  25. }
  26. 函数curlFunc($array )
  27. {
  28. $ch =curl_init();
  29. curl_setopt($ch, CURLOPT_URL, $array['url']);
  30. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if( isset( $array['header']) && $array['header'] ) {
  31. curl_setopt($ch, CURLOPT_HEADER, 1);
  32. }
  33. if(isset($array[') httpheader'] )) {
  34. curl_setopt($ch, CURLOPT_HTTPHEADER, $array['httpheader']);
  35. }
  36. if(isset($array['referer'])) {
  37. curl_setopt($ch , CURLOPT_REFERER, $array['referer']);
  38. }
  39. if( isset($array['post']) ) {
  40. curl_setopt($ch, CURLOPT_POST, 1 );
  41. curl_setopt ($ch, CURLOPT_POSTFIELDS, $array['post']);
  42. }
  43. if( isset($array['cookie']) ){
  44. curl_setopt($ch, CURLOPT_COOKIE, $array['餅乾']);
  45. }
  46. $r['erro'] = curl_error($ch);
  47. $r['errno'] = curl_errno($ch);
  48. $r['html'] = curl_exec($ch);
  49. $r['http_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  50. curl_close($ch);
  51. 回傳 $r;
  52. }
  53. /**
  54. * 取得驗證碼圖片和cookie
  55. * @param Null
  56. *
  57. * @return array('img'=>String, 'cookie'=>String)
  58. */
  59. function getVFCode ()
  60. {
  61. $vfcode = array(
  62. 'header' => true,
  63. 'cookie' => false,
  64. 'url'=>'http://ptlogin2.qq.com/getimage?aid='.$_GET['aid'].'&'.@$_GET ['t '],
  65. );
  66. $r = $this->curlFunc($vfcode);
  67. if ($r['http_code'] != 200 ) return false;
  68. $data = split("n", $r['html']);
  69. preg_match('/verifysession=([^;] );/',$data[5], $temp);
  70. $cookie = trim($temp[1]);
  71. $img = $data[9];
  72. return array('img'=>$img,'cookie'=>$cookie);
  73. }
  74. /**
  75. * 登陸qq郵箱
  76. *
  77. * @param $cookie getvfcode中產生的cookie
  78. *
  79. * @return array(
  80. * sid=>String , //使用者認證的唯一標示
  81. * login => Boolean, //true 登陸成功,false 登陸失敗
  82. * server_no => String // 伺服器編號
  83. * active => Boolean //true 已開通,false 未開通信箱
  84. * cookie => String // 取得資料cookie
  85. *
  86. * );
  87. */
  88. function login($cookie)
  89. {
  90. /* 產生參數字串*/
  91. $post = array();
  92. foreach($_POST as $k => $v) {
  93. $post[] = $k.'='.urlencode($v);
  94. }
  95. $poststr = implode('&' ,$post);
  96. $r['server_no'] = $_GET['server_no'];
  97. $login = array(
  98. 'url'=>'http://'. $r['server_no'].'.mail.qq.com/cgi-bin/login?sid =0,2,zh_CN',
  99. 'header' => true,
  100. 'cookie' => ' verifysession='.$cookie,
  101. 'referer' => 'http:// mail.qq.com/cgi-bin/loginpage',
  102. 'httpheader'=>array(
  103. "主機: " . $r['server_no'] . '.mail.qq.com',
  104. "用戶代理: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",
  105. "內容-類型:application/x-www-form-urlencoded",
  106. ),
  107. 'post' => $poststr ,
  108. );
  109. $data = $this->curlFunc($login);
  110. $data['html'] = iconv("gb2312", "UTF-8", $data['html']);
  111. if ($data['http_code'] != 200) {
  112. $this->error($data);
  113. 回傳false;
  114. }
  115. /* 測試資料*/
  116. //$data['html'] =file_get_contents('./r.txt');
  117. $r['uin'] = $_POST['uin'];
  118. /*登陸錯誤的判斷*/
  119. if (preg_match('|errtype=(d)|', $data['html'], $temp_err)) {
  120. $r['login' ] = 假;
  121. if ($temp_err[1] == 1) {
  122. $r['msg'] = '帳號與密碼錯誤';
  123. } elseif ($temp_err[1] == 2) {
  124. $r['msg'] = '驗證碼錯誤';
  125. }
  126. 回傳$r;
  127. }
  128. /* 登陸成功*/
  129. preg_match('|urlHead="( [^"] )"|i',$data['html'],$temp_url);
  130. $ urlhead = $temp_url[1];
  131. if (preg_match('|frame_html?sid=([^ "] )"|i',$data['html'],$temp_sid) ) {
  132. $r ['sid'] = $temp_sid[1];
  133. $r['active'] = true ;
  134. } elseif (preg_match('|autoactivation?sid=([^&] )?&|i' ,$data['html'],$temp_sid) ) {
  135. $r['sid'] = $temp_sid[1];
  136. $r['active'] = false
  137. }
  138. /* 登入後cookie的獲取,在後續操作中用到*/
  139. if (preg_match_all(' |Set-Cookie:([^=] =[^;] )|i', $data['html '], $new_cookies) ) {
  140. $cookiestr = implode('; ', $new_cookies[1] );
  141. $cookiestr .= '; verifysession='.$cookie
  142. }
  143. $r['登入'] = true;
  144. $r['cookie'] = $cookiestr ;
  145. 回傳$r;
  146. }// bbs.it-home.org
  147. function openEmail($param)
  148. {
  149. $openEmail = array(
  150. 'url'=>'http://'.$param ['server_no'].'.mail.qq.com/cgi-bin/autoactivation?actmode=6&sid='.$param['sid'],
  151. 'header' => true,
  152. 'cookie' => $param['cookie'],
  153. 'refer' => 'http://'.$param['server_no'].'mail.qq.com/cgi-bin/autoactivationside='$param [ 'sid'].'&action=reg_activate&actmode=6',
  154. 'httpheader'=>array(
  155. "一:" . $param['server_no'] . '.mail .qq.com' ,
  156. '預設參數:gb2312,utf-8;q=0.7,*;q=0.7',
  157. "預設參數: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",
  158. ),
  159. );
  160. $data = $this->curlFunc($openEmail);
  161. if (preg_match('|Set-Cookie:qqmail_activated=0|i', $data['html'])) {
  162. $param['active'] = true;
  163. $param['cookie'] = $param['cookie'].'; qqmail_activated = 0 ; qqmail_alias=';
  164. }
  165. 預設 $param;
  166. }
  167. /**
  168. *
  169. * 取得friends資料
  170. *
  171. * @param $param = array(
  172. * sid=>String , //使用者認證的唯一標示
  173. * login => Boolean , //true 登陸成功,false 登陸失敗
  174. * server_no => String // 伺服器編號
  175. * active => Boolean //true 已開通,false 未開通信箱
  176. * cookie => String //取得資料cookie
  177. *
  178. * );
  179. * @return Array(
  180. * key=>value, // key:qq號,value: nickname
  181. * );
  182. */
  183. function getFriends($param)
  184. {
  185. $friend = array(
  186. 'url'=> ;'http://'.$param['server_no'].'.mail.qq.com/cgi-bin/addr_listall? header' => true,
  187. 'cookie' => $param['cookie' ],
  188. '推薦人' => 'http://m151.mail.qq.com/cgi-bin/addr_listall?sid ='.$param['sid'].'&sorttype=null&category=common',
  189. 'httpheader'=>array(
  190. "一:" . $param['server_no'] . ' .mail.qq .com',
  191. 'Accept-Charset:utf-8;q=0.7 , *;q=0.7',
  192. "預設參數: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 " ,
  193. ),
  194. );
  195. $r = $this->curlFunc($friend);
  196. if ($r['http_code'] != 200) {
  197. $this->error($r);
  198. 預設 false:
  199. }
  200. $data = $r['html'];
  201. $preg = preg_match_all('|

    PHP模擬登入QQ信箱取得QQ好友清單的方法] /> ([^

    |i', $data, $temp_list);
  202. if ($ preg == 0 ) return array ( ) ;
  203. $list = array_combine($temp_list[1],$temp_list[2]);
  204. 關鍵字 $list;
  205. }
  206. /**
  207. * 錯誤顯示
  208. *
  209. * @param $str array
  210. *
  211. * @return
  212. */
  213. 公鑰($str) {
  214. $str['html'] = str_replace('script','', $str ['html']);
  215. var_dump($str);
  216. 免費
  217. }
  218. }
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板