php使用curl抓取qq空间的访客信息示例
config.php
<?php
define('app_dir', dirname(__file__));
define('cookie_file', app_dir . '/app.cookie.txt'); //会话记录文件
define('visitor_capture_interval', 3); //qq采集间隔
define('visitor_data_upload_interval', '');
define('this_time', time());
define('request_timeout', 20); //请求超时20秒
define('end_line', "\n");
define('debug', true); //开启调试
$login_users = array(
array('user' => '2064556526', 'password' => '909124951'),
array('user' => '483258700', 'password' => '909124951'),
array('user' => '1990270522', 'password' => '909124951'),
array('user' => '2718711637', 'password' => '909124951'),
array('user' => '2841076562', 'password' => '909124951'),
);
qy.visitor.php
<?php
include('./config.php');
include(app_dir . '/qy.visitor.php');
$sessions = array();
$user = $login_users[array_rand($login_users)];
$visitor_capture = new qqvisitorcapture($user['user'], $user['password'], cookie_file, request_timeout, debug, end_line);
$visitors = $visitor_capture->getvisitorinfo();
if (empty($visitors)) {
$this->clearcookies(true);
} else {
$cckf_service = new cckfservice(security_key,service_id,service_address,'', request_timeout, debug, end_line);
}
qy.class.php
<?php
class trace
{
public static function nl($num = 1)
{
$str = '';
for ($i = 0; $i < $num; $i++) {
$str .= "\n";
}
return $str;
}
public static function br($num = 1)
{
$str = '';
for ($i = 0; $i < $num; $i++) {
$str .= "<br/>";
}
return $str;
}
public static function write($content, $end_line, $title = null)
{
$close = '^^^^^^^^^^^^^^^^^';
if ($title) {
$start = '--------' . $title . '---------';
} else {
$start = '-----------------';
}
echo $start . $end_line;
if (is_array($content)) {
print_r($content);
echo $end_line;
} else {
echo $content;
echo $end_line;
}
if (empty($content)) {
echo $end_line;
} else {
echo $close . $end_line;
}
}
}
class utils
{
public static function getmicrotime()
{
list($mic, $time) = explode(" ", microtime());
return intval($time) + floatval(sprintf('%.3f', $mic));
}
public static function getutcmilliseconds()
{
return round(rand(1, 9) / 10 * 2147483647) * round(1, 999) % 10000000000;
}
public static function decodeuricomponent($content)
{
return urldecode(preg_replace("/\\\\x([0-9a-z]{2,3})/i", "%$1", $content));
}
public static function jsrandom()
{
list($mic, $time) = explode(" ", microtime());
return $mic;
}
function loginjstime()
{
list($mic, $time) = explode(" ", microtime());
return $time . sprintf('%3d', $mic * 1000);
}
protected static function utf8_unicode($c)
{
switch (strlen($c)) {
case 1:
return ord($c);
case 2:
$n = (ord($c[0]) & 0x3f) << 6;
$n += ord($c[1]) & 0x3f;
return $n;
case 3:
$n = (ord($c[0]) & 0x1f) << 12;
$n += (ord($c[1]) & 0x3f) << 6;
$n += ord($c[2]) & 0x3f;
return $n;
case 4:
$n = (ord($c[0]) & 0x0f) << 18;
$n += (ord($c[1]) & 0x3f) << 12;
$n += (ord($c[2]) & 0x3f) << 6;
$n += ord($c[3]) & 0x3f;
return $n;
}
}
public static function getgtk($str)
{
$hash = 5381;
for ($i = 0, $len = strlen($str); $i < $len; ++$i) {
$hash += ($hash << 5) + self::utf8_unicode($str[$i]);
}
return $hash & 2147483647;
}
protected static function hexchar2bin($str)
{
$arr = '';
$temp = null;
for ($i = 0; $i < strlen($str); $i = $i + 2) {
$arr .= "\\x" . substr($str, $i, 2);
}
eval('$temp="' . $arr . '";');
return $temp;
}
protected static function getuid($uid)
{
$temp = null;
eval('$temp="' . $uid . '";');
return $temp;
}
public static function getencryption($password, $uin, $vcode)
{
$uin = self::getuid($uin);
$str1 = self::hexchar2bin(strtoupper(md5($password)));
$str2 = strtoupper(md5($str1 . $uin));
return strtoupper(md5($str2 . strtoupper($vcode)));
}
}
class cookiefileextract
{
protected $cookie_file;
protected $cookie_list;
protected function __construct($cookie_file)
{
$this->cookie_file = $cookie_file;
$this->cookie_list = $this->extractfile();
}
protected function isvalidatecookiefile()
{
if ($this->cookie_file && file_exists($this->cookie_file)) {
return true;
} else {
return false;
}
}
protected function extractfile()
{
$cookie_list = array();
if ($this->isvalidatecookiefile($this->cookie_file)) {
$content = file($this->cookie_file);
if (is_array($content)) {
foreach ($content as $line) {
$line = trim($line);
if (strlen($line) > 0 && $line[0] != '#') {
$cookie = (preg_split("/\s+/", $line));
if (count($cookie) == 7) {
$cookie_list[$cookie[5]] = $cookie[6];
} else {
$cookie_list[$cookie[5]] = '';
}
}
}
}
}
return $cookie_list;
}
protected function buildcookiestr($cookies)
{
$arr = array();
if (is_array($cookies)) {
foreach ($cookies as $k => $cookie) {
$line = $cookie['domain'] . "\t" . "true" . "\t" . $cookie['path'] . "\t" . "false" . "\t" . $cookie['expires'] . "\t" . $k . "\t" . $cookie['value'];
$arr[] = $line;
}
}
return $arr;
}
protected function __setcookies($cookies)
{
$new_line = array();
if (is_array($cookies)) {
if ($this->isvalidatecookiefile($this->cookie_file)) {
$content = file($this->cookie_file);
if (is_array($content)) {
foreach ($content as $line) {
$line = trim($line);
if (strlen($line) > 0 && $line[0] != '#') {
$cookie = (preg_split("/\s+/", $line));
if (!in_array($cookie[5], $cookies)) {
$new_line[] = $line;
}
} else {
$new_line[] = $line;
}
}
}
}
file_put_contents($this->cookie_file, implode("\n", array_merge($new_line, $this->buildcookiestr($cookies))));
}
}
protected function __getallcookies($refresh = false)
{
if ($refresh) {
$this->cookie_list = $this->extractfile();
}
return $this->cookie_list;
}
protected function __getcookie($cookie_name, $refresh = false)
{
$cookie_list = $this->__getallcookies($refresh);
if (is_array($cookie_list) && array_key_exists($cookie_name, $cookie_list)) {
return $cookie_list[$cookie_name];
} else {
return null;
}
}
protected function __clearallcookies()
{
$this->cookie_list = null;
@unlink($this->cookie_file);
}
}
class baserequest extends cookiefileextract
{
protected $curl_instance;
protected $request_timeout;
protected $debug;
protected $end_line;
protected $user_agent = 'mozilla/5.0 (x11; ubuntu; linux i686; rv:26.0) gecko/20100101 firefox/26.0';
protected function __construct($cookie_file, $request_timeout, $debug, $end_line)
{
parent::__construct($cookie_file);
$this->request_timeout = $request_timeout;
$this->debug = $debug;
$this->end_line = $end_line;
$this->initinstance();
}
protected function initinstance()
{
$this->curl_instance = curl_init();
if ($this->isvalidatecookiefile()) {
curl_setopt($this->curl_instance, curlopt_cookiejar, $this->cookie_file);
curl_setopt($this->curl_instance, curlopt_cookiefile, $this->cookie_file);
}
curl_setopt($this->curl_instance, curlopt_timeout, $this->request_timeout);
curl_setopt($this->curl_instance, curlopt_returntransfer, 1);
curl_setopt($this->curl_instance, curlopt_header, 1);
curl_setopt($this->curl_instance, curlopt_ssl_verifypeer, false);
curl_setopt($this->curl_instance, curlopt_ssl_verifyhost, 0);
curl_exec($this->curl_instance);
}
function setcookies($cookies)
{
$this->closeinstance();
$this->__setcookies($cookies);
$this->initinstance();
}
protected function getallcookies($refresh = false)
{
$this->closeinstance();
$cookies = $this->__getallcookies($refresh);
$this->initinstance();
return $cookies;
}
protected function clearallcookies($refresh = false)
{
$this->closeinstance();
$this->__clearallcookies();
if ($refresh) {
$this->initinstance();
}
}
protected function getcookie($name, $refresh = false)
{
$this->closeinstance();
$cookie = $this->__getcookie($name, $refresh);
$this->initinstance();
return $cookie;
}
protected function getrequestinstance()
{
return $this->curl_instance;
}
protected function closeinstance()
{
if (is_resource($this->curl_instance)) {
curl_close($this->curl_instance);
}
}
protected function resetinstance()
{
$this->closeinstance();
@unlink($this->cookie_file);
$this->initinstance();
}
protected function requestexec($option)
{
curl_setopt_array($this->getrequestinstance(), $option);
//if ($this->debug) {
// $result = curl_exec($this->getrequestinstance());
// trace::write($result, $this->end_line, 'request output');
//} else {
return curl_exec($this->getrequestinstance());
//}
}
}
class qqvisitorrequest extends baserequest
{
protected $user;
protected $password;
protected function __construct($user, $password, $cookie_file, $request_timeout, $debug, $end_line)
{
parent::__construct(dirname($cookie_file) . '/' . $user . '.' . basename($cookie_file), $request_timeout, $debug, $end_line);
$this->user = $user;
$this->password = $password;
}
}
class resultextract
{
public static function getcorejsinfo($content, $user)
{
$arr = array();
preg_match('/cfg\s*=\s*\{(.*?)\s*\}\s*,\s*url_param_hash/s', $content, $m);
if (count($m) > 0) {
$f = preg_replace('/\s*/', '', $m[1]);
$f = preg_replace('/"\+g\_iloginuin\+"/', $user, $f);
$f = preg_replace('/\$j\.cookie.get\("hotfeeds_closed"\)==1\?""\:/', '', $f);
$f = explode(",", $f);
if (count($f) > 0) {
foreach ($f as $t) {
$t = trim($t);
$p = strpos($t, ':');
$key = trim(substr($t, 0, $p), '"');
$value = trim(substr($t, $p + 1), '"');
if ($key) {
$arr[$key] = $value;
}
}
if (count($arr) > 0) {
$arr['visitor'] = $arr;
}
}
}
return $arr;
}
public static function enterqzonesuccess($content)
{
$arr = array();
$arr2 = array();
preg_match('/g_data\s*=\s*{\s*feedspart1\s*:\s*(.*?)\s*,\s*feedspart2/s', $content, $m);
if (count($m) > 0) {
$f = preg_replace('/\s*/', '', $m[1]);
$f = preg_replace('/([\{,])([^,]*?)(\:)/', '$1"$2"$3', $f);
$f = preg_replace('/:\'(.*?)\'([,\}])/', ':"$1"$2', $f);
$arr = json_decode($f, true);
$arr = $arr['main'];
}
preg_match('/g_type.*?g_izone_flag/s', $content, $m);
if (count($m) > 0) {
$f = preg_replace('/\s*/', '', $m[0]);
$f = explode(",", $f);
foreach ($f as $t) {
$t = trim($t);
$p = strpos($t, '=');
$key = trim(substr($t, 0, $p));
$value = trim(substr($t, $p + 1), '"');
if ($key) {
$arr2[$key] = $value;
}
}
}
return array_merge($arr, $arr2);
}
public static function getloginjsinfo($content)
{
$s = preg_replace('/.*?pt\.plogin\s*=\s*\{(.*?)aqscanlink.*/s', '$1', $content);
preg_match('/.*js_type\s*:\s*(\d+)\s*,.*/', $s, $m);
if (count($m) > 1) {
return array('js_type' => $m[1]);
}
return array();
}
public static function getloginaddress($content)
{
preg_match('/.*?<\s*iframe\s*id\s*=\s*"login_frame"\s*name\s*=\s*"login_frame".*?src\s*=\s*"(.*?xui\.ptlogin2\.qq\.com.*?)".*?>\s*<\/iframe>.*?/', $content, $m);
if (count($m) > 1) {
return html_entity_decode($m[1]);
}
return null;
}
public static function checkloginsuccess($content)
{
preg_match_all('/.*?\((.*)\).*?/', $content, $match);
if ($match[1][0]) {
$g = explode(',', $match[1][0]);
if (count($g) > 1) {
if (($g[count($g) - 2]) == "'登录成功!'") {
$url_parts = parse_url($g[2]);
parse_str($url_parts['query'], $arr);
if (array_key_exists('ptsig', $arr)) {
$ptsig = $arr['ptsig'];
} else {
$ptsig = null;
}
return array('status' => true, 'value' => array('url' => $g[2], 'ptsig' => $ptsig));
}
}
}
return array('status' => false);
}
public static function rightframevisitors($content)
{
$visitor_list = array();
$f = preg_replace('/\s*/', '', $content);
$f = preg_replace('/.*?_callback\((\{.*?\})\).*?/', '$1', $f);
$f = json_decode($f, true);
if (is_array($f) && count($f) > 0 && array_key_exists('data', $f)
&& array_key_exists('module_3', $f['data'])
&& array_key_exists('data', $f['data']['module_3'])
&& array_key_exists('items', $f['data']['module_3']['data'])
) {
$visitors = $f['data']['module_3']['data']['items'];
foreach ($visitors as $visitor) {
if (!array_key_exists('loc', $visitor)) {
$visitor_list [] = array(
'uin' => $visitor['uin'], 'name' => $visitor['name'], 'online' => $visitor['online'], 'time' => $visitor['time'],
'img' => $visitor['img'], 'yellow' => $visitor['yellow'], 'supervip' => $visitor['supervip'],
);
}
}
}
return $visitor_list;
}
public static function getvisitors($content)
{
$f = preg_replace('/\s*/', '', $content);
preg_match('/^.*?(\{.*?\})\);\s*$/', $f, $m);
$visitor_list = array();
if (is_array($m) && count($m) > 1 && strlen($m[1]) > 0) {
$visitors = json_decode(trim($m[1]), true);
if (array_key_exists('data', $visitors) && array_key_exists('items', $visitors['data'])) {
foreach ($visitors['data']['items'] as $visitor) {
if ($visitor['name']) {
$_ = array(
'uin' => $visitor['uin'], 'name' => $visitor['name'], 'time' => $visitor['time'],
'yellow' => $visitor['yellow'], 'supervip' => $visitor['supervip'],
);
if (array_key_exists('portraitlabel', $visitor)) {
$_['portraitlabel'] = $visitor['portraitlabel'];
}
$visitor_list[] = $_;
if (array_key_exists('uins', $visitor)) {
foreach ($visitor['uins'] as $uins) {
$_ = array(
'uin' => $uins['uin'], 'name' => $uins['name'], 'time' => $uins['time'],
'yellow' => $uins['yellow'], 'supervip' => $uins['supervip'],
);
if (array_key_exists('portraitlabel', $uins)) {
$_['portraitlabel'] = $uins['portraitlabel'];
}
$visitor_list[] = $_;
}
}
}
}
}
}
return $visitor_list;
}
public static function checkvc($content)
{
preg_match_all('/.*?\((.*)\).*?/', $content, $match);
if (strlen($match[1][0]) > 1) {
$m = str_replace("'", '', $match[1][0]);
$g = explode(',', $m);
if (count($g) == 3) {
return array('saltuin' => $g[2], 'verifycode' => $g[1], 'rsakey' => $g[2] ? false : true);
}
}
return array();
}
public static function getlogininfo($content)
{
$s = preg_replace('/.*?pt\.ptui\s*=\s*\{(.*?)\}\s*;.*/s', '$1', $content);
$e = preg_split('/,\s*/', trim($s));
$info = array();
foreach ($e as $t) {
$t = trim($t);
$p = strpos($t, ':');
$key = trim(substr($t, 0, $p));
$value = trim(substr($t, $p + 1));
if (preg_match('/encodeuricomponent/', $value)) {
$value = preg_replace('/^encodeuricomponent\s*\(\s*"(.*)?"\s*\)\s*,?$/', '$1', $value);
} else {
$value = trim($value, '",');
}
if ($key) {
$info[$key] = urldecode($value);
}
}
return $info;
}
}
class qqvisitorcapture extends qqvisitorrequest
{
public function __construct($user, $password, $cookie_file, $request_timeout, $debug, $end_line)
{
parent:: __construct($user, $password, $cookie_file, $request_timeout, $debug, $end_line);
}
public function trace($content, $title)
{
if ($this->debug = true) {
trace:: write($content, $this->end_line, $title);
}
}
public function error($message)
{
$this->trace($message, 'login error ');
return false;
}
public function success()
{
return true;
}
public function getgtkencryption()
{
return utils ::getgtk($this->getcookie('skey', true));
}
public function getcookies($refresh = false)
{
return $this->getallcookies($refresh);
}
public function clearcookies($refresh = false)
{
return $this->clearallcookies($refresh);
}
public function login()
{
$login_submit_info_url = null;
$login_submit_info_url = $this->visitqzone();
$this->setcookies(array(
'pgv_pvid' => array(
'value' => utils::getutcmilliseconds(), 'path' => '/', 'domain' => '.qq.com', 'expires' => '0'
),
'pgv_info' => array(
'value' => 'ssid=s' . utils::getutcmilliseconds(), 'path' => '/', 'domain' => '.qq.com', 'expires' => '0'
),
'_qz_referrer' => array(
'value' => 'qzone.qq.com', 'path' => '/', 'domain' => '.qq.com', 'expires' => '0'
),
));
//log
$this->trace('', 'login begin');
//log
$this->trace($login_submit_info_url, '$login_submit_info_url===');
$login_submit_info = $this->getloginsubmitinfo($login_submit_info_url);
//log
$this->trace($login_submit_info, '$login_submit_info===');
if (empty($login_submit_info)) {
$this->error('err-001');
}
$this->report();
//log
$this->trace('', 'getloginjs');
$js_arr = $this->getloginjs();
//log
$this->trace($js_arr, '$getloginjs===');
if (empty($js_arr)) {
$this->error('err-002');
}
$u = $uin = $this->user;
$r = utils::jsrandom();
$verifycode = null;
$pt_rsa = null;
$ptredirect = $login_submit_info['target'];
$h = $t = $g = $from_ui = 1;
$p = null;
$regmaster = $login_submit_info['regmaster'];
$u1 = utils::decodeuricomponent($login_submit_info['s_url']);
$ptlang = $login_submit_info['lang'];
$action = strval(rand(5, 9)) . '-' . strval(strlen($this->user) + strlen($this->password) + rand(1, 5)) . '-' . utils::loginjstime();
$js_ver = $login_submit_info['ptui_version'];
$js_type = $js_arr['js_type'];
$login_sig = $login_submit_info['login_sig'];
$appid = $aid = $login_submit_info['appid'];
$pt_qzone_sig = $login_submit_info['pt_qzone_sig'];
$daid = $login_submit_info['daid'];
//log
$this->trace('', 'checkvc');
$check_data = $this->checkvc($regmaster, $appid, $js_ver, $js_type, $login_sig, $u1, $r);
if (count($check_data) !== 3) {
$this->error('err-003');
}
//log
$this->trace($check_data, '$check_data===');
//log
$this->trace(json_encode($check_data), '$check_data===');
$verifycode = $check_data['verifycode'];
if ($check_data['rsakey']) {
$this->error('err-004');
} else {
$p = utils::getencryption($this->password, $check_data['saltuin'], $verifycode);
$pt_rsa = 0;
}
//log
$this->trace('', 'submitlogin');
$this->setcookies(array(
'ptui_loginuin' => array(
'value' => $this->user, 'path' => '/', 'domain' => '.qq.com', 'expires' => '0'
),
));
$login_result = $this->submitlogin($verifycode, $p,
$pt_rsa, $ptredirect, $u1,
$h, $t, $g, $from_ui,
$ptlang, $action, $js_ver, $js_type,
$login_sig, $aid, $daid, $pt_qzone_sig);
if ($login_result['status']) {
$this->trace('登录成功', 'submitlogin');
$this->trace($login_result, '$login_result====');
$this->loginsuccessredirect($login_result['value']['url']);
$this->setcookies(array(
'fnc' => array(
'value' => 1, 'path' => '/', 'domain' => '.qzone.qq.com', 'expires' => '0'
),
));
$enterqzoneinfo = $this->enterqzone($login_result['value']['url'], $login_result['value']['ptsig']);
//log
$this->trace($enterqzoneinfo, '$enterqzoneinfo===');
if ($enterqzoneinfo) {
$this->trace('进入空间', 'enterqzone');
//$referer = $login_result['value']['url'];
//$scope = 0;
//log
$this->trace('', 'getcorejs');
$corejsinfo = $this->getcorejs();
$this->trace($corejsinfo, 'getcorejs===');
$this->setcookies(array(
'qzone_referer' => array(
'value' => $login_result['value']['url'], 'path' => '/', 'domain' => '.local.cckf123456789.com', 'expires' => '0'
),
'qzone_visitor_param' => array(
'value' => implode('|', array_values($corejsinfo['visitor'])), 'path' => '/', 'domain' => '.local.cckf123456789.com', 'expires' => '0'
),
));
//log
//$this->trace('', 'rightframevisitor');
//print_r($this->rightframevisitor($referer, implode('|', array_values($corejsinfo['visitor']))));
return $this->success();
} else {
$this->error('err-006');
}
} else {
$this->error('err-005');
}
}
protected function visitqzone()
{
$options = array(
curlopt_timeout => $this->request_timeout,
curlopt_header => 1,
curlopt_returntransfer => 1,
curlopt_url => 'http://qzone.qq.com',
curlopt_httpheader => array(
'referer:http://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=http%3a//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&pt_qzone_sig=1&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=http%3a//qzs.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=%e6%89%8b%e6%9c%baqq%e7%a9%ba%e9%97%b4&pt_qr_link=http%3a//z.qzone.com/download.html&self_regurl=http%3a//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http%3a//z.qzone.com/download.html',
'user-agent:' . $this->user_agent,
'host:qzone.qq.com',
'accept-language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3',
'connection:keep-alive',)
);
return resultextract::getloginaddress($this->requestexec($options));
}
protected function getloginjs()
{
$options = array(
curlopt_timeout => $this->request_timeout,
curlopt_header => 1,
curlopt_returntransfer => 1,
curlopt_url => 'http://imgcache.qq.com/ptlogin/ver/10067/js/c_login_old.js',
curlopt_httpheader => array(
'referer:http://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=http%3a//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&pt_qzone_sig=1&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=http%3a//qzs.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=%e6%89%8b%e6%9c%baqq%e7%a9%ba%e9%97%b4&pt_qr_link=http%3a//z.qzone.com/download.html&self_regurl=http%3a//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http%3a//z.qzone.com/download.html',
'user-agent:' . $this->user_agent,
'host:imgcache.qq.com',
'connection:keep-alive',)
);
return resultextract::getloginjsinfo($this->requestexec($options));
}
public function checkvc($regmaster, $appid, $js_ver, $js_type, $login_sig, $u1, $r)
{
$options = array(
curlopt_timeout => $this->request_timeout,
curlopt_header => 1,
curlopt_returntransfer => 1,
curlopt_url => 'http://check.ptlogin2.qq.com/check?' . http_build_query(array(
'regmaster' => $regmaster,
'uin' => $this->user,
'appid' => $appid,
'js_ver' => $js_ver,
'js_type' => $js_type,
'login_sig' => $login_sig,
'u1' => $u1,
'r' => $r,
)),
curlopt_httpheader => array(
'referer:http://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=http%3a//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&pt_qzone_sig=1&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=http%3a//qzs.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=%e6%89%8b%e6%9c%baqq%e7%a9%ba%e9%97%b4&pt_qr_link=http%3a//z.qzone.com/download.html&self_regurl=http%3a//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http%3a//z.qzone.com/download.html',
'user-agent:' . $this->user_agent,
'host:check.ptlogin2.qq.com',
'accept-language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3',
'connection:keep-alive',
)
);
return resultextract::checkvc($this->requestexec($options));
}
protected function report()
{
$url = 'http://ui.ptlogin2.qq.com/cgi-bin/report?id=358342&t=' . utils::jsrandom();
$options = array(
curlopt_timeout => $this->request_timeout,
curlopt_header => 1,
curlopt_returntransfer => 1,
curlopt_url => $url,
curlopt_httpheader => array(
'referer:http://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=http%3a//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&pt_qzone_sig=1&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=http%3a//qzs.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=%e6%89%8b%e6%9c%baqq%e7%a9%ba%e9%97%b4&pt_qr_link=http%3a//z.qzone.com/download.html&self_regurl=http%3a//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http%3a//z.qzone.com/download.html',
'user-agent:' . $this->user_agent,
'host:ui.ptlogin2.qq.com',
'connection:keep-alive',)
);
$this->requestexec($options);
}
protected function getloginsubmitinfo($url)
{
$options = array(
curlopt_timeout => $this->request_timeout,
curlopt_header => 1,
curlopt_returntransfer => 1,
curlopt_url => $url,
curlopt_httpheader => array(
'referer:http://qzone.qq.com/',
'user-agent:' . $this->user_agent,
'host:xui.ptlogin2.qq.com',
'connection:keep-alive',
)
);
return resultextract::getlogininfo($this->requestexec($options));
}
protected function submitlogin($verifycode, $p,
$pt_rsa, $ptredirect, $u1,
$h, $t, $g, $from_ui,
$ptlang, $action, $js_ver, $js_type,
$login_sig, $aid, $daid, $pt_qzone_sig)
{
$url = 'http://ptlogin2.qq.com/login';
$url .= '?' . http_build_query(array(
'u' => $this->user,
'verifycode' => $verifycode));
$url .= '&p=' . $p; ###
$url .= '&' . http_build_query(array(
'pt_rsa' => $pt_rsa,
'ptredirect' => $ptredirect,
'u1' => $u1,
'h' => $h,
't' => $t,
'g' => $g,
'from_ui' => $from_ui,
'ptlang' => $ptlang,
'action' => $action,
'js_ver' => $js_ver,
'js_type' => $js_type,
));
$url .= '&login_sig=' . $login_sig; ###
$url .= '&' . http_build_query(array(
'aid' => $aid,
'daid' => $daid,
'pt_qzone_sig' => $pt_qzone_sig));
$options = array(
curlopt_timeout => $this->request_timeout,
curlopt_header => 1,
curlopt_returntransfer => 1,
curlopt_url => $url,
curlopt_httpheader => array(
'referer:http://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=http%3a//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&pt_qzone_sig=1&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=http%3a//qzs.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=%e6%89%8b%e6%9c%baqq%e7%a9%ba%e9%97%b4&pt_qr_link=http%3a//z.qzone.com/download.html&self_regurl=http%3a//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http%3a//z.qzone.com/download.html',
'user-agent:' . $this->user_agent,
'host:ptlogin2.qq.com',
'accept-language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3',
'connection:keep-alive',
)
);
return resultextract::checkloginsuccess($this->requestexec($options));
}
public function loginsuccessredirect($url)
{
$options = array(
curlopt_timeout => $this->request_timeout,
curlopt_header => 1,
curlopt_returntransfer => 1,
curlopt_url => $url,
curlopt_httpheader => array(
'referer:http://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=http%3a//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&pt_qzone_sig=1&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=http%3a//qzs.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=%e6%89%8b%e6%9c%baqq%e7%a9%ba%e9%97%b4&pt_qr_link=http%3a//z.qzone.com/download.html&self_regurl=http%3a//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http%3a//z.qzone.com/download.html',
'user-agent:' . $this->user_agent,
'host:qzs.qq.com',
'accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'connection:keep-alive',
'dnt:1',
)
);
$this->requestexec($options);
}
public function enterqzone($referer, $ptsig)
{
$options = array(
curlopt_timeout => $this->request_timeout,
curlopt_header => 1,
curlopt_returntransfer => 1,
curlopt_url => 'http://user.qzone.qq.com/' . $this->user . '?ptsig=' . $ptsig,
curlopt_httpheader => array(
'referer:' . $referer,
'host:user.qzone.qq.com',
'connection:keep-alive',
)
);
return resultextract::enterqzonesuccess($this->requestexec($options));
}
public function getcorejs()
{
$options = array(
curlopt_timeout => $this->request_timeout,
curlopt_header => 1,
curlopt_returntransfer => 1,
curlopt_url => "http://ctc.qzonestyle.gtimg.cn/c/=/qzone/v8/engine/cpu.js,/qzone/v8/ic/qm.js,/qzone/v8/ic/tab_menu.js,/qzone/v8/ic/feeds.js,/qzone/v8/ic/tab_friend_feed.js,/qzone/v8/toolbar/core.js",
);
return resultextract::getcorejsinfo($this->requestexec($options), $this->user);
}
public function getvisitorinfo($mask = 7, $page = 1, $fupdate = 1, $clear = 1)
{
$options = array(
curlopt_timeout => $this->request_timeout,
curlopt_header => 1,
curlopt_returntransfer => 1,
curlopt_url => 'http://g.qzone.qq.com/cgi-bin/friendshow/cgi_get_visitor_more?' . http_build_query(array(
'uin' => $this->user,
'mask' => $mask,
'g_tk' => $this->getgtkencryption(),
'page' => $page,
'fupdate' => $fupdate,
'clear' => $clear,
'sd' => utils::jsrandom(),
)),
curlopt_httpheader => array(
'referer:http://ctc.qzs.qq.com/qzone/v6/friend_manage/visitors.html',
'user-agent:' . $this->user_agent,
'host:g.qzone.qq.com',
'connection:keep-alive',
)
);
return resultextract::getvisitors($this->requestexec($options));
}
public function rightframevisitor()
{
$param = utils ::getgtk($this->getcookie('qzone_visitor_param', true));
$referver = utils ::getgtk($this->getcookie('qzone_referer'));
$options = array(
curlopt_timeout => $this->request_timeout,
curlopt_header => 1,
curlopt_returntransfer => 1,
curlopt_url => 'http://r.qzone.qq.com/cgi-bin/right_frame.cgi?' . http_build_query(array(
'uin' => $this->user,
'param' => $param,
'g_tk' => $this->getgtkencryption(),
)),
curlopt_httpheader => array(
'referer:' . $referver,
'user-agent:' . $this->user_agent,
'host:r.qzone.qq.com',
'connection:keep-alive',
)
);
return resultextract::rightframevisitors($this->requestexec($options));
}
}
class cckfservicerequest extends baserequest
{
protected $service_address;
protected $service_id;
protected $security_key;
public function __construct($security_key, $service_id, $service_address, $cookie_file, $request_timeout, $debug, $end_line)
{
parent:: __construct($cookie_file, $request_timeout, $debug, $end_line);
$this->service_address = $service_address;
$this->service_id = $service_id;
$this->security_key = $security_key;
}
}
class cckfservice extends baserequest
{
public function __construct($security_key, $service_id, $service_address, $cookie_file, $request_timeout, $debug, $end_line)
{
parent:: __construct($security_key, $service_id, $service_address, $cookie_file, $request_timeout, $debug, $end_line);
}
public function uploaddata($data)
{
if (is_array($data) && !empty($data)) {
$options = array(
curlopt_timeout => $this->request_timeout,
curlopt_header => 1,
curlopt_returntransfer => 1,
curlopt_url => $this->service_address . '?' . http_build_query(array()),
);
}
}
}
class baseconfigfileutils
{
protected $file;
public function __construct($file)
{
$this->file = $file;
}
public function extractfile()
{
$f_str = '';
$fp = fopen($this->file, 'r');
if (flock($fp, lock_sh)) {
while (!feof($fp)) {
$f_str .= fgets($fp);
}
flock($fp, lock_un);
}
fclose($fp);
$c = json_decode($f_str, true);
return is_array($c) ? $c : array();
}
}
class runattimeconfig extends baseconfigfileutils
{
protected $visitor_capture_interval;
protected $config;
public function __construct($file, $visitor_capture_interval)
{
parent::__construct($file);
$this->config = $this->extractfile();
$this->visitor_capture_interval = $visitor_capture_interval;
}
public function updateconfig($arr)
{
$this->config = $this->extractfile();
if ($this->isvalidaterun()) {
$fp = fopen($this->file, 'w');
if (flock($fp, lock_ex)) {
fwrite($fp, json_encode(array_merge($this->config, $arr)));
flock($fp, lock_un);
}
fclose($fp);
return true;
}
return false;
}
public function getconfig($item)
{
if (is_array($this->config) && array_key_exists($item, $this->config)) {
return $this->config[$item];
}
return null;
}
public function isvalidaterun()
{
$c_time = utils::getmicrotime();
$run_at_time = floatval($this->getconfig('run_at_time'));
if ($c_time - $run_at_time >= $this->visitor_capture_interval) {
return true;
} else {
return false;
}
}
}
class visitorlist extends baseconfigfileutils
{
protected $visitor_list;
/**$visitor_list [] = array(
'uin' => $visitor['uin'], 'name' => $visitor['name'], 'online' => $visitor['online'], 'time' => $visitor['time'],
'img' => $visitor['img'], 'yellow' => $visitor['yellow'], 'supervip' => $visitor['supervip'],
);**/
public function __construct($file)
{
parent::__construct($file);
$this->visitor_list = $this->extractfile();
}
public function updatevisitor($visitor)
{
if (is_array($visitor) && !empty($visitor)) {
foreach ($visitor as $one) {
array_unshift($this->visitor_list, $one);
}
}
$fp = fopen($this->file, 'w');
if (flock($fp, lock_ex)) {
fwrite($fp, json_encode($this->visitor_list));
flock($fp, lock_un);
}
fclose($fp);
}
public function addvisitor($visitor)
{
$list = array();
if (is_array($visitor) && !empty($visitor)) {
foreach ($visitor as $one) {
if (!$this->isvisitorexist($one['name'])) {
$list[] = $one;
}
}
$this->updatevisitor($list);
}
return $list;
}
public function isvisitorexist($name)
{
foreach ($this->visitor_list as $one) {
if ($one['name'] == $name) {
return true;
}
}
return false;
}
}