g_tk是腾讯在QQ空间这一领域使用的密文,有写数据包或者url参数中需要加入你计算出的g_tk才能成功!
下面是通过浏览器抓包工具抓取
访问该js内容找出 QZONE.FrontPage.getACSRFToken() 函数
QZONE.FrontPage.getACSRFToken = function(url){
url = QZFL.util.URI(url);
var skey;
if(url){
if(url.host && url.host.indexOf(“qzone.qq.com”)> 0){
skey = QZFL.cookie.get(“p_skey”);
} else {
if(url.host && url.host.indexOf(“qq.com”)> 0){
skey = QZFL.cookie.get(“skey”);
}}
}}
}}
if(!skey){
尝试{
skey = parent.QZFL.cookie.get(“p_skey”)|| “”;
} catch(err){
skey = QZFL.cookie.get(“p_skey”)|| “”;
}}
}}
if(!skey){
skey = QZFL.cookie.get(“skey”)|| QZFL.cookie.get(“rv2”);
}}
var hash = 5381;
for(var i = 0,len = skey.length; i <len; ++ i){
hash + =(hash << 5)+ skey.charAt(i).charCodeAt();
}}
return hash&2147483647;
};
得到p_skey后,循环取单字符的二进制并取左值.累加之后就得到后面的g_tk值了
转为C#代码
string p_skey = pskey;
long hash = ;
for (int i = ; i < p_skey.Length; i++)
{
hash += (hash << ) + p_skey[i];
}
long g_tk = hash & 0x7fffffff;
bkn加密算法:
public long GetBkn(string skey)
{
var hash = ;
for (int i = , len = skey.Length; i < len; ++i)
{
hash += (hash << ) + (int)skey[i];
}
return hash & ;
}