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 = 5381; for (int i = 0; i < p_skey.Length; i++) { hash += (hash << 5) + p_skey[i]; } long g_tk = hash & 0x7fffffff;
bkn加密算法:
public long GetBkn(string skey) { var hash = 5381; for (int i = 0, len = skey.Length; i < len; ++i) { hash += (hash << 5) + (int)skey[i]; } return hash & 2147483647; }