获取邮箱联系人 FOR 163 BY PHP

 
  1. <?php
  2. function import_contacts($username$password) {
  3.     $cookie_jar = tempnam('./tmp','cookie');
  4.     $cookie_jar2 = tempnam('./tmp','cookie2');
  5.     $cookie_jar3 = tempnam('./tmp','cookie3');
  6.     $ch = curl_init();
  7.     curl_setopt($ch, CURLOPT_URL, 'http://reg.163.com/login.jsp?type=1&url=http://fm163.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D16');
  8.     curl_setopt($ch, CURLOPT_POST, 1);
  9.     $request = 'verifycookie=1&username='.$username.'&password='.$password.'&selType=jy&%B5%C7%C2%BC%D3%CA%CF%E4=%B5%C7%C2%BC%D3%CA%CF%E4&style=16&product=mail163';
  10.     curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
  11.     //把返回来的cookie信息保存在$cookie_jar文件中
  12.     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
  13.     //设定返回的数据是否自动显示
  14.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  15.     //设定是否显示头信息
  16.     curl_setopt($ch, CURLOPT_HEADER, false);
  17.     //设定是否输出页面内容
  18.     curl_setopt($ch, CURLOPT_NOBODY, false);
  19.     $html=curl_exec($ch);
  20.     curl_close($ch);
  21.     
  22.     
  23.     $ch = curl_init();
  24.     curl_setopt($ch, CURLOPT_URL, 'http://fm163.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=16&username='.$username);
  25.     curl_setopt($ch, CURLOPT_HEADER, false);
  26.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  27.     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
  28.     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar2);
  29.     $html=curl_exec($ch);
  30.     curl_close($ch);
  31.     
  32.     //echo $name;
  33.     
  34.     $find1   = 'sid=';
  35.     $find2   = '">here';
  36.     $pos1 = strpos($html$find1);
  37.     $pos2 = strpos($html$find2);
  38.     $l=$pos2-$pos1-4;
  39.     //echo substr($html, $pos1+4,$l);
  40.     $sess=substr($html$pos1+4,$l);
  41.     
  42.     $ch2 = curl_init();
  43.     //curl_setopt($ch2, CURLOPT_URL, 'http://mail3-13.sinamail.sina.com.cn/cgismarty/addr_member_list.php');
  44.     curl_setopt($ch2, CURLOPT_URL, 'http://g1a5.mail.163.com/coremail/fcg/ldvcapp?funcid=address&sid='.$sess.'&tempname=address%2Faddress.htm&ifirstv=&listnum=0&showlist=all');
  45.     //导出联系URL
  46.     /*curl_setopt($ch2, CURLOPT_URL, 'http://g1a3.mail.163.com/coremail/fcg/ldvcapp?
  47.     funcid=xportadd
  48.     sid='.$sess.'
  49.     ifirstv=&group=
  50.     outformat=8&outport.x=%BF%AA%CA%BC%B5%BC%B3%F6');*/
  51.     curl_setopt($ch2, CURLOPT_HEADER, false);
  52.     curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
  53.     curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_jar2);
  54.     $html = curl_exec($ch2);
  55.     $html=str_replace("/n","",$html); 
  56.     //echo $html;
  57.     
  58.     curl_close($ch2);
  59.       preg_match_all('/<!-- 修改 -->(.*?)<//td>/',$html,$name);
  60.       preg_match_all('/<!-- 发信 -->(.*?)<//a>/',$html,$mail);
  61.       //print_r($name[0]);
  62.       //print_r($mail[0]);
  63.       //echo count($mail[0]);
  64.       $users = array();
  65.       
  66.       for($i=0; $i<count($mail[0])&& (!empty($mail[0][$i])); $i++){
  67.         $str = iconv( 'GB2312''UTF-8'$name[0][$i] );//转换编码
  68.         $users[] = array (
  69.             0=>trim(strip_tags($str)),
  70.             1=>trim(strip_tags($mail[0][$i]))
  71.         );
  72.         
  73.       }
  74.       return $users;
  75. }
  76. //$results = import_contacts($_POST['username'],$_POST['password']);
  77. //print_r($results);
  78. ?>

你可能感兴趣的:(html,header,jar,url,import,tags)