文心春萌

厌倦了城市的喧嚣,向往美丽的草原!

« 教你如何用FOXMAIL设置GMAIL,HOTMAIL,YAHOO邮箱(及 -gmail邮箱登陆地址 Gmail邮箱帐号的野心是大一统互联网通行证 -gmail邮箱登陆地址 »

PHP获取163、gmail、126等邮箱联系人地址【已测试2009.10.10】 -gmail邮箱登陆地址


2009年10月11日

  最近一直忙着做项目上的QQ、MSN、邮箱(今朝以实现16三、126、gmail、sina、tom、sohu、yahoo等)通信录地址获取;此中搜狐掉效还需研究一下!

  在网上找了一些,大多都已掉效,为此我从头打叠整顿了一下;特别放出126的代码,163是比力容易抓取的;126有点掉常多了一次跳转,比力麻烦;

  在线demo地址:http://demo.jvones.com/get163emailladdress/

  <?php /** * @file class.126http.php * 得到126邮箱通信录列表 * @author jvones<jvones@gmail.com> 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=mai l126&url=http://entry.mail.126.com/cgi/ntesdoor?你好d =10010102&lightweight=1&verifycookie=1& language=0&style=-1"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$username."@126.com&password=".$passwo rd); 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_关上($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_关上($ch); if (strpos($contents, "安全退出") !== false) { return 0; } return 1; } /** * 获取邮箱通信录-地址 * @param $user * @param $password * @param $result * @return array */ public function getAddressList($username, $password) { if (!$t你好s->login($username, $password)) { return 0; } $header = $t你好s->_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></objec t></object><object><string name=\"func\">user:getSignatures</string></object><objec t><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_关上($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?你好d=100101 02&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_关上($ch); return array(''''sid''''=>$sid,''''refer''''=>$refer,''''host''''=>$host); } } ?>

  

  发表于 @ 2009年10月11日 11:48:00 | 评论( loading...) | 举报| 收藏

gmail企业邮箱登陆

  

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

本站采用创作共用版权协议, 要求署名、非商业用途和保持一致.

Auto Publisher Copyright Blog.cnxcn.net . All Rights Reserved.