search
HomeBackend DevelopmentPHP TutorialHow to simulate logging into QQ mailbox with PHP to obtain QQ friend list

  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('|

    How to simulate logging into QQ mailbox with PHP to obtain QQ friend list]+/> ([^

    |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
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

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

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)