您好,登錄后才能下訂單哦!
這篇文章主要介紹“php模擬郵箱登錄功能介紹”,在日常操作中,相信很多人在php模擬郵箱登錄功能介紹問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”php模擬郵箱登錄功能介紹”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
最近一直在忙,趕在這個假期結束的時候,發表一下此文,為了是讓這些源碼開源出來
當然這些方法可能不可取,但大致應該是這種方向了吧,由于目前做的一個UCHOME港臺的站點
咱們策劃說要改一下好友邀請里面的顯示方式,開始我也沒有在意,當時就說行!
到了弄這個的時候才發現,UCH里面的這個地方是用漫游型式做的,讓人很是無解,啥都改不了!
唉,既然都答應了說可以,現在實際情況不行了,所以覺得不好意思,為了快速解決這問題,在GOOGLE,
百度上搜了個遍,結果又出忽意料,就一個126郵箱的開源例子,其它的都沒有,有一牛哥留著QQ說要其它的源碼,
可以加QQ買!不對此人評論了!俺花了點時間,整了整,結果就幸運的弄出來了幾個,因為時間有限,目前手上的項目一直在弄,所以就沒有管其它的,現在給出 GMAIL,HOTMAIL(MSN),YAHOO的郵箱聯系人的PHP源代碼:
1.GMAIL
復制代碼 代碼如下:
<?php
define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) ); //定義COOKIES存放的路徑,要有操作的權限
define( "TIMEOUT", 1000 ); //超時設定
class GMAIL
{
private function login($username, $password)
{
//第一步:模擬抓取登錄頁面的數據,并記下cookies
$cookies = array();
$matches = array();
//獲取表單
$login_url = "https://www.google.com/accounts/ServiceLoginAuth";
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
//模擬參數
$name = array('dsh','timeStmp','secTok');
foreach($name as $v) {
preg_match('/<input/s*type="hidden"/s*name="'.$v.'"/s*id="'.$v.'"/s*value="(.*?)"/s*//>/i', $contents, $matches);
if(!empty($matches)) {
$$v = $matches[1];
$matches = array();
}
}
$server = 'mail';
preg_match('/<input/s*type="hidden"/s*name="GALX"/s*value="(.*?)"/s*//>/i', $contents, $matches);
if(!empty($matches)) {
$GALX = $matches[1];
$matches = array();
}
$timeStmp = time();
//第二步: 開始登錄
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ServiceLoginAuth");
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
curl_setopt($ch, CURLOPT_POST, 1);
$fileds = "dsh=$dsh&Email=".$username."&Passwd={$password}&GALX=$GALX&timeStmp=$timeStmp&secTok=$secTok&signIn=Sign in&rmShown=1&asts=&PersistentCookie=yes";
curl_setopt($ch, CURLOPT_POSTFIELDS, $fileds);
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);
//第三步:check Cookies即也算是個引導頁面
$ch = curl_init("https://www.google.com/accounts/CheckCookie?chtml=LoginDoneHtml");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_COOKIEFILE,COOKIEJAR);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
$str2 = curl_exec($ch);
curl_close($ch);
if (strpos($contents, "安全退出") !== false)
{
return FALSE;
}
return TURE;
}
//獲取郵箱通訊錄-地址
public function getAddressList($username, $password)
{
if (!$this->login($username, $password))
{
return FALSE;
}
//開始進入模擬抓取
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://mail.google.com/mail/contacts/data/contacts?thumb=true&groups=true&show=ALL&enums=true&psort=Name&max=300&out=js&rf=&jsx=true"); //out=js返回json數據,不設置返回為xml數據
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
/* 對于返回xml數據時需要此設置
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/xml"));
$str = "<?xml version=/"1.0/"?><object><array name=/"items/"><object><string name=/"func/">pab:searchContacts</string><object name=/"var/"><array name=/"order/"><object><string name=/"field/">FN</string><boolean name=/"ignoreCase/">true</boolean></object></array></object></object><object><string name=/"func/">user:getSignatures</string></object><object><string name=/"func/">pab:getAllGroups</string></object></array></object>";
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
*/
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
$contents = curl_exec($ch);
curl_close($ch);
//die($contents);
//get mail list from the page information username && emailaddress
/* 對于返回xml數據時的處理
preg_match_all("/<string/s*name=/"EMAILREF/">(.*)<//string>/Umsi",$contents,$mails);
preg_match_all("/<string/s*name=/"FN/">(.*)<//string>/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 '您的郵箱中尚未有聯系人';
}
*/
$contents = substr($contents, strlen('while (true); &&&START&&&'), -strlen('&&&END&&& '));
return $contents;
}
}
$gamil = new GMAIL;
$res = $gamil->getAddressList('username@163.com','123456');
echo $res;
?>
<mce:script type="text/javascript"><!--
var data = <?php echo $res; ?>
alert(data['Body']); //json數據
// --></mce:script>
2.HOTMAIL(MSN)
復制代碼 代碼如下:
<?php
define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) ); //定義COOKIES存放的路徑,要有操作的權限
define( "TIMEOUT", 1000 ); //超時設定
class MSN
{
function getAddressList($username, $password)
{
//第一步:模擬抓取登錄頁面的數據,并記下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.0.5285.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=2052&id=64855&mkt=en");
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);
//參數的分析
$matches = array();
preg_match('/<input/s*type="hidden"/s*name="PPFT"/s*id="(.*?)"/s*value="(.*?)"/s*//>/i', $str, $matches);
$PPFT = $matches[2];
preg_match('/srf_sRBlob=/'(.*?)/';/i', $str, $matches);
$PPSX = $matches[1];
$type = 11;
$LoginOptions = 3;
$Newuser = 1;
$idsbho = 1;
$i2 = 1;
$i12 = 1;
$i3 = '562390';
$PPSX = 'Pa';
//合并參數
$postfiles = "login=".$username."&passwd=".$password."&type=".$type."&LoginOptions=".$LoginOptions."&Newuser=".$Newuser."&idsbho=".$idsbho."&i2=".$i2."&i3=".$i3."&PPFT=".$PPFT."&PPSX=".$PPSX."&i12=1";
//第二步:開始登錄
$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.0.5285.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=2052&id=64855&mkt=en&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登錄頁面JS
return false; //登錄失敗
}
//獲取location鏈接
$matches = array();
preg_match('/window.location.replace/(/"(.*?)/"/)/i', $content, $matches);
$url_contiune_1 = $matches[1]; //接下來的鏈接
if(!$url_contiune_1) {
return false;
}
//第三步: 進入引導頁面
$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;
}
//跳過進入首頁
/*
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
curl_setopt($ch, CURLOPT_URL, $url_contiune_2);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1000);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$content_3 = curl_exec($ch);
curl_close($ch);
*/
//獲取郵箱請求基址 讀取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后面的數字是隨機數
if(!$url_contiune_3) {
return false;
}
//第四步: 開始獲取郵箱聯系人
//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);
//分析數據 (此處的數據因為hotmail的JS處理機制,所以在頁面上看不出來,源碼上可以看到數據)
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();
}
}
}
$msn = new MSN;
$res = $msn->getAddressList('username@111.com','123456');
echo $res;
?>
<mce:script type="text/javascript"><!--
var data = <?php echo $res; ?>
alert(data['ic1'][6]);
alert(data['ic1'][3]);
// --></mce:script>
3.YAHOO
復制代碼 代碼如下:
<?php
define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) ); //定義COOKIES存放的路徑,要有操作的權限
define( "TIMEOUT", 1000 ); //超時設定
class YAHOO
{
private function login($username, $password)
{
//第一步:模擬抓取登錄頁面的數據,并記下cookies
$cookies = array();
$matches = array();
//獲取表單
$login_url = "https://login.yahoo.com/config/login?.src=fpctx&.intl=us&.done=http%3A%2F%2Fwww.yahoo.com%2F";
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
//構造參數
$name = array('tries','src','md5','hash','js','last','promo','intl','bypass','partner','u','v','challenge','yplus','emailCode','pkg','stepid','ev','hasMsgr','chkP','done','pd','pad','aad');
$postfiles = array();
$matches = array();
foreach($name as $v) {
preg_match('/<input/s*type="hidden"/s*name=".'.$v.'"/s*value="(.*?)"/s*>/i', $contents, $matches);
if(!empty($matches)) {
$postfiles['.'.$v] = $matches[1];
$matches = array();
}
if($v == 'pd') {
$postfiles['.'.$v] = urlencode($postfiles['.'.$v]);
}
}
$postfiles['pad'] = 5;
$postfiles['aad'] = 6;
$postfiles['login'] = urlencode($username);
$postfiles['passwd'] = $password;
$postfiles['.persistent'] = 'y';
$postfiles['save'] = '';
$postfiles['.done'] = urlencode($postfiles['.done']);
//$postfiles['.pd'] = urlencode($postfiles['.pd']);
$postargs = '';
foreach($postfiles as $k => $v){
$postargs .= $k.'='.$v.'&';
}
$postargs = substr($postargs,0,-1);
$request = "https://login.yahoo.com/config/login?";
//開始登錄
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $request);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($ch);
curl_close($ch);
if (stripos($contents,'submit') != FALSE)
{
return 0;
}
return 1;
}
//獲取郵箱通訊錄-地址
public function getAddressList($username, $password)
{
if (!$this->login($username, $password))
{
return 0;
}
//開始進入模擬抓取
//get mail list from the page information username && emailaddress
$url = "http://address.mail.yahoo.com/";
$data = array( );
if ( !$data = $this->hanlde_date( $url, $names, $emails) )
{
return FALSE;
}
echo '<pre>';
print_r($data);
return $data;
}
function hanlde_date( $url, &$names, &$emails)
{
$ch = curl_init( );
curl_setopt( $ch, CURLOPT_COOKIEFILE, COOKIEJAR );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($ch);
curl_close($ch);
$temparr = array();
preg_match_all('/InitialContacts/s*=/s*(.*?);/i',$contents,$temparr);
return $temparr[1][0].';'; //匹配出JSON對象數組
}
}
$yahoo = new YAHOO;
$res = $yahoo->getAddressList('username@yahoo.com.cn','123456');
?>
<mce:script type="text/javascript"><!--
var data = <?php echo $res; ?>
var obj1 = data[0];
alert(data[0]['contactName']);
// --></mce:script>
到此,關于“php模擬郵箱登錄功能介紹”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。