php 获取邮箱好友

来源:互联网 发布:河南淘宝营销 编辑:程序博客网 时间:2024/05/16 23:50

前几天做的一个活动,用到了用户邮箱的好友,今天总结一下。。由于在本地无法测试,所有就把源码拿过来了。。

 

if ($_G['uid']<1){//用户没有登录

$referer = addslashes(str_replace("&","/u007C",dreferer()));

showmessage('对不起你还没有登陆!','member.php?mod=logging&action=login&referer='.$referer);

}

 

if(!empty($_G['gp_submit'])){//点击了查找好友提交按钮

if($_G['gp_submit']=='msnsubmit'){//获取msn好友列表

$invitelink = $_G['gp_invitelink'];

//var_dump($_POST);

 

$email = $_POST['username'] ;

$password = $_POST['password'] ;

$msn = new MSN;

$msn->set_account($email, $password);

$msn->msn_connect("messenger.hotmail.com",1863);

$data = $msn->getStatus();

if($data[0] == 200){

$len = count($data[1]);

$pos = strpos($email, '@');

if($pos === false ){

$name = $email ;

}else{

$name = substr($email, 0, $pos);

}

$invitername = $name;

$count = $len;

$data = $data[1];

}

/* 载入msn列表模板页 */

include_once template('buynow/baodaoyou_inviteothers2');

exit;

}elseif ($_G['gp_submit']=='emailsubmit'){//获取email联系人列表

$invitelink = $_G['gp_invitelink'];

//var_dump($_POST);

 

$username= $_POST['username'];

$password= $_POST['password'];

if($_POST['mailaddress'] == '163'){//163邮箱

//include("163.class.php");

$r = get_address($username,$password);

$data = array();

foreach ($r as $k=>$v){

$data[$k] = array($v[2],$v[1]);

}

$invitername = $_G['gp_username'];

$count = count($data);

//print_r($data);

}elseif ($_POST['mailaddress'] == '126'){//126邮箱

//include("126.class.php");

$a=new http126();

$tmp=$a->getAddressList($username,$password);

$data = array();

if(is_array($tmp)){

foreach($tmp as $k=>$v){

$data[$k] = array($k,$v);

//echo "<BR>$k = $v";

}

}else{//邮箱中没有联系人

//echo $tmp;

}

$invitername = $_G['gp_username'];

$count = count($data);

//print_r($data);

}elseif ($_POST['mailaddress'] == 'sina'){//新浪邮箱

//include("sina.class.php");

$a=new httpSina();

$tmp=$a->getFriendList($username."@sina.com",$password);

//print_r($tmp);

$data = array();

foreach($tmp as $k=>$v){

$data[$k] = array($v->email,$v->name);

//echo "姓名:".$v->name;

//echo "  email:".$v->email;

//echo "<br>";

}

$invitername = $_G['gp_username'];

$count = count($data);

//print_r($data);

}elseif ($_POST['mailaddress'] == 'gmail'){//谷歌邮箱

//include("gmail.class.php");

$gamil = new GMAIL;

$res = $gamil->getAddressList($username.'@gmail.com',$password);

$a = json_decode($res);

$data = array();

foreach($a->Body->Contacts as $k=>$v){

$data[$k] = array($v->Emails[0]->Address,$v->DisplayName);

//echo "姓名:".$v->DisplayName;

//echo "家庭email:".$v->Emails[0]->Address;

//echo "工作email:".$v->Emails[1]->Address;

//echo "<br>";

}

$invitername = $_G['gp_username'];

$count = count($data);

//print_r($data);

}elseif ($_POST['mailaddress'] == 'hotmail.com' || $_POST['mailaddress'] == 'live.cn'){//微软邮箱

//include("hotmail.class.php");

$msn = new hotmail;

$res = $msn->getAddressList($username.'@'.$_POST['mailaddress'],$password);

$a = json_decode($res, true);

unset($a['icTmConvTemplate']);

unset($a['icTmInlineTemplate']);

unset($a['icTmTabInlineTemplate']);

$data = array();

foreach($a as $k=>$v){

$data[$k] = array($v[6],$v[3]);

//echo "姓名:".$v[3];

//echo "  email:".$v[6];

//echo "<br>";

}

$invitername = $_G['gp_username'];

$count = count($data);

//print_r($data);

}elseif ($_POST['mailaddress'] == 'tom'){//tom邮箱

//include("tom.class.php");

$contacts = new contactstom;

$res = $contacts->getcontacts($username.'@tom.com',$password,$result);

$data = array();

foreach($res[0] as $k=>$v){

$data[$k] = array($res[1][$k],$v);

//echo "姓名:".$v;

//echo "  email:".$res[1][$k];

//echo "<br>";

}

$invitername = $_G['gp_username'];

$count = count($data);

//print_r($data);

}elseif ($_POST['mailaddress'] == 'yahoo.cn' || $_POST['mailaddress'] == 'yahoo.com' || $_POST['mailaddress'] == 'yahoo.com.cn'){//雅虎邮箱

//include("yahoo.class.php");

$yahoo = new YAHOO;

$res = $yahoo->getAddressList($username.'@'.$_POST['mailaddress'],$password);

$data = array();

foreach($res as $k=>$v){

$data[$k] = array($v['email'],$v['contactName']);

//echo "姓名:".$v['contactName'];

//echo "  email:".$v['email'];

//echo "<br>";

}

$invitername = $_G['gp_username'];

$count = count($data);

//print_r($data);

}

/* 载入邮箱列表模板页 */

include_once template('buynow/baodaoyou_inviteothers1');

exit;

}

}elseif (!empty($_G['gp_invitesubmit'])){//点击了“邀请”按钮,向被邀请的用户发送邮件

//var_dump($_POST);

$emails = $_G['gp_emails'];

$invitername = $_G['gp_invitername'];

$invitelink = "<a href='$_G[gp_invitelink]'>".$_G['gp_invitelink']."</a>";//邀请链接

$content = " HI,百脑汇上海站正在举行“签到百脑汇 浪漫双人游宝岛活动”。<br>只要点击下面的链接,就可以参加活动, <br>$invitelink<br>如果链接无法点击,请完整拷贝到浏览器地址栏里直接访问<br>就可参加活动,赶快来参加哦~ <br>百脑汇上海站<br>http://www.buynow.com.cn";

$count = count($emails);

foreach ($emails as $value){//循环发送邮件

sendmail($value, "签到游宝岛", $content);

}

/* 载入邀请成功模板页 */

include_once template('buynow/baodaoyou_inviteothers3');

exit;

}else{//进入“推荐好友”页面

if ($_G['uid']<1){//用户没有登录

$referer = addslashes(str_replace("&","/u007C",dreferer()));

showmessage('对不起你还没有登陆!','member.php?mod=logging&action=login&referer='.$referer);

}else{//用户已经登录

$sql = " SELECT drawcode".

  " FROM ".DB::table('buynow_baodaoyou_draw').

      " WHERE uid=".$_G['uid']." AND friendid=0";

$tmpdrawcode = DB::result_first($sql);

if(!empty($tmpdrawcode)){//用户参与过该活动,可以发起邀请

$inviterid = register_hash("encode",$_G['uid']);//将用户uid进行加密

$invitelink = "http://www.buynow.com.cn/baodaoyou.php?mod=draw&inviterid=$inviterid";

}

}

}

 

 

