/**
- * @ File class. qqhttp. php
- * QQ mail login and retrieval class
- * @ Author wc
- * @ Site bbs.it-home.org
- */
Class QQHttp {
-
- Var $ cookie = '';
-
- Function _ cunstrut (){
- }
-
- Function makeForm (){
- $ Form = array (
- 'URL' => "http://mail.qq.com/cgi-bin/loginpage ",
- );
- $ Data = $ this-> curlFunc ($ form );
- Preg_match ('/name = "ts" \ svalue = "(\ d +)"/', $ data ['html'], $ tspre );
- $ Ts = $ tspre [1];
- Preg_match ('/action = "http: \// (m \ d + )\. mail \. qq \. com/', $ data ['HTML'], $ server );
- $ Server_no = $ server [1];
-
- /* Login.html loading */
- $ Html = file_get_contents (dirname (_ FILE _). '/login.htm ');
- $ Html = str_replace ('{_ ts _}', $ ts, $ html );
- $ Html = str_replace ('{_ server_no _}', $ server_no, $ html );
- Return $ html;
- }
-
- Function curlFunc ($ array)
- {
- $ Ch = curl_init ();
- Curl_setopt ($ ch, CURLOPT_URL, $ array ['URL']);
- Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
- If (isset ($ array ['header']) & $ array ['header']) {
- Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
- }
- If (isset ($ array ['httphupload']) {
- Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ array ['httpheader ']);
- }
- If (isset ($ array ['referer']) {
- Curl_setopt ($ ch, CURLOPT_REFERER, $ array ['referer']);
- }
- If (isset ($ array ['post']) {
- Curl_setopt ($ ch, CURLOPT_POST, 1 );
- Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ array ['post']);
- }
- If (isset ($ array ['cooker']) {
- Curl_setopt ($ ch, CURLOPT_COOKIE, $ array ['cookies']);
- }
- $ R ['erro '] = curl_error ($ ch );
- $ R ['errno'] = curl_errno ($ ch );
- $ R ['HTML '] = curl_exec ($ ch );
- $ R ['http _ Code'] = curl_getinfo ($ ch, CURLINFO_HTTP_CODE );
- Curl_close ($ ch );
- Return $ r;
- }
-
- /**
- * Obtain the verification code Image and cookie
- * @ Param Null
- *
- * @ Return array ('IMG '=> String, 'cooki' => String)
- */
- Function getVFCode ()
- {
- $ Vfcode = array (
- 'Header' => true,
- 'Cookies' => false,
- 'URL' => 'http: // ptlogin2.qq.com/getimage? Aid = '. $ _ GET ['aid']. '&'. @ $ _ GET ['t'],
- );
-
- $ R = $ this-> curlFunc ($ vfcode );
- If ($ r ['http _ Code']! = 200) return false;
- $ Data = split ("\ n", $ r ['HTML ']);
- Preg_match ('/verifysession = ([^;] +);/', $ data [5], $ temp );
- $ Cookie = trim ($ temp [1]);
- $ Img = $ data [9];
- Return array ('IMG '=> $ img, 'cooki' => $ cookie );
- }
-
- /**
- * Log on to the QQ mailbox
- *
- * @ Param $ cookie the cookie generated in getvfcode
- *
- * @ Return array (
- * Sid => String, // unique User Authentication Identifier
- * Login => Boolean, // true: login succeeded. false: login failed.
- * Server_no => String // server ID
- * Active => Boolean // true is enabled, and false is disabled.
- * Cookie => String // get data cookie
- *
- *);
- */
- Function login ($ cookie)
- {
- /* Generate the parameter string */
- $ Post = array ();
- Foreach ($ _ POST as $ k => $ v ){
- $ Post [] = $ k. '='. urlencode ($ v );
- }
- $ Poststr = implode ('&', $ post );
- $ R ['server _ no'] = $ _ GET ['server _ no'];
-
- $ Login = array (
- 'URL' => 'http: // '. $ r ['server _ no'].' .mail.qq.com/cgi-bin/login? Sid = 0, 2, zh_CN ',
- 'Header' => true,
- 'Cookies' => 'verifysession = '. $ cookie,
- 'Referer' => 'http: // mail.qq.com/cgi-bin/loginpage ',
- 'Httphupload' => array (
- "Host:". $ r ['server _ no']. '.mail.qq.com ',
- "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 ",
- "Content-Type: application/x-www-form-urlencoded ",
- ),
- 'Post' => $ poststr,
- );
- $ Data = $ this-> curlFunc ($ login );
- $ Data ['HTML '] = iconv ("gb2312", "UTF-8", $ data ['HTML']);
- If ($ data ['http _ Code']! = 200 ){
- $ This-> error ($ data );
- Return false;
- }
-
- /* Test data */
- // $ Data ['HTML '] = file_get_contents ('./r.txt ');
- $ R ['uin'] =_ _ POST ['uin'];
- /* Logon error judgment */
- If (preg_match ('| errtype = (\ d) |', $ data ['HTML '], $ temp_err )){
- $ R ['login'] = false;
- If ($ temp_err [1] = 1 ){
- $ R ['MSG '] = 'incorrect account and password ';
- } Elseif ($ temp_err [1] = 2 ){
- $ R ['MSG '] = 'verification code error ';
- }
- Return $ r;
- }
- /* Login successful */
- Preg_match ('| urlHead = "([^"] +) "| I', $ data ['html'], $ temp_url );
- $ Urlhead = $ temp_url [1];
- If (preg_match ('| frame_html \? Sid = ([^ "] +)" | I ', $ data ['HTML'], $ temp_sid )){
- $ R ['Sid '] = $ temp_sid [1];
- $ R ['active'] = true;
- } Elseif (preg_match ('| autoactivation \? Sid = ([^ &] + )? & | I ', $ data ['html'], $ temp_sid )){
- $ R ['Sid '] = $ temp_sid [1];
- $ R ['active'] = false;
- }
- /* Obtain the cookie after logon, which will be used in subsequent operations */
- If (preg_match_all ('| Set-Cookie :( [^ =] + = [^;] +) | I', $ data ['html'], $ new_cookies )){
- $ Cookiestr = implode (';', $ new_cookies [1]);
- $ Cookiestr. = '; verifysession ='. $ cookie;
- }
-
- $ R ['login'] = true;
- $ R ['cooker'] = $ cookiestr;
- Return $ r;
- } // Bbs.it-home.org
-
- Function openEmail ($ param)
- {
- $ OpenEmail = array (
- 'URL' => 'http: // '. $ param ['server _ no'].' .mail.qq.com/cgi-bin/autoactivation? Actmode = 6 & sid = '. $ param ['Sid'],
- 'Header' => true,
- 'Cookies' => $ param ['cookies'],
- 'Referer' => 'http: // '. $ param ['server _ no']. 'mail .qq.com/cgi-bin/autoactivation? Sid = '. $ param ['Sid']. '& action = reg_activate & actmode = 6 ',
- 'Httphupload' => array (
- "Host:". $ param ['server _ no']. '.mail.qq.com ',
- 'Accept-Charset: gb2312, UTF-8; q = 0.7, *; q = 100 ',
- "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 ",
- ),
- );
-
- $ Data = $ this-> curlFunc ($ openEmail );
- If (preg_match ('| Set-Cookie: qqmail_activated = 0 | I', $ data ['html']) {
- $ Param ['active'] = true;
- $ Param ['cookies'] = $ param ['cookies']. '; qqmail_activated = 0; qqmail_alias = ';
- }
- Return $ param;
- }
-
- /**
- *
- * Getting friends data
- *
- * @ Param $ param = array (
- * Sid => String, // unique User Authentication Identifier
- * Login => Boolean, // true: login succeeded. false: login failed.
- * Server_no => String // server ID
- * Active => Boolean // true is enabled, and false is disabled.
- * Cookie => String // get data cookie
- *
- *);
- * @ Return Array (
- * Key => value, // key: QQ number, value: nickname
- *);
- */
- Function getFriends ($ param)
- {
-
- $ Friend = array (
- 'URL' => 'http: // '. $ param ['server _ no'].' .mail.qq.com/cgi-bin/addr_listall? Type = user & category = all & sid = '. $ param ['Sid'],
- 'Header' => true,
- 'Cookies' => $ param ['cookies'],
- 'Referer' => 'http: // m151.mail.qq.com/cgi-bin/addr_listall? Sid = '. $ param ['Sid']. '& sorttype = null & category = common ',
- 'Httphupload' => array (
- "Host:". $ param ['server _ no']. '.mail.qq.com ',
- 'Accept-Charset: UTF-8; q = 0.7, *; q = 100 ',
- "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 ",
- ),
- );
- $ R = $ this-> curlFunc ($ friend );
- If ($ r ['http _ Code']! = 200 ){
- $ This-> error ($ r );
- Return false;
- }
- $ Data = $ r ['html'];
- $ Preg = preg_match_all ('|
] +/> ([^ <] +) | I ', $ data, $ temp_list );
- If ($ preg = 0) return array ();
- $ List = array_combine ($ temp_list [1], $ temp_list [2]);
- Return $ list;
- }
-
- /**
- * ERROR DISPLAY
- *
- * @ Param $ str array
- *
- * @ Return
- */
- Function error ($ str ){
- $ Str ['HTML '] = str_replace ('script', '', $ str ['HTML']);
- Var_dump ($ str );
- Exit;
- }
- }
- ?>
>>> More php simulated logon articles. topic links: php simulated logon php curl simulated logon tutorials |