2018年04月6日网站服务器迁移完成……

php curl 导出163邮箱联系人 代码

php 苏 demo 3032℃ 0评论

<?php
header(“Content-Type:text/html;charset=utf-8″);
clearstatcache();
function import_contacts($username, $password) {
$cookie_jar = tempnam(‘./tmp’,’cookie’);
$cookie_jar2 = tempnam(‘./tmp’,’cookie2′);
$cookie_jar3 = tempnam(‘./tmp’,’cookie3′);
$ch = curl_init();
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’);
curl_setopt($ch, CURLOPT_POST, 1);
$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′;
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
//把返回来的cookie信息保存在$cookie_jar文件中
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
//设定返回的数据是否自动显示
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//设定是否显示头信息
curl_setopt($ch, CURLOPT_HEADER, false);
//设定是否输出页面内容
curl_setopt($ch, CURLOPT_NOBODY, false);
$html=curl_exec($ch);
curl_close($ch);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ‘http://fm163.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=16&username=’.$username);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar2);
$html=curl_exec($ch);
curl_close($ch);

//echo $name; 33.
$find1 = ‘sid=’;
$find2 = ‘”>here’;
$pos1 = strpos($html, $find1);
$pos2 = strpos($html, $find2);
$l=$pos2-$pos1-4;
//echo substr($html, $pos1+4,$l);
$sess=substr($html, $pos1+4,$l);

$ch2 = curl_init();
//curl_setopt($ch2, CURLOPT_URL, ‘http://mail3-13.sinamail.sina.com.cn/cgismarty/addr_member_list.php’);
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’);
//导出联系URL
/*curl_setopt($ch2, CURLOPT_URL, ‘http://g1a3.mail.163.com/coremail/fcg/ldvcapp?
funcid=xportadd
sid=’.$sess.’
ifirstv=&group=
outformat=8&outport.x=%BF%AA%CA%BC%B5%BC%B3%F6′);*/
curl_setopt($ch2, CURLOPT_HEADER, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_jar2);
$html = curl_exec($ch2);
$html=str_replace(“\n”,””,$html);
//echo $html;
curl_close($ch2);
preg_match_all(‘/<!– 修改 –>(.*?)<\/td>/’,$html,$name);
preg_match_all(‘/<!– 发信 –>(.*?)<\/a>/’,$html,$mail);
//print_r($name[0]);
//print_r($mail[0]);
//echo count($mail[0]);
$users = array();

for($i=0; $i<count($mail[0])&& (!empty($mail[0][$i])); $i++){
$str = iconv( ‘GB2312’, ‘UTF-8’, $name[0][$i] );//转换编码
$users[] = array (
0=>trim(strip_tags($str)),
1=>trim(strip_tags($mail[0][$i]))
);

}
return $users;
}
$username = “”;//email
$password = “”;//password
$results = import_contacts($username,$password);
print_r($results);
?>

打赏

转载请注明:苏demo的别样人生 » php curl 导出163邮箱联系人 代码

   如果本篇文章对您有帮助,欢迎向博主进行赞助,赞助时请写上您的用户名。
支付宝直接捐助帐号oracle_lee@qq.com 感谢支持!
喜欢 (0)or分享 (0)
发表我的评论
取消评论
表情