php 模拟GMAIL,HOTMAIL(MSN),YAHOO,163,126邮箱登录的详细介绍
程序员文章站
2023-10-13 17:14:29
最近一直在忙,赶在这个假期结束的时候,发表一下此文,为了是让这些源码开源出来当然这些方法可能不可取,但大致应该是这种方向了吧,由于目前做的一个uchome港台的站点咱们策划...
最近一直在忙,赶在这个假期结束的时候,发表一下此文,为了是让这些源码开源出来
当然这些方法可能不可取,但大致应该是这种方向了吧,由于目前做的一个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×tmp=$timestmp§ok=$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>
注:
163,126在网上的源码都有,在此就不一一的列出来了哦
当然此代码是自己个人的拙作,只是为了给大家此类问题做一个指引
当然这些方法可能不可取,但大致应该是这种方向了吧,由于目前做的一个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×tmp=$timestmp§ok=$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>
注:
163,126在网上的源码都有,在此就不一一的列出来了哦
当然此代码是自己个人的拙作,只是为了给大家此类问题做一个指引
上一篇: 走心甜点!GTX 1660 Ti定价曝光:游戏性能超GTX 1070
下一篇: 本人南方人
推荐阅读
-
php 模拟GMAIL,HOTMAIL(MSN),YAHOO,163,126邮箱登录的详细介绍
-
php 模拟GMAIL,HOTMAIL(MSN),YAHOO,163,126信箱登录(原创)
-
php 模拟GMAIL,HOTMAIL(MSN),YAHOO,163,126邮箱登录的详细介绍
-
php 模拟GMAIL,HOTMAIL(MSN),YAHOO,163,126邮箱登录的详细介绍
-
php 模拟GMAIL,HOTMAIL(MSN),YAHOO,163,126信箱登录(原创)
-
php 模拟GMAIL,HOTMAIL(MSN),YAHOO,163,126邮箱登录的详细介绍_php技巧
-
php 模拟GMAIL,HOTMAIL(MSN),YAHOO,163,126信箱登录(原创)
-
php 模拟GMAIL,HOTMAIL(MSN),YAHOO,163,126邮箱登录的详细介绍_PHP教程
-
php 模拟GMAIL,HOTMAIL(MSN),YAHOO,163,126邮箱登录的详细介绍_php技巧
-
php 模拟GMAIL,HOTMAIL(MSN),YAHOO,163,126邮箱登录的详细介绍