/****************************************************start:邮箱类文件**************************************************************/

 

/**

* @file class.126http.php

* 获得126邮箱通讯录列表

* @author jvones<jvones@gmail.com> http://www.jvones.com/blog

* @date 2009-09-26

**/

 

class http126{

function __construct() {

define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) );   //定义COOKIES存放的路径,要有操作的权限

define( "TIMEOUT", 1000 ); //超时设定

}

 

/*** 模拟登陆* */

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);

curl_close($ch);

//获取redirect_url跳转地址

preg_match("/replace/(/"(.*?)/"/)/;/", $str, $mtitle);

$_url1 = $mtitle[1];

//第二步:再次跳转到到上面$_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;

}

/*** 获取邮箱通讯录-地址* */

public function getAddressList($username, $password){

if (!$this->login($username, $password)){

return 'login失败';

}

$header = $this->_getheader($username);

if (!$header['sid']){

return '_getheader失败';

}

//开始进入模拟抓取

$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);

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){

$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);

}

}

 

/*********163************/

function get_address($username,$password){

error_reporting(0);

//邮箱用户名(不带@163.com后缀的)

$user       = $username;

//邮箱密码

$pass       = $password;

//目标邮箱

//$mail_addr = uenucom@163.com';

//登陆

$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';

$ch             = curl_init($url);

//创建一个用于存放cookie信息的临时文件

$cookie         = tempnam('.','~');

$referer_login = 'http://mail.163.com';

//返回结果存放在变量中,而不是默认的直接输出

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_HEADER, true);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_REFERER, $referer_login);

