Ec (2); & lt ;? Php *** @ fileclass.126http. php * Get 126 mail address book list * @ authorjvones & lt; jvones@gmail.com & gt; www. jvones. comblog * @ date2009-09-26 ** & nbsp; "script" ec (2); "script"
-
- /**
- * @ File class.126http. php
- * Obtain the 126 email address book list
- * @ Author jvones Http://www.jvones.com/blog
- * @ Date 2009-09-26
- **/
-
- Class http126
- {
-
- Private function login ($ username, $ password)
- {
- // Step 1: initial login
- $ Cookies = array ();
- $ Ch = curl_init ();
- Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false );
-
- Curl_setopt ($ ch, CURLOPT_URL, "https://reg.163.com/logins.jsp? Type = 1 & product = mail126 & url = http://entry.mail.126.com/cgi/ntesdoor? Hid % 3D10010102% 26 lightweight % 3D1% 26 verifycookie % 3D1% 26 language % 3D0% 26 style % 3D-1 ");
- Curl_setopt ($ ch, CURLOPT_POST, 1 );
- Curl_setopt ($ ch, CURLOPT_POSTFIELDS, "username =". $ username. "@ 126.com& password =". $ password );
-
- Curl_setopt ($ ch, CURLOPT_COOKIEJAR, COOKIEJAR );
- Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
- Curl_setopt ($ ch, CURLOPT_TIMEOUT, TIMEOUT );
- Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
- $ Str = curl_exec ($ ch );
- // File_put_contents ('./126result.txt', $ str );
- Curl_close ($ ch );
-
- // Obtain the redirect_url.pdf address, which can be viewed from 126result.txt and matched in the $ str returned stream using the regular expression.
- Preg_match ("/replace ("(.*?) ");/", $ Str, $ mtitle );
- $ _ Url1 = $ mtitle [1];
-
- // File_put_contents ('./126resulturl.txt', $ redirect_url );
- // Step 2: Jump to $ _ url1
- $ Ch = curl_init ($ _ url1 );
-
- Curl_setopt ($ ch, CURLOPT_TIMEOUT, TIMEOUT );
- Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
- Curl_setopt ($ ch, CURLOPT_COOKIEFILE, COOKIEJAR );
- Curl_setopt ($ ch, CURLOPT_COOKIEJAR, COOKIEJAR );
- Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
- $ Str2 = curl_exec ($ ch );
- Curl_close ($ ch );
-
- If (strpos ($ contents, "exit safely ")! = False)
- {
- Return 0;
- }
- Return 1;
- }
-
- /**
- * Get the email address book-address
- * @ Param $ user
- * @ Param $ password
- * @ Param $ result
- * @ Return array
- */
- Public function getAddressList ($ username, $ password)
- {
- If (! $ This-> login ($ username, $ password ))
- {
- Return 0;
- }
-
- $ Header = $ this-> _ getheader ($ username );
- If (! $ Header ['sid '])
- {
- Return 0;
- }
-
- // Locate the sid (important) and host in the test
- // File_put_contents ('./host.txt', $ header ['host']);
- // File_put_contents ('./sid.txt', $ header ['sid ']);
-
- // Start to enter the simulated capture
- $ Ch = curl_init ();
- Curl_setopt ($ ch, CURLOPT_URL, "http: //". $ header ['host']. "/a/s? Sid = ". $ header ['sid ']." & func = global: sequential ");
- Curl_setopt ($ ch, CURLOPT_COOKIEFILE, COOKIEJAR );
- Curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ("Content-Type: application/xml "));
- $ Str =" Pab: searchContacts FN True User: getSignatures Pab: getAllGroups ";
- Curl_setopt ($ ch, CURLOPT_POST, 1 );
- Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ str );
- Curl_setopt ($ ch, CURLOPT_TIMEOUT, TIMEOUT );
- Ob_start ();
- Curl_exec ($ ch );
- $ Contents = ob_get_contents ();
-
- Ob_end_clean ();
- Curl_close ($ ch );
-
- // Get mail list from the page information username & emailaddress
- Preg_match_all ("/ (.*)/Umsi ", $ contents, $ mails );
- Preg_match_all ("/ (.*)/Umsi ", $ contents, $ names );
- $ Users = array ();
- Foreach ($ names [1] as $ k => $ user)
- {
- // $ User = iconv ($ user, 'utf-8', 'gb2312 ');
- $ Users [$ mails [1] [$ k] = $ user;
- }
- If (! $ Users)
- {
- Return 'no contacts in your mailbox ';
- }
-
- Return $ users;
- }
-
- /**
- * Get Header info
- */
- Private function _ getheader ($ username)
- {
- $ Ch = curl_init ();
- Curl_setopt ($ ch, CURLOPT_URL, "http://entry.mail.126.com/cgi/ntesdoor? Hid = 10010102 & lightweight = 1 & verifycookie = 1 & language = 0 & style =-1 & username = ". $ username." @ 126.com ");
- Curl_setopt ($ ch, CURLOPT_COOKIEFILE, COOKIEJAR); // The cookie currently in use
- Curl_setopt ($ ch, CURLOPT_COOKIEJAR, COOKIEJAR); // The new cookie returned by the server
- Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
- Curl_setopt ($ ch, CURLOPT_HEADER, true );
- Curl_setopt ($ ch, CURLOPT_NOBODY, true );
- $ Content = curl_exec ($ ch );
-
- Preg_match_all ('/Location: s *(.*?) Rn/I ', $ content, $ regs );
- $ Refer = $ regs [1] [0];
- Preg_match_all ('/http ://(.*?) // I ', $ refer, $ regs );
- $ Host = $ regs [1] [0];
- Preg_match_all ("/sid = (. *)/I", $ refer, $ regs );
- $ Sid = $ regs [1] [0];
-
- Curl_close ($ ch );
- Return array ('sid '=> $ sid, 'Referer' => $ refer, 'host' => $ host );
- }
- }
-
- ?>