Home Backend Development PHP Tutorial How to simulate logging into QQ mailbox with PHP to obtain QQ friend list

How to simulate logging into QQ mailbox with PHP to obtain QQ friend list

Jul 25, 2016 am 08:53 AM

  1. /**

  2. * @file class.qqhttp.php
  3. * QQ mailbox login acquisition 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://(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. 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 image and cookie
  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'] != 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,'cookie'=>$cookie);
  74. }
  75. /**
  76. * Log in to qq mailbox
  77. *
  78. * @param $cookie The cookie generated in getvfcode
  79. *
  80. * @return array(
  81. * sid=>String, //The unique identifier of user authentication
  82. * login => Boolean, / /true if the login is successful, false if the login is failed
  83. * server_no => String // Server number
  84. * active => Boolean //true has been activated, false if the mailbox has not been activated
  85. * cookie => String // Get data cookie
  86. *
  87. * );
  88. */
  89. function login($cookie)
  90. {
  91. /* 生成参数字符串 */
  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. /* 测试数据 */
  117. //$data['html'] =file_get_contents('./r.txt');
  118. $r['uin'] = $_POST['uin'];
  119. /* 登陆错误的判断 */
  120. if (preg_match('|errtype=(d)|', $data['html'], $temp_err)) {
  121. $r['login'] = false;
  122. if ($temp_err[1] == 1) {
  123. $r['msg'] = '账号和密码错误';
  124. } elseif ($temp_err[1] == 2) {
  125. $r['msg'] = '验证码错误';
  126. }
  127. return $r;
  128. }
  129. /* 登陆成功 */
  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. /* 登录后cookie的获取 ,在后续操作中用到 */
  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 , //The unique identifier of user authentication
  174. * login => Boolean, //true if the login is successful, false if the login fails
  175. * server_no => String // Server number
  176. * active => Boolean //true has been opened, false the mailbox has not been opened
  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. '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. ?>

复制代码

>>> 更多 php模拟登录 文章,专题链接:php模拟登录 php curl模拟登录教程大全



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

What are Enumerations (Enums) in PHP 8.1? What are Enumerations (Enums) in PHP 8.1? Apr 03, 2025 am 12:05 AM

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What is REST API design principles? What is REST API design principles? Apr 04, 2025 am 12:01 AM

RESTAPI design principles include resource definition, URI design, HTTP method usage, status code usage, version control, and HATEOAS. 1. Resources should be represented by nouns and maintained at a hierarchy. 2. HTTP methods should conform to their semantics, such as GET is used to obtain resources. 3. The status code should be used correctly, such as 404 means that the resource does not exist. 4. Version control can be implemented through URI or header. 5. HATEOAS boots client operations through links in response.

How do you handle exceptions effectively in PHP (try, catch, finally, throw)? How do you handle exceptions effectively in PHP (try, catch, finally, throw)? Apr 05, 2025 am 12:03 AM

In PHP, exception handling is achieved through the try, catch, finally, and throw keywords. 1) The try block surrounds the code that may throw exceptions; 2) The catch block handles exceptions; 3) Finally block ensures that the code is always executed; 4) throw is used to manually throw exceptions. These mechanisms help improve the robustness and maintainability of your code.

What are anonymous classes in PHP and when might you use them? What are anonymous classes in PHP and when might you use them? Apr 04, 2025 am 12:02 AM

The main function of anonymous classes in PHP is to create one-time objects. 1. Anonymous classes allow classes without names to be directly defined in the code, which is suitable for temporary requirements. 2. They can inherit classes or implement interfaces to increase flexibility. 3. Pay attention to performance and code readability when using it, and avoid repeatedly defining the same anonymous classes.

See all articles