$fields_post = array(

'username'=> $user,

'password'=> $pass,

'verifycookie'=>1,

'style'=>-1,

'product'=> 'mail163',

'selType'=>-1,

'secure'=>'on'

);

$headers_login = 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'

);

$fields_string = '';

foreach($fields_post as $key => $value){

$fields_string .= $key . '=' . $value . '&';

}

$fields_string = rtrim($fields_string , '&');

curl_setopt($ch, CURLOPT_COOKIESESSION, true);

//关闭连接时,将服务器端返回的cookie保存在以下文件中

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_login);

curl_setopt($ch, CURLOPT_POST, count($fields_post));

curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);

$result= curl_exec($ch);

curl_close($ch);

//跳转

$url='http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=-1&username=loki_wuxi';

$ch = curl_init($url);

$headers = array(

'User-Agent'        => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0'

);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_HEADER, true);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

//将之前保存的cookie信息,一起发送到服务器端

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);

$result = curl_exec($ch);

curl_close($ch);

//取得sid

preg_match('/sid=[^/"].*/', $result, $location);

$sid = substr($location[0], 4, -1);

//file_put_contents('./result.txt', $sid);

//通讯录地址

$url='http://g4a30.mail.163.com/jy3/address/addrlist.jsp?sid='.$sid.'&gid=all';

$ch = curl_init($url);

$headers = array(

'User-Agent'        => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0'

);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_HEADER, true);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);

$result = curl_exec($ch);

curl_close($ch);

unlink($cookie);

$result = iconv("gbk","utf-8",$result);

//开始抓取内容

preg_match_all('/<td class="Ibx_Td_addrName"><a[^>]*>(.*?)<//a><//td><td class="Ibx_Td_addrEmail"><a[^>]*>(.*?)<//a><//td>/i', $result,$infos,PREG_SET_ORDER);

//1:姓名2:邮箱

return $infos;

}

 

/************gmail***************/

class GMAIL{

function __construct() {

define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) );   //定义COOKIES存放的路径,要有操作的权限

define( "TIMEOUT", 1000 ); //超时设定

}

 

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;

}

}

 

/****************hotmail********************/

class hotmail{

 

function __construct() {

define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) );   //定义COOKIES存放的路径,要有操作的权限

define( "TIMEOUT", 1000 ); //超时设定

}

 

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();

}

}

}

 

/*******************sina*********************/

class httpSina{

private $gurl='';

 

function __construct() {

date_default_timezone_set('Asia/Shanghai');

}

 

private function vlogin($url,$name, $ps){

$cookie_jar = tempnam('./tmp','cookie');//在当前目录下生成一个随机文件名的临时文件

$ch = curl_init($url); //初始化curl模块

$fields_post = array(

'logintype'=>'uid',

'u'=>$name,

'domain'=>'sina.com',

'psw'=>$ps,

'btnloginfree'=>'%B5%C7+%C2%BC'

);

curl_setopt($ch,CURLOPT_URL,$url);//登录页地址

curl_setopt($ch, CURLOPT_POST, 1);//post方式提交

$fields_string = '';

foreach($fields_post as $key => $value){

$fields_string .= $key . '=' . $value . '&';

}

$fields_string = rtrim($fields_string , '&');

curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);//要提交的内容

//把返回$cookie_jar来的cookie信息保存在$cookie_jar文件中

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);

$headers_login = array(

'Host'  => 'mail.sina.com.cn',

'User-Agent'      => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2',

'Accept'          => 'text/javascript, text/html, application/xml',

'Accept_Language' => 'zh-cn,zh;q=0.5',

'Accept_Encoding' => 'gzip,deflate',

'Accept_Charset'  => 'GB2312,utf-8;q=0.7,*;q=0.7/r/n',

'Keep-Alive'      => '115',

'Connection'      => 'keep-alive',

'X-Requested-With'=> 'XMLHttpRequest',

'Content_Type'    => 'application/x-www-form-urlencoded; charset=UTF-8',

'Referer'         => 'http://mail.sina.com.cn/'

);

//设定返回的数据是否自动显示

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//设定是否显示头信息

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_login);

//设定是否输出页面内容

curl_setopt($ch, CURLOPT_NOBODY, 0);

