getGTK

function getGTK($skey){
        $len = strlen($skey);
        $hash = 5381;
        for ($i = 0; $i < $len; $i++) {
            $hash += ($hash << 5 & 2147483647) + ord($skey[$i]) & 2147483647;
            $hash &= 2147483647;
        }
        return $hash & 2147483647;
}

getGTK2

function getGTK2($skey){
    $salt = 5381;
    $md5key = 'tencentQQVIP123443safde&!%^%1282';
    $hash = array();
    $hash[] = ($salt << 5);
    for($i = 0; $i < strlen($skey); $i ++)
    {
        $ASCIICode = mb_convert_encoding($skey[$i], 'UTF-32BE', 'UTF-8');
        $ASCIICode = hexdec(bin2hex($ASCIICode));
        $hash[] = (($salt << 5) + $ASCIICode);
        $salt = $ASCIICode;
    }
    $md5str = md5(implode($hash) . $md5key);
    return $md5str;
}

getGTK3

function getGTK3($skey){
        $salt = 108;
        $md5key = 'tencent.mobile.qq.csrfauth';
        $hash = array();
        $hash[] = ($salt << 5);
        for($i = 0; $i < strlen($skey); $i ++)
        {
            $ASCIICode = mb_convert_encoding($skey[$i], 'UTF-32BE', 'UTF-8');
            $ASCIICode = hexdec(bin2hex($ASCIICode));
            $hash[] = (($salt << 5) + $ASCIICode);
            $salt = $ASCIICode;
        }
        $md5str = md5(implode($hash) . $md5key);
        return $md5str;
}

getToken

function getToken($token){
        $len = strlen($token);
        $hash = 0;
        for ($i = 0; $i < $len; $i++) {
            $hash = fmod($hash * 33 + ord($token[$i]), 4294967296);
        }
        return $hash;
}

curl

function get_curl($url,$post=0,$referer=0,$cookie=0,$header=0,$ua=0,$nobaody=0){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $httpheader[] = "Accept:*/*";
    $httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
    $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
    $httpheader[] = "Connection:close";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    if($post){
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
    if($header){
        curl_setopt($ch, CURLOPT_HEADER, TRUE);
    }
    if($cookie){
        curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    }
    if($referer){
        if($referer==1){
            curl_setopt($ch, CURLOPT_REFERER, 'https://m.qzone.com/infocenter?g_f=');
        }else{
            curl_setopt($ch, CURLOPT_REFERER, $referer);
        }
    }
    if($ua){
        curl_setopt($ch, CURLOPT_USERAGENT,$ua);
    }else{
        curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Linux; Android 4.4.2; NoxW Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36');
    }
    if($nobaody){
        curl_setopt($ch, CURLOPT_NOBODY,1);
    }
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    $ret = curl_exec($ch);
    curl_close($ch);
    return $ret;
}
最后修改:2021 年 09 月 16 日 09 : 50 PM
如果觉得我的文章对你有用,请随意赞赏
END
本文作者:
文章标题:QQ扫码登录cookie常用的PHP算法
本文地址:https://www.jufb.cn/archives/49.html
版权说明:若无注明,本文皆雨尘博客原创,转载请保留文章出处。