php curl 获取 邮箱通讯录 sns(hotmail)
生活随笔
收集整理的這篇文章主要介紹了
php curl 获取 邮箱通讯录 sns(hotmail)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
<?phpdefine("COOKIEJAR", tempnam(ini_get("upload_tmp_dir"), "cookie")); //定義COOKIES存放的路徑,要有操作的權限
define("TIMEOUT", 10000); //超時設定
error_reporting(E_ALL);$msn = new mail_msn();
$res = $msn->getAddressList('email@hotmail.com', 'password');$data = json_decode($res, true);
unset($data['ic1']); //自己的
foreach ($data as $key => $val) {if (!strstr($key, 'Template')) {$list['username'] = $val['3'];$list['email'] = $val['6'];$lists[] = $list;}
}var_dump($lists);class mail_msn {function getAddressList($username, $password) {//第一步:模擬抓取登入頁面的數(shù)據(jù),并記下cookies$cookies = array();$ch = curl_init();curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_URL, "http://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=" . time() . "&rver=6.1.6206.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=2052&id=64855&mkt=zh-cn&cbcxt=mail&snsc=1");curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$str = curl_exec($ch);curl_close($ch);//數(shù)據(jù)文件 模擬JS生成的cookie$CkTst = 'G' . time() * 1000;$wlidperf = "throughput=3&latency=948&FR=L&ST=" . (time() * 1000 + 1254);$fp = fopen(COOKIEJAR, "a+");$str_new = "login.live.com\tTRUE\t/\tFALSE\t0\tCkTst\t$CkTst\r\n";$str_new .= "login.live.com\tTRUE\t/\tFALSE\t0\twlidperf\t$wlidperf\r\n";fwrite($fp, $str_new);fclose($fp);//參數(shù)的分析$matches = array();preg_match('/<input\s*type="hidden"\s*name="PPFT"\s*id="(.*?)"\s*value="(.*?)"\s*\/>/i', $str, $matches);$PPFT = $matches[2];$type = 11;$LoginOptions = 3;$Newuser = 1;$idsbho = 1;$i2 = 1;$i12 = 1;$i3 = '562390';$i14 = '868';$i15 = '1338';$PPSX = 'Pa';//合并參數(shù)$postfiles = "login=" . $username . "&passwd=" . $password . "&type=" . $type . "&LoginOptions=" . $LoginOptions . "&Newuser=" . $Newuser . "&idsbho=" . $idsbho . "&i2=" . $i2 . "&i3=" . $i3 . "&PPFT=" . $PPFT . "&PPSX=" . $PPSX . "&i12=1&i14=$i14&i15=$i15";//第二步:開始登入$ch = curl_init();curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);curl_setopt($ch, CURLOPT_URL, 'https://login.live.com/ppsecure/post.srf?wa=wsignin1.0&rpsnv=11&ct=' . (time() + 5) . '&rver=6.1.6206.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=2052&id=64855&mkt=zh-cn&cbcxt=mail&snsc=1&bk=' . (time() + 715)); //此處的兩個time()是為了模擬隨機的時間curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $postfiles);curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);curl_setopt($ch, CURLOPT_HEADER, 1);curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$content = curl_exec($ch);curl_close($ch);if (stripos($content, 'WLWorkflow') !== FALSE) { //WLWorkflow登入頁面JSreturn false; //登入失敗}//獲取location鏈接$matches = array();preg_match('/window.location.replace\(\"(.*?)\"\)/i', $content, $matches);$url_contiune_1 = $matches[1]; //接下來的鏈接if (!$url_contiune_1) {return false;}//除去多余的COOKIE$arr_new = file(COOKIEJAR);$str_new = '';$need_arr = array(0, 1, 2, 3, 7, 9, 13, 15, 16, 17, 18, 21, 22);foreach ($arr_new as $k => $v) {if (in_array($k, $need_arr))$str_new .= "$v";}$fp = fopen(COOKIEJAR, "w+");fwrite($fp, $str_new);fclose($fp);//第三步: 進入引導頁面$ch = curl_init();curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);curl_setopt($ch, CURLOPT_URL, $url_contiune_1);curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);curl_setopt($ch, CURLOPT_HEADER, 1);curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$content_2 = curl_exec($ch);//echo $postfiles;curl_close($ch);//獲取redicturl鏈接$matches = array();preg_match('/<a\s*href=\"(.*?)\"\s*>/i', $content_2, $matches);$url_contiune_2 = $matches[1]; //接下來的鏈接if (!$url_contiune_2) {return false;}//獲取郵箱請求基址 讀取host$matches = array();preg_match('/(.*?)\/\/(.*?)\/(.*?)/i', $url_contiune_2, $matches);$url_contiune_3 = trim($matches[1]) . '//' . trim($matches[2]); //首頁定義的站點基址$url_4 = $url_contiune_3 . '/mail/ContactMainLight.aspx?n=435707983'; //n后面的數(shù)字是隨機數(shù)if (!$url_contiune_3) {return false;}//第四步: 開始獲取郵箱聯(lián)系人//base $url_4$ch = curl_init();curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);curl_setopt($ch, CURLOPT_URL, $url_4);curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$str = curl_exec($ch);curl_close($ch);//分析數(shù)據(jù) (此處的數(shù)據(jù)因為hotmail的JS處理機制,所以在頁面上看不出來,源碼上可以看到數(shù)據(jù))return $this->hanlde_date($str);}function hanlde_date($data) {$new_str = array();if (!empty($data)) {$ops_start = stripos($data, 'ic_control_data');$ops_end = stripos($data, ';', $ops_start);$new_str = substr($data, $ops_start + strlen('ic_control_data = '), $ops_end - $ops_start - strlen('ic_control_data = '));return $new_str; //返回JSON對象} else {return array();}}}?>
?2012年3月24 經測試可使用
轉載于:https://www.cnblogs.com/ybbqg/archive/2012/03/24/2415708.html
總結
以上是生活随笔為你收集整理的php curl 获取 邮箱通讯录 sns(hotmail)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nand Flash VS Nor Fl
- 下一篇: DotNetNuke的升级路径