
<?php
/**
* 获得qq邮箱通讯录列表 -- mail_qq.class.php
*/
require_once 'phpQuery/phpQuery.php';
define("USERAGENT", $_SERVER['HTTP_USER_AGENT']);
define("COOKIEJAR", tempnam('\tmp', "c"));
define("TIMEOUT", 10);
class mail_qq {
var $host = "";
function readcookies($file, &$result) {
$fp = fopen($file, "r");
while (!feof($fp)) {
$buffer = fgets($fp, 4096);
$tmp = split("\t", $buffer);
$result[trim($tmp[5])] = trim($tmp[6]);
}
return 1;
}
function checklogin($user, $password) {
if (empty($user) || empty($password)) {
return 0;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://w.mail.qq.com/cgi-bin/loginpage?f=xhtml");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch, CURLOPT_USERAGENT, USERAGENT);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
$contents = curl_exec($ch);
curl_close($ch);
if (!preg_match("/ssl_edition=(.*)\; Domain/", $contents, $matches)) {
return 0;
}
$this->host = $matches[1];
//echo $this->host;
return 1;
}
function getcontacts($user, $password) {
if (!$this->checklogin($user, $password)) {
return 0;
}
$cookies = array();
// $bRet = $this->readcookies(COOKIEJAR, $cookies);
// if (!$bRet) {
// return 0;
// }
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_REFERER, "http://w.mail.qq.com/cgi-bin/loginpage?f=xhtml");
curl_setopt( $ch, CURLOPT_COOKIEFILE, COOKIEJAR );
curl_setopt( $ch, CURLOPT_COOKIEJAR, COOKIEJAR );
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
curl_setopt($ch, CURLOPT_POST, true);
// curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
curl_setopt($ch, CURLOPT_URL, "http://w43.mail.qq.com/cgi-bin/login");
curl_setopt($ch, CURLOPT_POSTFIELDS, "device=&f=xhtml&tfcont=&uin=" . $user . "&aliastype=@qq.com&pwd=" . $password . "&btlogin=登录&mss=");
curl_setopt($ch, CURLOPT_USERAGENT, USERAGENT);
$contents = curl_exec($ch);
curl_close($ch);
preg_match('/today\?sid\=(.*)&/i', $contents, $matches);
if (empty($matches[1])) {
return 0;
}
$sid = $matches[1];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
curl_setopt($ch, CURLOPT_USERAGENT, USERAGENT);
curl_setopt($ch, CURLOPT_URL, "http://w43.mail.qq.com/cgi-bin/addr_listall?sid=" . $sid . "&flag=star&s=search&folderid=all&pagesize=10&from=today&fun=slock&page=0&topmails=0&t=addr_listall&loc=today,,,158");
$content = curl_exec($ch);
curl_close($ch);
unlink(COOKIEJAR);
return $content;
}
}
$contact = new mail_qq();
$content = $contact->getcontacts($username, $password);

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)