$result=curl_exec ($ch);

//echo $result;

preg_match('/Location:[^/"].*/', $result, $location);

if(empty($location)){

return 0;

}

 

list($lc,$urltemp)=explode(':',$location[0],2);

$this -> gurl = $urltemp;

curl_close($ch); //get data after login

return $cookie_jar;

}

 

/***  获取通讯录列表* */

public function getFriendList($username,$password){

$result_array = array();

$login_url   = 'http://mail.sina.com.cn/cgi-bin/login.cgi';

$cookie_file = $this -> vlogin($login_url,$username,$password);    //模拟登陆

if(!$cookie_file){

return $result_array;

}

$this -> gurl = trim($this -> gurl);

$ch   = curl_init($this -> gurl);

$headers = array(

'Host'       => 'mail3-145.sinamail.sina.com.cn',

'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2'

);

curl_setopt($ch, CURLOPT_URL,$this -> gurl);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_HEADER, true);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);

curl_setopt($ch, CURLOPT_POST, 0);

curl_setopt($ch, CURLOPT_REFERER, 'http://mail.sina.com.cn/');

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

//将之前保存的cookie信息,一起发送到服务器端

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);

curl_setopt($ch, CURLOPT_NOBODY, 0);

$result = curl_exec($ch);

curl_close($ch);

preg_match('/Location:[^/"].*/', $result, $location);

list($lc,$urltemp)=explode(':',$location[0],2);

$this -> gurl=trim($this -> gurl);

$server = substr(substr($this -> gurl,strpos($this -> gurl,'//')+2),0,strpos(substr($this -> gurl,strpos($this -> gurl,'//')+2),'/'));

$ch   = curl_init($this -> gurl);

$headers = array(

'Host'       => $server,

'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2'

);

curl_setopt($ch, CURLOPT_URL,$this -> gurl);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_HEADER, true);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);

curl_setopt($ch, CURLOPT_POST, 0);

curl_setopt($ch, CURLOPT_REFERER, 'http://mail.sina.com.cn/');

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

//将之前保存的cookie信息,一起发送到服务器端

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);

curl_setopt($ch, CURLOPT_NOBODY, 0);

$result = curl_exec($ch);

curl_close($ch);

$url = "http://".$server."/classic/address.php?ts=".mktime()."358_1";

$ch   = curl_init($url);

$headers = array(

'Host'       =>$server,

'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2'

);

curl_setopt($ch, CURLOPT_URL,$url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_HEADER, true);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);

curl_setopt($ch, CURLOPT_POST, 0);

curl_setopt($ch, CURLOPT_REFERER, $this -> gurl);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

//将之前保存的cookie信息,一起发送到服务器端

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);

curl_setopt($ch, CURLOPT_NOBODY, 0);

// echo file_get_contents($cookie_file);

$result = curl_exec($ch);

//echo $result;

curl_close($ch);

$url="http://".$server."/classic/addr_member.php";

$ch   = curl_init($url);

$headers = array(

'Host'         => $server,

'User-Agent'   => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2',

'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'

);

$str ="act=list&sort_item=letter&sort_type=desc";

curl_setopt($ch, CURLOPT_URL,$url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $str);

curl_setopt($ch, CURLOPT_REFERER, $this -> gurl);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

//将之前保存的cookie信息,一起发送到服务器端

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);

$result = curl_exec($ch);

$result_mid[] = json_decode($result);

return $result_mid[0]->data->contact;

}

}

 

/**

 * 获得tom邮箱通讯录列表 -- contactstom.class.php

 */

 

 

class contactstom{

function __construct() {

define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) );   //定义COOKIES存放的路径,要有操作的权限

define( "TIMEOUT", 1000 ); //超时设定

}

 

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);

$result = ob_get_contents( );

ob_end_clean( );

curl_close( $ch );

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 );

$res = iconv("gb2312","utf-8",$res);

$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;

}

}

 

/*******************yahoo**********************/

class YAHOO{

function __construct() {

define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) );

define( "TIMEOUT", 1000 );

}

 

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']);

$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 '登陆失败';

}

//开始进入模拟抓取

$url = "http://address.mail.yahoo.com/";

$data = array( );

if ( !$data = $this->hanlde_date( $url, $names, $emails) ){

return FALSE;

}

 

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 json_decode($temparr[1][0], true);

}

}

/****************************************************end:邮箱类文件******************************************************/

/**

 * 获取msn好友列表类

 *

 */

class msn{

private $startcomm = 0;

private $username = '';

private $password = '';

private $commend = '';

private $domain = '';

private $socket = '';

private $challenge = '';

private $status = array();

private $data = array();

 

function set_account($username, $password){

$this->username = $username;

$this->password = $password;

}

 

function getData(){

$buffer="";

while (!feof($this->socket)) {

$buffer .= fread($this->socket,1024);

if (preg_match("//r/",$buffer)) {

break;

}

}

$this->checkData($buffer);

}

 

function getData2() {

$buffer="";

while (!feof($this->socket)) {

$buffer .= fread($this->socket,1024);

if (preg_match("//r/n/r/n/",$buffer)) {

break;

}

}

$this->checkData($buffer);

}

 

function checkData($buffer) {

if (preg_match("/lc/=(.+?)/Ui",$buffer,$matches)) {

$this->challenge = "lc=" . $matches[1];

}

 

if (preg_match("/(XFR 3 NS )([0-9/./:]+?) (.*) ([0-9/./:]+?)/is",$buffer,$matches)) {

$split = explode(":",$matches[2]);

$this->startcomm = 1;

$this->msn_connect($split[0],$split[1]);

}

 

if (preg_match("/tpf/=([a-zA-Z0-9]+?)/Ui",$buffer,$matches)) {

$this->nexus_connect($matches[1]);

}

$split = explode("/n",$buffer);

for ($i=0;$i<count($split);$i++) {

$detail = explode(" ",$split[$i]);

if ($detail[0] == "LST") {

if(isset($detail[2])) $this->data[] = array($detail[1], urldecode($detail[2]));

}

}

$this->status = array(200, $this->data);

//echo $buffer;

}

 

function msn_connect($server,$port) {

if ($this->socket) {

fclose($this->socket);

}

$this->socket = @fsockopen($server,$port, $errno, $errstr, 20);

if (!$this->socket) {

$this->status = array(500,'MSN验证服务器无法连接');

return false;

} else {

$this->startcomm++;

$this->send_command("VER " . $this->startcomm . " MSNP8 CVR0",1);

$this->send_command("CVR " . $this->startcomm . " 0x0409 win 4.10 i386 MSNMSGR 6.2 MSMSGS " . $this->username,1);

$this->send_command("USR " . $this->startcomm . " TWN I " . $this->username,1);

}

}

 

function send_command($command) {

$this->commend = $command;

$this->startcomm++;

fwrite($this->socket,$command . "/r/n");

$this->getData();

}

 

function nexus_connect($tpf) {

$arr[] = "GET /rdr/pprdr.asp HTTP/1.0/r/n/r/n";

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, "https://nexus.passport.com:443/rdr/pprdr.asp");

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_VERBOSE, 0);

curl_setopt($curl, CURLOPT_HEADER,1);

curl_setopt($curl, CURLOPT_HTTPHEADER, $arr);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);

$data = curl_exec($curl);

curl_close($curl);

preg_match("/DALogin=(.+?),/",$data,$matches);

if(!isset($matches[1])) return false;

$split = explode("/",$matches[1]);

$headers[0] = "GET /$split[1] HTTP/1.1/r/n";

$headers[1] = "Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=" . $this->username . ",pwd=" . $this->password . ", " . trim($this->challenge) . "/r/n";

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, "https://" . $split[0] . ":443/". $split[1]);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_VERBOSE, 0);

curl_setopt($curl,CURLOPT_FOLLOWLOCATION,1);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

curl_setopt($curl, CURLOPT_HEADER,1);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);

$data = curl_exec($curl);

curl_close($curl);

preg_match("/t=(.+?)'/",$data,$matches);

if(!isset($matches[1])){

$this->status = array(404, '你输入的MSN帐号或者密码错误');

return false;

}

$this->send_command("USR " . $this->startcomm . " TWN S t=" . trim($matches[1]) . "",2);

$this->send_command("CHG " . $this->startcomm . " HDN",2);

$this->send_command("SYN " . $this->startcomm . " 0",2);

$this->getData2();

$this->send_command("SYN " . $this->startcomm . " 1 46 2",2);

$this->getData2();

$this->send_command("CHG ". $this->startcomm . " BSY");

$this->getData();

}

 

public function getStatus(){

return $this->status;

}

 

}

应该是没有问题的,如果有需要的话可以拿过来用。。