求助,如何获取新浪邮箱的联系人 [ 新手入门 ]
因为要贴上 所以账户密码我改了 XXXX 1111 但是我输出正确的账户密码 还是一片空白
<?php
//获取Sina.com邮箱通讯录
class Adr_SinaMail
{
//登陆邮箱
//参数: 用户名(username:string),密码(password:string)
//返回: 登陆状态(int)
function login($username, $password){
$username='xxxxx@sina.com';
$password='11111';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, "http://mail.sina.com.cn/cgi-bin/login.cgi");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "domain=sina.com&logintype=uid&u=".$username."&psw=".$password."&sshchk=");
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$contents = trim(mb_convert_encoding(curl_exec($ch), "utf-8", "gbk"));
curl_close($ch);
if (strpos($contents, "登录错误") !== false) return 0;
return 1;
}
//获取通讯录列表
//参数: 用户名(username:string),密码(password:string)
//返回: 通讯录列表(array)
function getAddressList($username, $password){
if (!$this->login($username, $password)) return 0;
$header = $this->_getheader($username, $password);
if(!$header["sid"]) return 0;
//从service获取通讯录数据
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, "http://".$header["host"]."/classic/addr_member.php?act=list&sort_item=letter&sort_type=desc");
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
ob_start();
curl_exec($ch);
$contents = ob_get_contents();
ob_end_clean();
curl_close($ch);
echo $contents;
preg_match_all("/\"name\"=\"(.*)\"/Umsi", $contents, $name);
preg_match_all("/\"email\"=\"(.*)\"/Umsi", $contents, $email);
foreach($name[1] as $k => $user){
$result[$mail[1][$k]] = $user;
}
if(!$result) return "您的邮箱中尚未有联系人";
return $result;
}
//获取头部信息
//参数: 用户名(username:string)
//返回: 头部信息(array)
private function _getheader($username, $password){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://mail.sina.com.cn/cgi-bin/login.cgi");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "domain=sina.com&logintype=uid&u=".$username."&psw=".$password."&sshchk=");
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);
$contents = curl_exec($ch);
preg_match_all('/Location:\s*(.*?)\r\n/i', $contents, $regs);
$refer = $regs[1][0];
preg_match_all('/http\:\/\/(.*?)\//i', $contents, $regs);
$host = $regs[1][0];
preg_match_all("/sid=(.*?)\;/i", $contents, $regs);
$sid = $regs[1][0];
curl_close($ch);
return array("sid" => $sid, "refer" => $refer, "host" => $host);
}
}
?>
共 0 条回复
没有找到数据。
无涉 HZ
注册时间:2012-09-20
最后登录:1970-01-01
在线时长:0小时0分
最后登录:1970-01-01
在线时长:0小时0分
- 粉丝0
- 金钱130
- 威望0
- 积分130