Heim > php教程 > PHP源码 > Hauptteil

php使用curl抓取qq空间的访客信息示例_php技巧

PHP中文网
Freigeben: 2016-05-25 16:59:49
Original
1710 Leute haben es durchsucht

这篇文章主要介绍了php使用curl抓取qq空间的访客信息示例,需要的朋友可以参考下

config.php

<?php
define(&#39;APP_DIR&#39;, dirname(__FILE__));
define(&#39;COOKIE_FILE&#39;, APP_DIR . &#39;/app.cookie.txt&#39;); //会话记录文件
define(&#39;VISITOR_CAPTURE_INTERVAL&#39;, 3); //QQ采集间隔
define(&#39;VISITOR_DATA_UPLOAD_INTERVAL&#39;, &#39;&#39;);
define(&#39;THIS_TIME&#39;, time());
define(&#39;REQUEST_TIMEOUT&#39;, 20); //请求超时20秒
define(&#39;END_LINE&#39;, "\n");
define(&#39;DEBUG&#39;, true); //开启调试
$login_users = array(
    array(&#39;user&#39; => &#39;2064556526&#39;, &#39;password&#39; => &#39;909124951&#39;),
    array(&#39;user&#39; => &#39;483258700&#39;, &#39;password&#39; => &#39;909124951&#39;),
    array(&#39;user&#39; => &#39;1990270522&#39;, &#39;password&#39; => &#39;909124951&#39;),
    array(&#39;user&#39; => &#39;2718711637&#39;, &#39;password&#39; => &#39;909124951&#39;),
    array(&#39;user&#39; => &#39;2841076562&#39;, &#39;password&#39; => &#39;909124951&#39;),
);
Nach dem Login kopieren

qy.visitor.php

<?php
include(&#39;./config.php&#39;);
include(APP_DIR . &#39;/qy.visitor.php&#39;);
$sessions = array();
$user = $login_users[array_rand($login_users)];
$visitor_capture = new QQVisitorCapture($user[&#39;user&#39;], $user[&#39;password&#39;], 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,&#39;&#39;, REQUEST_TIMEOUT, DEBUG, END_LINE);
}
qy.class.php
<?php
class Trace
{
    public static function nl($num = 1)
    {
        $str = &#39;&#39;;
        for ($i = 0; $i < $num; $i++) {
            $str .= "\n";
        }
        return $str;
    }
    public static function br($num = 1)
    {
        $str = &#39;&#39;;
        for ($i = 0; $i < $num; $i++) {
            $str .= "<br/>";
        }
        return $str;
    }
    public static function write($content, $end_line, $title = null)
    {
        $close = &#39;^^^^^^^^^^^^^^^^^&#39;;
        if ($title) {
            $start = &#39;--------&#39; . $title . &#39;---------&#39;;
        } else {
            $start = &#39;-----------------&#39;;
        }
        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(&#39;%.3f&#39;, $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(&#39;%3d&#39;, $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 = &#39;&#39;;
        $temp = null;
        for ($i = 0; $i < strlen($str); $i = $i + 2) {
            $arr .= "\\x" . substr($str, $i, 2);
        }
        eval(&#39;$temp="&#39; . $arr . &#39;";&#39;);
        return $temp;
    }
    protected static function getUid($uid)
    {
        $temp = null;
        eval(&#39;$temp="&#39; . $uid . &#39;";&#39;);
        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] != &#39;#&#39;) {
                        $cookie = (preg_split("/\s+/", $line));
                        if (count($cookie) == 7) {
                            $cookie_list[$cookie[5]] = $cookie[6];
                        } else {
                            $cookie_list[$cookie[5]] = &#39;&#39;;
                        }
                    }
                }
            }
        }
        return $cookie_list;
    }
    protected function buildCookieStr($cookies)
    {
        $arr = array();
        if (is_array($cookies)) {
            foreach ($cookies as $k => $cookie) {
                $line = $cookie[&#39;domain&#39;] . "\t" . "TRUE" . "\t" . $cookie[&#39;path&#39;] . "\t" . "FALSE" . "\t" . $cookie[&#39;expires&#39;] . "\t" . $k . "\t" . $cookie[&#39;value&#39;];
                $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] != &#39;#&#39;) {
                            $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 = &#39;Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0&#39;;
    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, &#39;request output&#39;);
        //} 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) . &#39;/&#39; . $user . &#39;.&#39; . 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(&#39;/cfg\s*=\s*\{(.*?)\s*\}\s*,\s*URL_PARAM_HASH/s&#39;, $content, $m);
        if (count($m) > 0) {
            $f = preg_replace(&#39;/\s*/&#39;, &#39;&#39;, $m[1]);
            $f = preg_replace(&#39;/"\+g\_iLoginUin\+"/&#39;, $user, $f);
            $f = preg_replace(&#39;/\$j\.cookie.get\("hotfeeds_closed"\)==1\?""\:/&#39;, &#39;&#39;, $f);
            $f = explode(",", $f);
            if (count($f) > 0) {
                foreach ($f as $t) {
                    $t = trim($t);
                    $p = strpos($t, &#39;:&#39;);
                    $key = trim(substr($t, 0, $p), &#39;"&#39;);
                    $value = trim(substr($t, $p + 1), &#39;"&#39;);
                    if ($key) {
                        $arr[$key] = $value;
                    }
                }
                if (count($arr) > 0) {
                    $arr[&#39;visitor&#39;] = $arr;
                }
            }
        }
        return $arr;
    }
    public static function  enterQzoneSuccess($content)
    {
        $arr = array();
        $arr2 = array();
        preg_match(&#39;/g_Data\s*=\s*{\s*feedsPart1\s*:\s*(.*?)\s*,\s*feedsPart2/s&#39;, $content, $m);
        if (count($m) > 0) {
            $f = preg_replace(&#39;/\s*/&#39;, &#39;&#39;, $m[1]);
            $f = preg_replace(&#39;/([\{,])([^,]*?)(\:)/&#39;, &#39;$1"$2"$3&#39;, $f);
            $f = preg_replace(&#39;/:\&#39;(.*?)\&#39;([,\}])/&#39;, &#39;:"$1"$2&#39;, $f);
            $arr = json_decode($f, true);
            $arr = $arr[&#39;main&#39;];
        }
        preg_match(&#39;/g_type.*?g_IZone_Flag/s&#39;, $content, $m);
        if (count($m) > 0) {
            $f = preg_replace(&#39;/\s*/&#39;, &#39;&#39;, $m[0]);
            $f = explode(",", $f);
            foreach ($f as $t) {
                $t = trim($t);
                $p = strpos($t, &#39;=&#39;);
                $key = trim(substr($t, 0, $p));
                $value = trim(substr($t, $p + 1), &#39;"&#39;);
                if ($key) {
                    $arr2[$key] = $value;
                }
            }
        }
        return array_merge($arr, $arr2);
    }
    public static function getLoginJsInfo($content)
    {
        $s = preg_replace(&#39;/.*?pt\.plogin\s*=\s*\{(.*?)aqScanLink.*/s&#39;, &#39;$1&#39;, $content);
        preg_match(&#39;/.*js_type\s*:\s*(\d+)\s*,.*/&#39;, $s, $m);
        if (count($m) > 1) {
            return array(&#39;js_type&#39; => $m[1]);
        }
        return array();
    }
    public static function getLoginAddress($content)
    {
        preg_match(&#39;/.*?<\s*iframe\s*id\s*=\s*"login_frame"\s*name\s*=\s*"login_frame".*?src\s*=\s*"(.*?xui\.ptlogin2\.qq\.com.*?)".*?>\s*<\/iframe>.*?/&#39;, $content, $m);
        if (count($m) > 1) {
            return html_entity_decode($m[1]);
        }
        return null;
    }
    public static function checkLoginSuccess($content)
    {
        preg_match_all(&#39;/.*?\((.*)\).*?/&#39;, $content, $match);
        if ($match[1][0]) {
            $g = explode(&#39;,&#39;, $match[1][0]);
            if (count($g) > 1) {
                if (($g[count($g) - 2]) == "&#39;登录成功!&#39;") {
                    $url_parts = parse_url($g[2]);
                    parse_str($url_parts[&#39;query&#39;], $arr);
                    if (array_key_exists(&#39;ptsig&#39;, $arr)) {
                        $ptsig = $arr[&#39;ptsig&#39;];
                    } else {
                        $ptsig = null;
                    }
                    return array(&#39;status&#39; => true, &#39;value&#39; => array(&#39;url&#39; => $g[2], &#39;ptsig&#39; => $ptsig));
                }
            }
        }
        return array(&#39;status&#39; => false);
    }
    public static function rightFrameVisitors($content)
    {
        $visitor_list = array();
        $f = preg_replace(&#39;/\s*/&#39;, &#39;&#39;, $content);
        $f = preg_replace(&#39;/.*?_Callback\((\{.*?\})\).*?/&#39;, &#39;$1&#39;, $f);
        $f = json_decode($f, true);
        if (is_array($f) && count($f) > 0 && array_key_exists(&#39;data&#39;, $f)
            && array_key_exists(&#39;module_3&#39;, $f[&#39;data&#39;])
            && array_key_exists(&#39;data&#39;, $f[&#39;data&#39;][&#39;module_3&#39;])
            && array_key_exists(&#39;items&#39;, $f[&#39;data&#39;][&#39;module_3&#39;][&#39;data&#39;])
        ) {
            $visitors = $f[&#39;data&#39;][&#39;module_3&#39;][&#39;data&#39;][&#39;items&#39;];
            foreach ($visitors as $visitor) {
                if (!array_key_exists(&#39;loc&#39;, $visitor)) {
                    $visitor_list [] = array(
                        &#39;uin&#39; => $visitor[&#39;uin&#39;], &#39;name&#39; => $visitor[&#39;name&#39;], &#39;online&#39; => $visitor[&#39;online&#39;], &#39;time&#39; => $visitor[&#39;time&#39;],
                        &#39;img&#39; => $visitor[&#39;img&#39;], &#39;yellow&#39; => $visitor[&#39;yellow&#39;], &#39;supervip&#39; => $visitor[&#39;supervip&#39;],
                    );
                }
            }
        }
        return $visitor_list;
    }
    public static function getVisitors($content)
    {
        $f = preg_replace(&#39;/\s*/&#39;, &#39;&#39;, $content);
        preg_match(&#39;/^.*?(\{.*?\})\);\s*$/&#39;, $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(&#39;data&#39;, $visitors) && array_key_exists(&#39;items&#39;, $visitors[&#39;data&#39;])) {
                foreach ($visitors[&#39;data&#39;][&#39;items&#39;] as $visitor) {
                    if ($visitor[&#39;name&#39;]) {
                        $_ = array(
                            &#39;uin&#39; => $visitor[&#39;uin&#39;], &#39;name&#39; => $visitor[&#39;name&#39;], &#39;time&#39; => $visitor[&#39;time&#39;],
                            &#39;yellow&#39; => $visitor[&#39;yellow&#39;], &#39;supervip&#39; => $visitor[&#39;supervip&#39;],
                        );
                        if (array_key_exists(&#39;portraitlabel&#39;, $visitor)) {
                            $_[&#39;portraitlabel&#39;] = $visitor[&#39;portraitlabel&#39;];
                        }
                        $visitor_list[] = $_;
                        if (array_key_exists(&#39;uins&#39;, $visitor)) {
                            foreach ($visitor[&#39;uins&#39;] as $uins) {
                                $_ = array(
                                    &#39;uin&#39; => $uins[&#39;uin&#39;], &#39;name&#39; => $uins[&#39;name&#39;], &#39;time&#39; => $uins[&#39;time&#39;],
                                    &#39;yellow&#39; => $uins[&#39;yellow&#39;], &#39;supervip&#39; => $uins[&#39;supervip&#39;],
                                );
                                if (array_key_exists(&#39;portraitlabel&#39;, $uins)) {
                                    $_[&#39;portraitlabel&#39;] = $uins[&#39;portraitlabel&#39;];
                                }
                                $visitor_list[] = $_;
                            }
                        }
                    }
                }
            }
        }
        return $visitor_list;
    }
    public static function  checkVC($content)
    {
        preg_match_all(&#39;/.*?\((.*)\).*?/&#39;, $content, $match);
        if (strlen($match[1][0]) > 1) {
            $m = str_replace("&#39;", &#39;&#39;, $match[1][0]);
            $g = explode(&#39;,&#39;, $m);
            if (count($g) == 3) {
                return array(&#39;saltUin&#39; => $g[2], &#39;verifycode&#39; => $g[1], &#39;RSAKey&#39; => $g[2] ? false : true);
            }
        }
        return array();
    }
    public static function getLoginInfo($content)
    {
        $s = preg_replace(&#39;/.*?pt\.ptui\s*=\s*\{(.*?)\}\s*;.*/s&#39;, &#39;$1&#39;, $content);
        $e = preg_split(&#39;/,\s*/&#39;, trim($s));
        $info = array();
        foreach ($e as $t) {
            $t = trim($t);
            $p = strpos($t, &#39;:&#39;);
            $key = trim(substr($t, 0, $p));
            $value = trim(substr($t, $p + 1));
            if (preg_match(&#39;/encodeURIComponent/&#39;, $value)) {
                $value = preg_replace(&#39;/^encodeURIComponent\s*\(\s*"(.*)?"\s*\)\s*,?$/&#39;, &#39;$1&#39;, $value);
            } else {
                $value = trim($value, &#39;",&#39;);
            }
            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, &#39;login error &#39;);
        return false;
    }
    public function success()
    {
        return true;
    }
    public function getGTKEncryption()
    {
        return Utils ::getGTK($this->getCookie(&#39;skey&#39;, 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(
            &#39;pgv_pvid&#39; => array(
                &#39;value&#39; => Utils::getUTCMilliseconds(), &#39;path&#39; => &#39;/&#39;, &#39;domain&#39; => &#39;.qq.com&#39;, &#39;expires&#39; => &#39;0&#39;
            ),
            &#39;pgv_info&#39; => array(
                &#39;value&#39; => &#39;ssid=s&#39; . Utils::getUTCMilliseconds(), &#39;path&#39; => &#39;/&#39;, &#39;domain&#39; => &#39;.qq.com&#39;, &#39;expires&#39; => &#39;0&#39;
            ),
            &#39;_qz_referrer&#39; => array(
                &#39;value&#39; => &#39;qzone.qq.com&#39;, &#39;path&#39; => &#39;/&#39;, &#39;domain&#39; => &#39;.qq.com&#39;, &#39;expires&#39; => &#39;0&#39;
            ),
        ));
        //log
        $this->trace(&#39;&#39;, &#39;login begin&#39;);
        //log
        $this->trace($login_submit_info_url, &#39;$login_submit_info_url===&#39;);
        $login_submit_info = $this->getLoginSubmitInfo($login_submit_info_url);
        //log
        $this->trace($login_submit_info, &#39;$login_submit_info===&#39;);
        if (empty($login_submit_info)) {
            $this->error(&#39;err-001&#39;);
        }
        $this->report();
        //log
        $this->trace(&#39;&#39;, &#39;getLoginJs&#39;);
        $js_arr = $this->getLoginJs();
        //log
        $this->trace($js_arr, &#39;$getLoginJs===&#39;);
        if (empty($js_arr)) {
            $this->error(&#39;err-002&#39;);
        }
        $u = $uin = $this->user;
        $r = Utils::jsRandom();
        $verifycode = null;
        $pt_rsa = null;
        $ptredirect = $login_submit_info[&#39;target&#39;];
        $h = $t = $g = $from_ui = 1;
        $p = null;
        $regmaster = $login_submit_info[&#39;regmaster&#39;];
        $u1 = Utils::decodeURIComponent($login_submit_info[&#39;s_url&#39;]);
        $ptlang = $login_submit_info[&#39;lang&#39;];
        $action = strval(rand(5, 9)) . &#39;-&#39; . strval(strlen($this->user) + strlen($this->password) + rand(1, 5)) . &#39;-&#39; . Utils::loginJsTime();
        $js_ver = $login_submit_info[&#39;ptui_version&#39;];
        $js_type = $js_arr[&#39;js_type&#39;];
        $login_sig = $login_submit_info[&#39;login_sig&#39;];
        $appid = $aid = $login_submit_info[&#39;appid&#39;];
        $pt_qzone_sig = $login_submit_info[&#39;pt_qzone_sig&#39;];
        $daid = $login_submit_info[&#39;daid&#39;];
        //log
        $this->trace(&#39;&#39;, &#39;checkVC&#39;);
        $check_data = $this->checkVC($regmaster, $appid, $js_ver, $js_type, $login_sig, $u1, $r);
        if (count($check_data) !== 3) {
            $this->error(&#39;err-003&#39;);
        }
        //log
        $this->trace($check_data, &#39;$check_data===&#39;);
        //log
        $this->trace(json_encode($check_data), &#39;$check_data===&#39;);
        $verifycode = $check_data[&#39;verifycode&#39;];
        if ($check_data[&#39;RSAKey&#39;]) {
            $this->error(&#39;err-004&#39;);
        } else {
            $p = Utils::getEncryption($this->password, $check_data[&#39;saltUin&#39;], $verifycode);
            $pt_rsa = 0;
        }
        //log
        $this->trace(&#39;&#39;, &#39;submitLogin&#39;);
        $this->setCookies(array(
            &#39;ptui_loginuin&#39; => array(
                &#39;value&#39; => $this->user, &#39;path&#39; => &#39;/&#39;, &#39;domain&#39; => &#39;.qq.com&#39;, &#39;expires&#39; => &#39;0&#39;
            ),
        ));
        $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[&#39;status&#39;]) {
            $this->trace(&#39;登录成功&#39;, &#39;submitLogin&#39;);
            $this->trace($login_result, &#39;$login_result====&#39;);
            $this->loginSuccessRedirect($login_result[&#39;value&#39;][&#39;url&#39;]);
            $this->setCookies(array(
                &#39;fnc&#39; => array(
                    &#39;value&#39; => 1, &#39;path&#39; => &#39;/&#39;, &#39;domain&#39; => &#39;.qzone.qq.com&#39;, &#39;expires&#39; => &#39;0&#39;
                ),
            ));
            $enterQzoneInfo = $this->enterQzone($login_result[&#39;value&#39;][&#39;url&#39;], $login_result[&#39;value&#39;][&#39;ptsig&#39;]);
            //log
            $this->trace($enterQzoneInfo, &#39;$enterQzoneInfo===&#39;);
            if ($enterQzoneInfo) {
                $this->trace(&#39;进入空间&#39;, &#39;enterQzone&#39;);
                //$referer = $login_result[&#39;value&#39;][&#39;url&#39;];
                //$scope = 0;
                //log
                $this->trace(&#39;&#39;, &#39;getCoreJs&#39;);
                $coreJsInfo = $this->getCoreJs();
                $this->trace($coreJsInfo, &#39;getCoreJs===&#39;);
                $this->setCookies(array(
                    &#39;qzone_referer&#39; => array(
                        &#39;value&#39; => $login_result[&#39;value&#39;][&#39;url&#39;], &#39;path&#39; => &#39;/&#39;, &#39;domain&#39; => &#39;.local.cckf123456789.com&#39;, &#39;expires&#39; => &#39;0&#39;
                    ),
                    &#39;qzone_visitor_param&#39; => array(
                        &#39;value&#39; => implode(&#39;|&#39;, array_values($coreJsInfo[&#39;visitor&#39;])), &#39;path&#39; => &#39;/&#39;, &#39;domain&#39; => &#39;.local.cckf123456789.com&#39;, &#39;expires&#39; => &#39;0&#39;
                    ),
                ));
                //log
                //$this->trace(&#39;&#39;, &#39;rightFrameVisitor&#39;);
                //print_r($this->rightFrameVisitor($referer, implode(&#39;|&#39;, array_values($coreJsInfo[&#39;visitor&#39;]))));
                return $this->success();
            } else {
                $this->error(&#39;err-006&#39;);
            }
        } else {
            $this->error(&#39;err-005&#39;);
        }
    }
    protected function visitQzone()
    {
        $options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => &#39;http://qzone.qq.com&#39;,
            CURLOPT_HTTPHEADER => array(
                &#39;Referer:http://www.php.cn/&#39;,
                &#39;User-Agent:&#39; . $this->user_agent,
                &#39;Host:qzone.qq.com&#39;,
                &#39;Accept-Language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3&#39;,
                &#39;Connection:keep-alive&#39;,)
        );
        return ResultExtract::getLoginAddress($this->requestExec($options));
    }
    protected function getLoginJs()
    {
        $options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => &#39;http://imgcache.qq.com/ptlogin/ver/10067/js/c_login_old.js&#39;,
            CURLOPT_HTTPHEADER => array(
                &#39;Referer:http://www.php.cn/&#39;,
                &#39;User-Agent:&#39; . $this->user_agent,
                &#39;Host:imgcache.qq.com&#39;,
                &#39;Connection:keep-alive&#39;,)
        );
        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 => &#39;http://check.ptlogin2.qq.com/check?&#39; . http_build_query(array(
                &#39;regmaster&#39; => $regmaster,
                &#39;uin&#39; => $this->user,
                &#39;appid&#39; => $appid,
                &#39;js_ver&#39; => $js_ver,
                &#39;js_type&#39; => $js_type,
                &#39;login_sig&#39; => $login_sig,
                &#39;u1&#39; => $u1,
                &#39;r&#39; => $r,
            )),
            CURLOPT_HTTPHEADER => array(
                &#39;Referer:http://www.php.cn/&#39;,
                &#39;User-Agent:&#39; . $this->user_agent,
                &#39;Host:check.ptlogin2.qq.com&#39;,
                &#39;Accept-Language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3&#39;,
                &#39;Connection:keep-alive&#39;,
            )
        );
        return ResultExtract::checkVC($this->requestExec($options));
    }
    protected function report()
    {
        $url = &#39;http://ui.ptlogin2.qq.com/cgi-bin/report?id=358342&t=&#39; . Utils::jsRandom();
        $options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => $url,
            CURLOPT_HTTPHEADER => array(
                &#39;Referer:http://www.php.cn/&#39;,
                &#39;User-Agent:&#39; . $this->user_agent,
                &#39;Host:ui.ptlogin2.qq.com&#39;,
                &#39;Connection:keep-alive&#39;,)
        );
        $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(
                &#39;Referer:http://www.php.cn/&#39;,
                &#39;User-Agent:&#39; . $this->user_agent,
                &#39;Host:xui.ptlogin2.qq.com&#39;,
                &#39;Connection:keep-alive&#39;,
            )
        );
        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 = &#39;http://ptlogin2.qq.com/login&#39;;
        $url .= &#39;?&#39; . http_build_query(array(
                &#39;u&#39; => $this->user,
                &#39;verifycode&#39; => $verifycode));
        $url .= &#39;&p=&#39; . $p; ###
        $url .= &#39;&&#39; . http_build_query(array(
                &#39;pt_rsa&#39; => $pt_rsa,
                &#39;ptredirect&#39; => $ptredirect,
                &#39;u1&#39; => $u1,
                &#39;h&#39; => $h,
                &#39;t&#39; => $t,
                &#39;g&#39; => $g,
                &#39;from_ui&#39; => $from_ui,
                &#39;ptlang&#39; => $ptlang,
                &#39;action&#39; => $action,
                &#39;js_ver&#39; => $js_ver,
                &#39;js_type&#39; => $js_type,
            ));
        $url .= &#39;&login_sig=&#39; . $login_sig; ###
        $url .= &#39;&&#39; . http_build_query(array(
                &#39;aid&#39; => $aid,
                &#39;daid&#39; => $daid,
                &#39;pt_qzone_sig&#39; => $pt_qzone_sig));
        $options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => $url,
            CURLOPT_HTTPHEADER => array(
                &#39;Referer:http://www.php.cn/&#39;,
                &#39;User-Agent:&#39; . $this->user_agent,
                &#39;Host:ptlogin2.qq.com&#39;,
                &#39;Accept-Language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3&#39;,
                &#39;Connection:keep-alive&#39;,
            )
        );
        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(
                &#39;Referer:http://www.php.cn/&#39;,
                &#39;User-Agent:&#39; . $this->user_agent,
                &#39;Host:qzs.qq.com&#39;,
                &#39;Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&#39;,
                &#39;Connection:keep-alive&#39;,
                &#39;DNT:1&#39;,
            )
        );
        $this->requestExec($options);
    }
    public function  enterQzone($referer, $ptsig)
    {
        $options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => &#39;http://user.qzone.qq.com/&#39; . $this->user . &#39;?ptsig=&#39; . $ptsig,
            CURLOPT_HTTPHEADER => array(
                &#39;Referer:&#39; . $referer,
                &#39;Host:user.qzone.qq.com&#39;,
                &#39;Connection:keep-alive&#39;,
            )
        );
        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 => &#39;http://g.qzone.qq.com/cgi-bin/friendshow/cgi_get_visitor_more?&#39; . http_build_query(array(
                &#39;uin&#39; => $this->user,
                &#39;mask&#39; => $mask,
                &#39;g_tk&#39; => $this->getGTKEncryption(),
                &#39;page&#39; => $page,
                &#39;fupdate&#39; => $fupdate,
                &#39;clear&#39; => $clear,
                &#39;sd&#39; => Utils::jsRandom(),
            )),
            CURLOPT_HTTPHEADER => array(
                &#39;Referer:http://www.php.cn/&#39;,
                &#39;User-Agent:&#39; . $this->user_agent,
                &#39;Host:g.qzone.qq.com&#39;,
                &#39;Connection:keep-alive&#39;,
            )
        );
        return ResultExtract::getVisitors($this->requestExec($options));
    }
    public function  rightFrameVisitor()
    {
        $param = Utils ::getGTK($this->getCookie(&#39;qzone_visitor_param&#39;, true));
        $referver = Utils ::getGTK($this->getCookie(&#39;qzone_referer&#39;));
        $options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => &#39;http://r.qzone.qq.com/cgi-bin/right_frame.cgi?&#39; . http_build_query(array(
                &#39;uin&#39; => $this->user,
                &#39;param&#39; => $param,
                &#39;g_tk&#39; => $this->getGTKEncryption(),
            )),
            CURLOPT_HTTPHEADER => array(
                &#39;Referer:&#39; . $referver,
                &#39;User-Agent:&#39; . $this->user_agent,
                &#39;Host:r.qzone.qq.com&#39;,
                &#39;Connection:keep-alive&#39;,
            )
        );
        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 . &#39;?&#39; . http_build_query(array()),
            );
        }
    }
}
class BaseConfigFileUtils
{
    protected $file;
    public function __construct($file)
    {
        $this->file = $file;
    }
    public function extractFile()
    {
        $f_str = &#39;&#39;;
        $fp = fopen($this->file, &#39;r&#39;);
        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, &#39;w&#39;);
            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(&#39;run_at_time&#39;));
        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(
    &#39;uin&#39; => $visitor[&#39;uin&#39;], &#39;name&#39; => $visitor[&#39;name&#39;], &#39;online&#39; => $visitor[&#39;online&#39;], &#39;time&#39; => $visitor[&#39;time&#39;],
    &#39;img&#39; => $visitor[&#39;img&#39;], &#39;yellow&#39; => $visitor[&#39;yellow&#39;], &#39;supervip&#39; => $visitor[&#39;supervip&#39;],
    );**/
    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, &#39;w&#39;);
        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[&#39;name&#39;])) {
                    $list[] = $one;
                }
            }
            $this->updateVisitor($list);
        }
        return $list;
    }
    public function isVisitorExist($name)
    {
        foreach ($this->visitor_list as $one) {
            if ($one[&#39;name&#39;] == $name) {
                return true;
            }
        }
        return false;
    }
}
Nach dem Login kopieren
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage