您好,登錄后才能下訂單哦!
小編給大家分享一下PHP如何模擬登陸163郵箱發郵件及獲取通訊錄列表,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
具體實現方法如下:
<?php header("Content-Type: text/html; charset=UTF-8"); error_reporting(0); /** * 登陸 * $user 163用戶名 * $pass 密碼 **/ function login($user,$pass){ //登陸 $url = 'http://reg.163.com/logins.jsp?type=1&url=http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D-1'; $cookie = tempnam('./cache/','~');//創建一個用于存放cookie信息的臨時文件 $fields_post = array( 'username' => $user, 'password' => $pass, 'verifycookie' => 1, 'style' => -1, 'product' => 'mail163', 'selType' => -1, 'secure' => 'on' ); $fields_string = ''; foreach($fields_post as $key => $value){ $fields_string .= $key . '=' . $value . '&'; } $fields_string = rtrim($fields_string , '&'); $headers = array( 'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0', 'Referer' => 'http://www.163.com' ); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//返回結果存放在變量中,而不是默認的直接輸出 curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);//關閉連接時,將服務器端返回的cookie保存在以下文件中 curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); $result= curl_exec($ch); curl_close($ch); preg_match_all('/<div class="info" id="eHint">(.*?) <\/div>/i', $result,$infos,PREG_SET_ORDER); if(!empty($infos['0']['1'])){ unlink($cookie); exit('<script type="text/javascript">alert("'.$infos['0']['1'].'");history.go(-1);</script>'); }else{ $G_ROOT = dirname(__FILE__); file_put_contents($G_ROOT.'/cache/cookie', $cookie); return $cookie; } } /** * * $data['url'] 請求地址 * $data['data_post'] post數據 * $data['cookie'] * **/ function curl($data){ $url = $data['url']; $data_post= $data['data_post']? $data['data_post']: false; $cookie = $data['cookie']; $headers = array( 'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0', 'Referer' => 'http://www.163.com' ); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); //cookie文件 登陸之后 //POST 提交 if($data_post){ curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_post); } $result = curl_exec($ch); curl_close($ch); return $result; }
以上是“PHP如何模擬登陸163郵箱發郵件及獲取通訊錄列表”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。