0

0

PHP获取163、sina、sohu、yahoo、126、gmail、tom邮箱联系人地址

php中文网

php中文网

发布时间:2016-06-08 17:29:04

|

1728人浏览过

|

来源于php中文网

原创

  1. /**
  2. * @file class.126http.php
  3. * 获得126邮箱通讯录列表
  4. * @author jvones http://www.jvones.com/blog
  5. * @date 2009-09-26
  6. **/
  7.  
  8. class http126
  9. {
  10.  
  11.         private function login($username, $password)
  12.         {               
  13.                 //第一步:初步登陆
  14.                 $cookies = array();
  15.                 $ch = curl_init();
  16.                 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  17.                
  18.                 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");
  19.                 curl_setopt($ch, CURLOPT_POST, 1);
  20.                 curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$username."@126.com&password=".$password);
  21.                
  22.                 curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
  23.                 curl_setopt($ch,CURLOPT_HEADER,1);               
  24.                 curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
  25.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  26.                 $str = curl_exec($ch);        
  27.                 //file_put_contents('./126result.txt', $str);               
  28.                 curl_close($ch);
  29.                         
  30.                 //获取redirect_url跳转地址,可以从126result.txt中查看,通过正则在$str返回流中匹配该地址
  31.                 preg_match("/replace("(.*?)");/", $str, $mtitle);
  32.                 $_url1 = $mtitle[1];
  33.                
  34.                 //file_put_contents('./126resulturl.txt', $redirect_url);        
  35.                 //第二步:再次跳转到到上面$_url1
  36.                 $ch = curl_init($_url1);               
  37.                
  38.                 curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
  39.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  40.                 curl_setopt($ch,CURLOPT_COOKIEFILE,COOKIEJAR);
  41.                 curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);               
  42.                 curl_setopt($ch,CURLOPT_HEADER,1);        
  43.                 $str2 = curl_exec($ch);
  44.                 curl_close($ch);
  45.                                                 
  46.                 if (strpos($contents, "安全退出") !== false)
  47.                 {                        
  48.                         return 0;
  49.                 }               
  50.                 return 1;
  51.         }
  52.         
  53.         /**
  54.          * 获取邮箱通讯录-地址
  55.          * @param $user
  56.          * @param $password
  57.          * @param $result
  58.          * @return array
  59.          */
  60.         public function getAddressList($username, $password)
  61.         {               
  62.                 if (!$this->login($username, $password))
  63.                 {
  64.                         return 0;
  65.                 }
  66.             
  67.                 $header = $this->_getheader($username);
  68.                 if (!$header['sid'])
  69.         {
  70.             return 0;
  71.         }
  72.         
  73.         //测试找出sid(很重要)和host
  74.         //file_put_contents('./host.txt', $header['host']);
  75.         //file_put_contents('./sid.txt', $header['sid']);
  76.         
  77.                 //开始进入模拟抓取
  78.                 $ch = curl_init();
  79.                 curl_setopt($ch, CURLOPT_URL, "http://".$header['host']."/a/s?sid=".$header['sid']."&func=global:sequential");
  80.                 curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
  81.                 curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/xml"));
  82.                 $str = "pab:searchContactsFNtrueuser:getSignaturespab:getAllGroups";
  83.                 curl_setopt($ch, CURLOPT_POST, 1);
  84.                 curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
  85.                 curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
  86.                 ob_start();
  87.                 curl_exec($ch);
  88.                 $contents = ob_get_contents();
  89.  
  90.                 ob_end_clean();
  91.                 curl_close($ch);
  92.                
  93.         //get mail list from the page information username && emailaddress
  94.         preg_match_all("/(.*)/Umsi",$contents,$mails);
  95.         preg_match_all("/(.*)/Umsi",$contents,$names);
  96.         $users = array();
  97.         foreach($names[1] as $k=>$user)
  98.         {
  99.             //$user = iconv($user,'utf-8','gb2312');
  100.             $users[$mails[1][$k]] = $user;
  101.         }
  102.         if (!$users)
  103.         {
  104.             return '您的邮箱中尚未有联系人';
  105.         }      
  106.         
  107.         return $users;
  108.         }
  109.         
  110.         /**
  111.     * Get Header info
  112.     */
  113.     private function _getheader($username)
  114.     {
  115.                 $ch = curl_init();
  116.                 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");
  117.                 curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);  //当前使用的cookie
  118.                 curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);   //服务器返回的新cookie
  119.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  120.                 curl_setopt($ch, CURLOPT_HEADER, true);
  121.                 curl_setopt($ch, CURLOPT_NOBODY, true);
  122.                 $content=curl_exec($ch);
  123.                
  124.                 preg_match_all('/Location:s*(.*?)rn/i',$content,$regs);
  125.         $refer = $regs[1][0];
  126.         preg_match_all('/http://(.*?)//i',$refer,$regs);               
  127.         $host = $regs[1][0];
  128.         preg_match_all("/sid=(.*)/i",$refer,$regs);
  129.         $sid = $regs[1][0];
  130.                
  131.                 curl_close($ch);
  132.                 return array('sid'=>$sid,'refer'=>$refer,'host'=>$host);
  133.     }
  134. }
  135.  
  136. ?>

相关标签:

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
go语言 注释编码
go语言 注释编码

本专题整合了go语言注释、注释规范等等内容,阅读专题下面的文章了解更多详细内容。

32

2026.01.31

go语言 math包
go语言 math包

本专题整合了go语言math包相关内容,阅读专题下面的文章了解更多详细内容。

23

2026.01.31

go语言输入函数
go语言输入函数

本专题整合了go语言输入相关教程内容,阅读专题下面的文章了解更多详细内容。

16

2026.01.31

golang 循环遍历
golang 循环遍历

本专题整合了golang循环遍历相关教程,阅读专题下面的文章了解更多详细内容。

5

2026.01.31

Golang人工智能合集
Golang人工智能合集

本专题整合了Golang人工智能相关内容,阅读专题下面的文章了解更多详细内容。

6

2026.01.31

2026赚钱平台入口大全
2026赚钱平台入口大全

2026年最新赚钱平台入口汇总,涵盖任务众包、内容创作、电商运营、技能变现等多类正规渠道,助你轻松开启副业增收之路。阅读专题下面的文章了解更多详细内容。

268

2026.01.31

高干文在线阅读网站大全
高干文在线阅读网站大全

汇集热门1v1高干文免费阅读资源,涵盖都市言情、京味大院、军旅高干等经典题材,情节紧凑、人物鲜明。阅读专题下面的文章了解更多详细内容。

195

2026.01.31

无需付费的漫画app大全
无需付费的漫画app大全

想找真正免费又无套路的漫画App?本合集精选多款永久免费、资源丰富、无广告干扰的优质漫画应用,涵盖国漫、日漫、韩漫及经典老番,满足各类阅读需求。阅读专题下面的文章了解更多详细内容。

170

2026.01.31

漫画免费在线观看地址大全
漫画免费在线观看地址大全

想找免费又资源丰富的漫画网站?本合集精选2025-2026年热门平台,涵盖国漫、日漫、韩漫等多类型作品,支持高清流畅阅读与离线缓存。阅读专题下面的文章了解更多详细内容。

85

2026.01.31

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Excel 教程
Excel 教程

共162课时 | 15万人学习

Pandas 教程
Pandas 教程

共15课时 | 1万人学习

C# 教程
C# 教程

共94课时 | 8.2万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号