//get mail list from the page information username && emailaddress preg_match_all("/<string\s*name=\"EMAIL;PREF\">(.*)<\/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 '您的邮箱中尚未有联系人'; }
/**
* 获得tom邮箱通讯录列表 -- contactstom.class.php
*/
define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) ); //定义COOKIES存放的路径,要有操作的权限
define( "TIMEOUT", 1000 ); //超时设定class contactstom
{ function checklogin( $user, $password )
{
$ch = curl_init( );
curl_setopt( $ch, CURLOPT_URL, "http://login.mail.tom.com/cgi/login" );
curl_setopt( $ch, CURLOPT_USERAGENT, USERAGENT );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_COOKIEJAR, COOKIEJAR );
curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT );
$fileds = "user=".$user."&pass={$password}";
$fileds .= "&style=0&verifycookie";
$fileds .= "&type=0&url=http://bjweb.mail.tom.com/cgi/login2";
curl_setopt( $ch, CURLOPT_POSTFIELDS, $fileds );
ob_start( );
curl_exec( $ch );
$str = curl_exec($ch);
// echo $str;exit;
$result = ob_get_contents( );
ob_end_clean( );
curl_close( $ch );
/*if ( preg_match( "/warning|?��??/", $result ) )
{
return 0;
}*/
return 1;
} function getcontacts( $user, $password, &$result )
{
if ( !$this->checklogin( $user, $password ) )
{
return 'checklogin失败';
}
$this->readcookies( COOKIEJAR, $res );
if ( $res['Coremail'] == "" )
{
return 'readcookies失败';
}
$sid = substr( trim( $res['Coremail'] ), -16 );
$url = "http://bjapp2.mail.tom.com/cgi/ldvcapp";
$url .= "?funcid=address&sid=".$sid."&showlist=all&listnum=0";
$ch = curl_init( );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_USERAGENT, USERAGENT );
curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT );
curl_setopt( $ch, CURLOPT_COOKIEFILE, COOKIEJAR );
ob_start( );
curl_exec( $ch );
$res = ob_get_contents( );
ob_end_clean( );
curl_close( $ch );
$p="/<td\sclass=\"Addr_Td_Name\"><a href=\"(.+)?\">(.+)?<\/a><\/td><td\sclass=\"Addr_Td_Address\"><a\shref=\"(.+)?\">(.+)?<\/a>/";
preg_match_all( $p, $res, $tmp);
$result[0]=$tmp[2];
$pattern = "/([\\w_-])+@([\\w])+([\\w.]+)/";
if ( preg_match_all( $pattern, $res, $tmpres, PREG_PATTERN_ORDER ) )
{
$result[1] = array_unique( $tmpres[0] );
}
return $result;
}
function readcookies( $file, &$result )
{
$fp = fopen( $file, "r" );
while ( !feof( $fp ) )
{
$buffer = fgets( $fp, 4096 );
$tmp = split( "\t", $buffer );
$result[trim( $tmp[5] )] = trim( $tmp[6] );
}
return 1;
}}$contacts = new contactstom;$res = $contacts->getcontacts('****@tom.com','*****',$result);print_r($res);?>
/**
* @file class.126http.php
* 获得126邮箱通讯录列表
* @author jvones<[email protected]> http://www.jvones.com/blog
* @date 2009-09-26
**/
class http126
{
private function login($username, $password)
{
//第一步:初步登陆
$cookies = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, "https://reg.163.com/logins.jsp?type=1&product=mail126&url=http://entry.mail.126.com/cgi/ntesdoor?hid%3D10010102%26lightweight%3D1%26verifycookie%3D1%26language%3D0%26style%3D-1");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$username."@126.com&password=".$password);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch,CURLOPT_HEADER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$str = curl_exec($ch);
//file_put_contents('./126result.txt', $str);
curl_close($ch);
//获取redirect_url跳转地址,可以从126result.txt中查看,通过正则在$str返回流中匹配该地址
preg_match("/replace\(\"(.*?)\"\)\;/", $str, $mtitle);
$_url1 = $mtitle[1];
//file_put_contents('./126resulturl.txt', $redirect_url);
//第二步:再次跳转到到上面$_url1
$ch = curl_init($_url1);
curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_COOKIEFILE,COOKIEJAR);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch,CURLOPT_HEADER,1);
$str2 = curl_exec($ch);
curl_close($ch);
if (strpos($contents, "安全退出") !== false)
{
return 0;
}
return 1;
}
/**
* 获取邮箱通讯录-地址
* @param $user
* @param $password
* @param $result
* @return array
*/
public function getAddressList($username, $password)
{
if (!$this->login($username, $password))
{
return 0;
}
$header = $this->_getheader($username);
if (!$header['sid'])
{
return 0;
}
//测试找出sid(很重要)和host
//file_put_contents('./host.txt', $header['host']);
//file_put_contents('./sid.txt', $header['sid']);
//开始进入模拟抓取
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://".$header['host']."/a/s?sid=".$header['sid']."&func=global:sequential");
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
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_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
ob_start();
curl_exec($ch);
$contents = ob_get_contents(); ob_end_clean();
curl_close($ch);
//get mail list from the page information username && emailaddress
preg_match_all("/<string\s*name=\"EMAIL;PREF\">(.*)<\/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 '您的邮箱中尚未有联系人';
}
return $users;
}
/**
* Get Header info
*/
private function _getheader($username)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://entry.mail.126.com/cgi/ntesdoor?hid=10010102&lightweight=1&verifycookie=1&language=0&style=-1&username=".$username."@126.com");
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR); //当前使用的cookie
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR); //服务器返回的新cookie
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
$content=curl_exec($ch);
preg_match_all('/Location:\s*(.*?)\r\n/i',$content,$regs);
$refer = $regs[1][0];
preg_match_all('/http\:\/\/(.*?)\//i',$refer,$regs);
$host = $regs[1][0];
preg_match_all("/sid=(.*)/i",$refer,$regs);
$sid = $regs[1][0];
curl_close($ch);
return array('sid'=>$sid,'refer'=>$refer,'host'=>$host);
}
}?>
再有就是联系人列表中有的没有name,那么也容易导致错误,解决方案就是在错误处进行详细处理,比如name=邮箱@前面的字符串,因为这个在我做yahoo邮箱的时候有过错误,很容易导致用户名和邮箱不匹配。
还有就是建议楼主把gmail加进去,毕竟这个很多人都用,而且gmail还有一点小的挑战性哦~
/**
* $obj->name 用户姓名
* $obj->nickname 昵称
* $obj->emailAddress email
* 在UTF-8下已测试
* 根据sohu邮箱特点,该邮箱不提供用户姓名,只提供用户昵称以及用户的昵称拼音,获取时昵称作为用户姓名,拼音作为昵称
* 非汉字时,获取的拼音为空,因此昵称与姓名将保持一致
* 当姓名为中文时显示中文,否则为英文,对于其他语种日文韩文已经测试成功无乱码
* 测试输入接口为:getAddressList('[email protected]', 'password');
*/
define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) );
class sohu
{
public function getAddressList($username, $password)
{
$name=explode('@', $username);
$username=$name[0];
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$encodeurl = "http://passport.sohu.com/sso/login.jsp?userid=".urlencode($username . "@sohu.com") . "&password=".md5($password)."&appid=1000&persistentcookie=0&s=".time()."343&b=2&w=1024&pwdtype=1";
curl_setopt($ch, CURLOPT_URL, $encodeurl);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR );
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$contents = curl_exec( $ch );
if ( strpos( $contents, "success" ) === false )
{
return 0;
}
curl_setopt($ch, CURLOPT_URL, "http://mail.sohu.com/bapp/99/main");
$contents = curl_exec($ch);
if(false !== $contents && '' != trim($contents)){
curl_close( $ch );
return $this->parserContent($contents);
}
curl_setopt($ch, CURLOPT_URL, "http://mail.sohu.com/bapp/79/main#addressList");
$contents = curl_exec($ch);
if(false == $contents){
curl_close( $ch );
return false;
}else{
curl_close( $ch );
return $this->parserContent($contents);
}
}
function parserContent($content){
preg_match_all("/var addresses = '(.*)';/Umsi",$content,$data);
$numList= json_decode( $data[1][0]);
$contactList = array();
foreach ($numList->contact as $val){
$obj = new stdClass;
$obj->name = $val->nickname;
$obj->nickname = $val->pinyin;
$obj->emailAddress = $val->email;
if($obj->nickname==""){
$obj->nickname = $obj->name;
}
$contactList[] = $obj;
}
if( count($contactList) == 0 ){
return false;
}else{
return $contactList;
}
}
}$test = new sohu();
$contects = $test->getAddressList('[email protected]', 'password');?>
搜狐的邮箱登陆界面,源码是这样写的:
<form action="" name="form_login" onsubmit="return mydoLogin();">
<input type="hidden" id="userid" name="userid" value="" />
<input type="hidden" id="appid" name="appid" value="1000" />
<input type="hidden" id="ru" name="ru" value="" />
<ul>
<li class="wrong" id="errorMsg"> </li> <li>邮 箱:
<input type="text" class="wid" id="username" name="username" tabindex="1" autocomplete="off" disableautocomplete/>
</li>
<div id="ppcard" style="position: absolute; padding-left:0px"> </div>
<li>密 码:
<input type="password" class="wid" id="password" name="password" tabindex="1"/><a href="http://passport.sohu.com/web/recover.jsp" target="_blank" class="pw">忘记密码</a></li>
<li class="font12 mar"><input name="persistentcookie" id="rpwd" type="checkbox" value="1" tabindex="1"/><label for="rpwd">记住登录状态</label>
<span style="margin:0 0 17px 13px"><a href="https://mail.sohu.com?schemeforce=1" class="pw" title="从登录开始全程加密,让你的信息更安全。">https安全访问</a></span></li> <li class="mar">
<input id="login_img" type="image" src="http://js.mail.sohu.com/images/index/button_login_new.gif" border="0" tabindex="1" />
<span id="login_tip" style="display:none;">正在登录搜狐通行证,请稍候...</span>
</li>
<li class="now"><a href="http://passport.sohu.com/web/dispatchAction.action?appid=1000&ru=http://mail.sohu.com/reg/signup_success.jsp" target="_blank">
<img src="http://js.mail.sohu.com/images/index/spacer.gif" width="56" height="20" border="0" class="cursor"/></a></li>
</ul>
</form>
其中的<form action="" name="form_login" onsubmit="return mydoLogin();">调用的是mydoLogin函数,通过进行一些列跟踪不难获得最终有用的url地址(我的用firebug进行跟踪的):、
{document.location.href="http://passport.sohu.com";return false}
var A=getBrowserType();
var B=screen.width;document.forms[C].action="http://passport.sohu.com/sso/login_js.jsp?appid="+this.appid+"&ru="+this.postru+"&b="+A+"&w="+B+"&v="+this.version;document.forms[C].submit();
return false},
doLogin:function(){if(this.eInterval){return }
if(arguments[0]){PassportCardList[index].doLogin()}
也就是实际上登录按钮提交以后,是这个页面(http://passport.sohu.com/sso/login_js.jsp?*****)来帮我们实现登录的,然后进行相关跳转的。
那个sohu类的代码中有这样一行:
$encodeurl = "http://passport.sohu.com/sso/login.jsp?userid=".urlencode($username . "@sohu.com") . "&password=".md5($password)."&appid=1000&persistentcookie=0&s=".time()."343&b=2&w=1024&pwdtype=1";
我们完完全全可以在这里设置一个断点,获取得到$encodeurl(大概是这样的值:http://passport.sohu.com/sso/login.jsp?userid=username%40sohu.com&password=(urlencode处理过的密码)&appid=1000&persistentcookie=0&s=1310705795343&b=2&w=1024&pwdtype=1),然后把这个值放在浏览器的地址栏里回车,你就会发现网页刷新显示了“login_status='success';”这几个字,这时候说明你的登录已经结束了,现在在刷新一下搜狐登录界面会发现直接进入邮箱了,没错$encodeurl值已经帮你实现登录存储数据过程了。这时候在curl抓取任何信息都容易了。
下面再分析一下我发的代码就应该容易理解一些了:
<?php
/**
* $obj->name 用户姓名
* $obj->nickname 昵称
* $obj->emailAddress email
* 在UTF-8下已测试
* 根据sohu邮箱特点,该邮箱不提供用户姓名,只提供用户昵称以及用户的昵称拼音,获取时昵称作为用户姓名,拼音作为昵称
* 非汉字时,获取的拼音为空,因此昵称与姓名将保持一致
* 当姓名为中文时显示中文,否则为英文,对于其他语种日文韩文已经测试成功无乱码
* 测试输入接口为:getAddressList('[email protected]', 'password');
*/
define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) );
class sohu
{
public function getAddressList($username, $password)
{
$name=explode('@', $username);
$username=$name[0];
$ch = curl_init();
//这个地址encodeurl就是刚才所说的那个可以帮助实现登录的地址
$encodeurl = "http://passport.sohu.com/sso/login.jsp?userid=".urlencode($username . "@sohu.com") . "&password=".md5($password)."&appid=1000&persistentcookie=0&s=".time()."343&b=2&w=1024&pwdtype=1";
curl_setopt($ch, CURLOPT_URL, $encodeurl);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR );
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$contents = curl_exec( $ch );
if ( strpos( $contents, "success" ) === false )
{
return 0;
}
//由于已经记录了登录后的所有数据行为,因此只需看一下搜狐地址簿(就是联系人的链接地址),是http://mail.sohu.com/bapp/79/main#addressList
//因此我们只需模拟一下这个页面就可很方便的抓取上面的相关信息
curl_setopt($ch, CURLOPT_URL, "http://mail.sohu.com/bapp/79/main#addressList");
$contents = curl_exec($ch);
if(false == $contents){
curl_close( $ch );
return false;
}else{
curl_close( $ch );
return $this->parserContent($contents);
}
}
function parserContent($content){
preg_match_all("/var addresses = '(.*)';/Umsi",$content,$data);
$numList= json_decode( $data[1][0]);
$contactList = array();
foreach ($numList->contact as $val){
$obj = new stdClass;
$obj->name = $val->nickname;
$obj->nickname = $val->pinyin;
$obj->emailAddress = $val->email;
if($obj->nickname==""){
$obj->nickname = $obj->name;
}
$contactList[] = $obj;
}
if( count($contactList) == 0 ){
return false;
}else{
return $contactList;
}
}
}$test = new sohu();
$contects = $test->getAddressList('[email protected]', 'password');?>
不知道这么说你能否明白,很乐意一起讨论。之前在一个人人网API的帖子上面也看见你了,有经验的话也可以一起讨论,之前也有关研究人人、开心、facebook的api,不过不是很成熟,所以可以讨论。
$fieldsStr = implode(' , ', $fields );
$valueStr = implode(' , ', $value);
$whereStr = implode (',', $where);
$sql = 'UPDATE ' . $table . ' SET ' . $fieldsStr . ' = ' . $valueStr . 'WHERE ( ' . $whereStr . ' ) ';
return mysql_query($sql);
}
这是我写的一个通用的更新数据的方法 更新多条怎么写!帮帮呢!
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);
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); $contents = substr($contents, strlen('while (true); &&&START&&&'), -strlen('&&&END&&& '));
return $contents;
}
}$gamil = new GMAIL;$res = $gamil->getAddressList('****@gmail.com','****');$a = json_decode($res);echo "<pre>";
//print_r($a->Body->Contacts);
foreach($a->Body->Contacts as $k=>$v)
{
echo "姓名:".$v->DisplayName;
echo "家庭email:".$v->Emails[0]->Address;
echo "工作email:".$v->Emails[1]->Address;
echo "<br>";
}
echo "</pre>";?>
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_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);
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后面的数字是随机数
if(!$url_contiune_3)
{
return false;
}
/* 第四步: 开始获取邮箱联系人 */
$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('[email protected]','a000000');
$res = $msn->getAddressList('[email protected]','88888');echo "<pre>";
//print_r(json_decode($res, true));
$a = json_decode($res, true);
unset($a['icTmConvTemplate']);
unset($a['icTmInlineTemplate']);
unset($a['icTmTabInlineTemplate']);
//print_r($a);
foreach($a as $k=>$v)
{
echo "姓名:".$v[3];
echo " email:".$v[6];
echo "<br>";
}
echo "</pre>";
?>
改为
"http://mail.sohu.com/bapp/117/main#addressList"
了...希望也对后面的同志有帮助