PHP simulated logon to QQ mailbox to obtain the QQ friends list

Source: Internet
Author: User
Tags preg
PHP simulated logon to QQ mailbox to obtain the QQ friends list

  1. /**

  2. * @ File class. qqhttp. php
  3. * QQ mail login and retrieval 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 ['httphupload']) {
  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 ['cooker']) {
  45. Curl_setopt ($ ch, CURLOPT_COOKIE, $ array ['cookies']);
  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. * Obtain the verification code Image and cookie
  56. * @ Param Null
  57. *
  58. * @ Return array ('IMG '=> String, 'cooki' => String)
  59. */
  60. Function getVFCode ()
  61. {
  62. $ Vfcode = array (
  63. 'Header' => true,
  64. 'Cookies' => false,
  65. 'URL' => 'http: // ptlogin2.qq.com/getimage? Aid = '. $ _ GET ['aid']. '&'. @ $ _ GET ['t'],
  66. );
  67. $ R = $ this-> curlFunc ($ vfcode );
  68. If ($ r ['http _ Code']! = 200) 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, 'cooki' => $ cookie );
  74. }
  75. /**
  76. * Log on to the QQ mailbox
  77. *
  78. * @ Param $ cookie the cookie generated in getvfcode
  79. *
  80. * @ Return array (
  81. * Sid => String, // unique User Authentication Identifier
  82. * Login => Boolean, // true: login succeeded. false: login failed.
  83. * Server_no => String // server ID
  84. * Active => Boolean // true is enabled, and false is disabled.
  85. * Cookie => String // get data cookie
  86. *
  87. *);
  88. */
  89. Function login ($ cookie)
  90. {
  91. /* Generate the 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. 'Cookies' => 'verifysession = '. $ cookie,
  102. 'Referer' => 'http: // mail.qq.com/cgi-bin/loginpage ',
  103. 'Httphupload' => 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. /* Logon 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 '] = 'incorrect account and password ';
  124. } Elseif ($ temp_err [1] = 2 ){
  125. $ R ['MSG '] = 'verification code 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. /* Obtain the cookie after logon, which will be 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 ['cooker'] = $ 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. 'Cookies' => $ param ['cookies'],
  154. 'Referer' => 'http: // '. $ param ['server _ no']. 'mail .qq.com/cgi-bin/autoactivation? Sid = '. $ param ['Sid']. '& action = reg_activate & actmode = 6 ',
  155. 'Httphupload' => array (
  156. "Host:". $ param ['server _ no']. '.mail.qq.com ',
  157. 'Accept-Charset: gb2312, UTF-8; q = 0.7, *; q = 100 ',
  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 ['cookies'] = $ param ['cookies']. '; qqmail_activated = 0; qqmail_alias = ';
  165. }
  166. Return $ param;
  167. }
  168. /**
  169. *
  170. * Getting friends data
  171. *
  172. * @ Param $ param = array (
  173. * Sid => String, // unique User Authentication Identifier
  174. * Login => Boolean, // true: login succeeded. false: login failed.
  175. * Server_no => String // server ID
  176. * Active => Boolean // true is enabled, and false is disabled.
  177. * Cookie => String // get data cookie
  178. *
  179. *);
  180. * @ Return Array (
  181. * Key => value, // key: QQ number, 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. 'Cookies' => $ param ['cookies'],
  190. 'Referer' => 'http: // m151.mail.qq.com/cgi-bin/addr_listall? Sid = '. $ param ['Sid']. '& sorttype = null & category = common ',
  191. 'Httphupload' => array (
  192. "Host:". $ param ['server _ no']. '.mail.qq.com ',
  193. 'Accept-Charset: UTF-8; q = 0.7, *; q = 100 ',
  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. ?>

>>> More php simulated logon articles. topic links: php simulated logon php curl simulated logon tutorials

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.