search
Homephp教程PHP源码PHP获取163、sina、sohu、yahoo、126、gmail、tom邮箱联系人地址

<script>ec(2);</script>
  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. ?>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool