阅读时长:5分钟
本文内容: 在QQ空间领域中需要使用的g_tk算法
介绍:g_tk是腾讯在QQ空间这一领域使用的密文(其他的地方我没遇到g_tk)。调用其url时,需要添加计算出的g_tk参数才能成功!
def get_g_tk(cookie):
hashes = 5381
for letter in cookie.split(';')[-1].split('=')[-1]:
hashes += (hashes << 5) + ord(letter)
g_tk = hashes & 0x7fffffff
return g_tk
比如获得
## get_data
def fetch_like_number_data(cookie, Id):
if not itemId:
raise ValueError("id does not exist")
g_tk = get_g_tk(cookie)
url = f'https://vip.qq.com/vbs/n_UniBusinessCollectObj/nCollectInfo?Id=999&g_tk={g_tk}'
stLo = {
"iKeyType": 1,
"iOpplat": 1,
"sClientIp": "",
"sClientVer": "undefined.undefined.undefined",
"sSKey": "string"
}
query_param = {
"stLogin": stLo,
"stUniBusinessItemList": ["1"],
}
a_headers = {
'User-Agent': user_agent,
'Cookie': cookie,
'Content-Type': 'application/json; charset=utf-8',
}
chick_url = f'https://vip.qq.com/vbs/b_UniBusinessLogicObj/uC?Id=888&g_tk={g_tk}'
dumps = json.dumps(query_param)
requests.post(url=chick_url, data=dumps, headers=a_headers)
a_response = requests.post(url=a_url, data=dumps, headers=a_headers)
a_json = json.loads(a_response.text)
# 数据
a_num = a_json['data']['stRsp']['stItemCollectInfoList'][0]['cnt']
print(a_num)
return a_num
```