PHP Demo login QQ mailbox to get QQ Friends List method

Source: Internet
Author: User
Tags preg
  1. /**

  2. * @file class.qqhttp.php
  3. * QQ Mailbox landing Get class
  4. * @author WC
  5. * @site bbs.it-home.org
  6. */

  7. Class Qqhttp {

  8. var $cookie = ';
  9. function __cunstrut () {
  10. }
  11. function Makeform () {
  12. $form = Array (
  13. ' url ' = ' http://mail.qq.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:\/\/(m\d+) \.mail\.qq\.com/', $data [' html '], $server);
  19. $server _no = $server [1];
  20. /* login.html Loading */
  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. function Curlfunc ($array)
  27. {
  28. $ch = Curl_init ();
  29. curl_setopt ($ch, Curlopt_url, $array [' URL ']);
  30. curl_setopt ($ch, Curlopt_returntransfer, true);
  31. if (Isset ($array [' header ']) && $array [' header ']) {
  32. curl_setopt ($ch, Curlopt_header, 1);
  33. }
  34. if (Isset ($array [' Httpheader '])) {
  35. curl_setopt ($ch, Curlopt_httpheader, $array [' Httpheader ']);
  36. }
  37. if (Isset ($array [' Referer '])) {
  38. curl_setopt ($ch, Curlopt_referer, $array [' REFERER ']);
  39. }
  40. if (Isset ($array [' Post '])) {
  41. curl_setopt ($ch, Curlopt_post, 1);
  42. curl_setopt ($ch, Curlopt_postfields, $array [' Post ']);
  43. }
  44. if (Isset ($array [' Cookie ')]) {
  45. curl_setopt ($ch, Curlopt_cookie, $array [' COOKIE ']);
  46. }
  47. $r [' erro '] = Curl_error ($ch);
  48. $r [' errno '] = Curl_errno ($ch);
  49. $r [' html '] = curl_exec ($ch);
  50. $r [' http_code '] = Curl_getinfo ($ch, Curlinfo_http_code);
  51. Curl_close ($ch);
  52. return $r;
  53. }
  54. /**
  55. * Get Verification code pictures and cookies
  56. * @param Null
  57. *
  58. * @return Array (' img ' =>string, ' Cookie ' =>string)
  59. */
  60. function Getvfcode ()
  61. {
  62. $vfcode = Array (
  63. ' Header ' = True,
  64. ' Cookie ' = False,
  65. ' url ' = ' http://ptlogin2.qq.com/getimage?aid= '. $_get[' aid '. ' & '. @$_get[' t '],
  66. );
  67. $r = $this->curlfunc ($vfcode);
  68. if ($r [' http_code ']! =) return false;
  69. $data = Split ("\ n", $r [' html ']);
  70. Preg_match ('/verifysession= ([^;] +);/', $data [5], $temp);
  71. $cookie = Trim ($temp [1]);
  72. $img = $data [9];
  73. Return Array (' img ' = = $img, ' cookie ' = $cookie);
  74. }
  75. /**
  76. * Login QQ Mailbox
  77. *
  78. * @param cookies generated in the $cookie Getvfcode
  79. *
  80. * @return Array (
  81. * sid=>string,//user authentication unique indication
  82. * Login = Boolean,//true login succeeded, false login failed
  83. * Server_no = String//server number
  84. * Active = Boolean//true is open, false mailbox not opened
  85. * Cookie = String//Get Data cookie
  86. *
  87. * );
  88. */
  89. function Login ($cookie)
  90. {
  91. /* Generate a parameter String */
  92. $post = Array ();
  93. foreach ($_post as $k = = $v) {
  94. $post [] = $k. ' = '. UrlEncode ($v);
  95. }
  96. $poststr = Implode (' & ', $post);
  97. $r [' server_no '] = $_get[' server_no ');
  98. $login = Array (
  99. ' url ' = ' http: '/'. $r [' server_no ']. '. Mail.qq.com/cgi-bin/login?sid=0,2,zh_cn ',
  100. ' Header ' = True,
  101. ' Cookie ' = ' verifysession= '. $cookie,
  102. ' Referer ' = ' http://mail.qq.com/cgi-bin/loginpage ',
  103. ' Httpheader ' =>array (
  104. "Host:". $r [' Server_no ']. '. Mail.qq.com ',
  105. "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 ",
  106. "Content-type:application/x-www-form-urlencoded",
  107. ),
  108. ' Post ' = $poststr,
  109. );
  110. $data = $this->curlfunc ($login);
  111. $data [' html '] = Iconv ("gb2312", "UTF-8", $data [' html ']);
  112. if ($data [' http_code ']! = 200) {
  113. $this->error ($data);
  114. return false;
  115. }
  116. /* Test Data */
  117. $data [' HTML '] =file_get_contents ('./r.txt ');
  118. $r [' uin '] = $_post[' UIn ');
  119. /* Login Error judgment */
  120. if (Preg_match (' |errtype= (\d) | ', $data [' html '], $temp _err)) {
  121. $r [' login '] = false;
  122. if ($temp _err[1] = = 1) {
  123. $r [' msg '] = ' account number and password error ';
  124. } elseif ($temp _err[1] = = 2) {
  125. $r [' msg '] = ' captcha error ';
  126. }
  127. return $r;
  128. }
  129. /* Login Successful */
  130. Preg_match (' |urlhead= ' ([^ "]+)" |i ', $data [' html '], $temp _url);
  131. $urlhead = $temp _url[1];
  132. if (Preg_match (' |frame_html\?sid= ([^ ']+) ' |i ', $data [' html '], $temp _sid)) {
  133. $r [' sid '] = $temp _sid[1];
  134. $r [' active '] = true;
  135. } elseif (Preg_match (' |autoactivation\?sid= ([^&]+) ' &|i ', $data [' html '], $temp _sid)) {
  136. $r [' sid '] = $temp _sid[1];
  137. $r [' active '] = false;
  138. }
  139. /* Access to cookies after login, used in subsequent operations */
  140. if (Preg_match_all (' | Set-cookie: ([^=]+=[^;] +) |i ', $data [' html '], $new _cookies)) {
  141. $cookiestr = Implode ('; ', $new _cookies[1]);
  142. $cookiestr. = '; Verifysession= '. $cookie;
  143. }
  144. $r [' login '] = true;
  145. $r [' cookie '] = $COOKIESTR;
  146. return $r;
  147. }//Bbs.it-home.org
  148. function Openemail ($param)
  149. {
  150. $openEmail = Array (
  151. ' url ' = ' http: '/'. $param [' server_no ']. '. mail.qq.com/cgi-bin/autoactivation?actmode=6&sid= '. $param [' Sid '],
  152. ' Header ' = True,
  153. ' Cookie ' = $param [' Cookie '],
  154. ' referer ' = ' http:/'. $param [' server_no ']. ' Mail.qq.com/cgi-bin/autoactivation?sid= '. $param [' Sid ']. ' &action=reg_activate&actmode=6 ',
  155. ' Httpheader ' =>array (
  156. "Host:". $param [' Server_no ']. '. Mail.qq.com ',
  157. ' accept-charset:gb2312,utf-8;q=0.7,*;q=0.7 ',
  158. "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 ",
  159. ),
  160. );
  161. $data = $this->curlfunc ($openEmail);
  162. if (Preg_match (' | Set-cookie:qqmail_activated=0|i ', $data [' html ']) {
  163. $param [' active '] = true;
  164. $param [' cookie '] = $param [' Cookie ']. '; Qqmail_activated=0; Qqmail_alias= ';
  165. }
  166. return $param;
  167. }
  168. /**
  169. *
  170. * Get Friends Data
  171. *
  172. * @param $param = Array (
  173. * sid=>string,//user authentication unique indication
  174. * Login = Boolean,//true login succeeded, false login failed
  175. * Server_no = String//server number
  176. * Active = Boolean//true is open, false mailbox not opened
  177. * Cookie = String//Get Data cookie
  178. *
  179. * );
  180. * @return Array (
  181. * Key=>value,//KEY:QQ, Value:nickname
  182. * );
  183. */
  184. function Getfriends ($param)
  185. {
  186. $friend = Array (
  187. ' url ' = ' http: '/'. $param [' Server_no ']. Mail.qq.com/cgi-bin/addr_listall?type=user&&category=all&sid= '. $param [' Sid '],
  188. ' Header ' = True,
  189. ' Cookie ' = $param [' Cookie '],
  190. ' Referer ' = ' http://m151.mail.qq.com/cgi-bin/addr_listall?sid= '. $param [' Sid ']. ' &sorttype=null&category=common ',
  191. ' Httpheader ' =>array (
  192. "Host:". $param [' Server_no ']. '. Mail.qq.com ',
  193. ' accept-charset:utf-8;q=0.7,*;q=0.7 ',
  194. "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 ",
  195. ),
  196. );
  197. $r = $this->curlfunc ($friend);
  198. if ($r [' http_code ']! = 200) {
  199. $this->error ($R);
  200. return false;
  201. }
  202. $data = $r [' html '];
  203. $preg = Preg_match_all (' |

    ]+/> ([^<]+)

    |i ', $data, $temp _list);
  204. if ($preg = = 0) return array ();
  205. $list = Array_combine ($temp _list[1], $temp _list[2]);
  206. return $list;
  207. }
  208. /**
  209. * ERROR Display
  210. *
  211. * @param $str Array
  212. *
  213. * @return
  214. */
  215. Function error ($STR) {
  216. $str [' html '] = str_replace (' script ', ' ', $str [' html ']);
  217. Var_dump ($STR);
  218. Exit
  219. }
  220. }
  221. ?>

Copy Code

>>> more PHP Demo login articles, featured links: PHP Emulation login PHP Curl Demo Login Tutorial Daquan

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.