|
<? Php
// =============================== Account information ==========================
// User name
$ UserName = 'xxxxxxxx ';
// Password
$ Password = 'xxxxxxxx ';
// Email
$ Email = $ userName. '@ 163.com ';
// ========================================================
// Logon address (the logon address is not the address set in the form. You have modified the form action attribute through js. You need to check the source code on the logon page to find the logon address)
$ LoginUrl = "https://ssl.mail.163.com/entry/coremail/fcg/ntesdoor2? Df = mail163_letter & from = web & funcid = loginone & iframe = 1 & language =-1 & passtype = 1 & product = mail163 & net = n & style =-1 & race = -2_56_-2 _ hz & uid = {$ email }";
// Post data sent during login (view form, note that there are hidden fields)
$ PostArray = array (
"Url2" => "http://mail.163.com/errorpage/error163.htm ",
"Savelogin" => 0, "username" => trim ($ userName), "password" => $ password,
);
$ PostString = '';
Foreach ($ postArray as $ key => $ value ){
$ PostString. = "{$ key} = {$ value }&";
}
$ PostString = trim ($ postString ,'&');
// Initialize the CURL object
$ Curl = curl_init ();
// Set the request address
Curl_setopt ($ curl, CURLOPT_URL, $ loginUrl );
// After being disabled, the CURL will be terminated from the server for verification.
Curl_setopt ($ curl, CURLOPT_SSL_VERIFYPEER, FALSE );
// When enabled, the obtained information is returned in the form of a file stream, rather than being output directly.
Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, TRUE );
// When enabled, the header file information is output as a data stream.
Curl_setopt ($ curl, CURLOPT_HEADER, TRUE );
// Set the POST parameter
Curl_setopt ($ curl, CURLOPT_POST, TRUE );
Curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ postString );
// Execute the specified CURL session
// Returns TRUE if the call succeeds, and FALSE if the call fails.
// However, if the CURLOPT_RETURNTRANSFER option is set, the execution result is returned when the function is successfully executed, and FALSE if the function fails.
$ Html = curl_exec ($ curl );
// Write the obtained data to a file for viewing
// File_put_contents('temp1.txt ', $ html );
// Split the header file and content
List ($ head, $ content) = explode ("\ r \ n", $ html, 2 );
// Write the obtained data to a file for viewing
// File_put_contents('temp2.txt ', $ head );
// File_put_contents('temp3.txt ', $ content );
$ Head = explode ("\ r \ n", $ head );
// Obtain cookie information
$ CookieString = '';
Foreach ($ head as $ value ){
If (stripos ($ value, "Set-Cookie :")! = False ){
$ CookieString. = str_replace ("Set-Cookie:", "", $ value );
}
}
// Analyze the sid value from the content (read the parameters of address book information)
$ StartString = 'Top. location. href = "';
$ EndString = '"; </script> ';
$ Start = strpos ($ content, $ startString );
$ End = strpos ($ content, $ endString );
$ TempUrl = substr ($ content, $ start + strlen ($ startString), $ end-$ start-strlen ($ startString ));
$ TempUrlVals = parse_url ($ tempUrl );
Parse_str ($ tempUrlVals ['query'], $ queryVals );
$ Sid = $ queryVals ['Sid '];
// ============================== Read email ==============================
// Read the email address
$ ReadUrl = "http://twebmail.mail.163.com/contacts/call.do? Uid = {$ email} & sid = {$ sid} & from = webmail & cmd = newapi. getContacts & vcardver = 3.0 & ctype = all & attachinfos = yellowpage ";
// Set the request address
Curl_setopt ($ curl, CURLOPT_URL, $ readUrl );
// Set the POST parameter
Curl_setopt ($ curl, CURLOPT_POST, TRUE );
Curl_setopt ($ curl, CURLOPT_POSTFIELDS, 'Order = [{"field": "N", "desc": "false"}] ');
// Set the cookie obtained from the logon operation.
Curl_setopt ($ curl, CURLOPT_COOKIE, $ cookieString );
// Disable header file output
Curl_setopt ($ curl, CURLOPT_HEADER, FALSE );
// Execute the specified CURL session
// Returns TRUE if the call succeeds, and FALSE if the call fails.
// However, if the CURLOPT_RETURNTRANSFER option is set, the execution result is returned when the function is successfully executed, and FALSE if the function fails.
$ Content = curl_exec ($ curl );
// Write the obtained data to a file for viewing
// File_put_contents('temp4.txt ', $ content );
// Close a CURL session and release resources
Curl_close ($ curl );
Echo '<pre> ';
Print_r (json_decode ($ content, true ));
Echo '</pre> '; |