//获取Sina.com邮箱通讯录
class Adr_SinaMail
{
//登陆邮箱
//参数: 用户名(username:string),密码(password:string)
//返回: 登陆状态(int)
function login($username, $password){
$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);
}
}
这是我按网上搜的获取163邮箱改的 登陆成功 获取那3个参数也成功
但获取通讯录列表时 好像用户信息没传过去 返回是info:null
有什么办法能把用户信息传过去