QQ空间协议点赞实现以及QQ空间g_tk算法
QQ空间协议——点赞篇
该文章点赞的前提是有登录成功的Cookie
登录协议请看我的其他文章
结尾附实现代码
一、抓包、参数分析
1.1数据包1—点赞包
https://user.qzone.qq.com/proxy/domain/w.qzone.qq.com/cgi-bin/likes/internal_dolike_app?g_tk=456731308
g_tk——登录qq的gtk 利用Cookie中的skey通过加密算法获得
POST请求表单数据:
qzreferrer=https%3A%2F%2Fuser.qzone.qq.com%2F2793603016&opuin=2793603016&unikey=http%3A%2F%2Fuser.qzone.qq.com%2F20050606%2Fmood%2Faef23101f9b9db6644310800&curkey=http%3A%2F%2Fuser.qzone.qq.com%2F20050606%2Fmood%2Faef23101f9b9db6644310800&from=1&appid=311&typeid=0&abstime=1725676025&fid=aef23101f9b9db6644310800&active=0&fupdate=1
"qzreferrer": "https://user.qzone.qq.com/2793603016",
"opuin": "2793603016",
"unikey": "http://user.qzone.qq.com/20050606/mood/aef23101f9b9db6644310800",
"curkey": "http://user.qzone.qq.com/20050606/mood/aef23101f9b9db6644310800",
"from": "1",
"appid": "311",
"typeid": "0",
"abstime": "1725676025",
"fid": "aef23101f9b9db6644310800",
"active": "0",
"fupdate": "1"
opuin——被点赞的QQ
unikey——点赞文章的URL KEY (就是点赞文章的链接)
curkey——和unikey一样
abstime——点赞时间戳
fid——文章id
响应结果
响应mseeage为succ即为点赞成功,若为fail则为失败
1.2 unikey和fid包
https://user.qzone.qq.com/proxy/domain/ic2.qzone.qq.com/cgi-bin/feeds/feeds3_html_more?uin=2793603016&scope=0&view=1&daylist=&uinlist=&gid=&flag=1&filter=all&applist=all&refresh=0&aisortEndTime=0&aisortOffset=0&getAisort=0&aisortBeginTime=0&pagenum=1&externparam=offset=11&total=8&basetime=1701051331&feedsource=0&firstGetGroup=0&icServerTime=0&mixnocache=0&scene=0&begintime=0&count=10&dayspac=0&sidomain=qzonestyle.gtimg.cn&useutf8=1&outputhtmlfeed=1&rd=0.6607262087150207&usertime=1726798706032&windowId=0.007749873364047644&getob=1&g_tk=784492993
uin——登录的QQ
basetime——可固定
usertime——发包时间戳
g_tk
用Cookie GET请求从相应内容中找到data-unikey即可获得unikey和fid
这个包是说说内容的包,不仅包含这两个参数,还有说说的内容,浏览量,点赞量等数据
二、g_tk算法
通过跟栈即可找放到g_tk加密的地方 可以看到,g_tk是通过Cookie中的skey进行计算得到的
三Java代码实现
3.1g_tk算法
public static String getTK(String skey){//g_tk计算
int hash = 5381;
for (int i = 0, len = skey.length(); i < len; ++i) {
hash += (hash << 5) + skey.charAt(i);
}
return (hash & 2147483647) + "";
}
3.2点赞包发包
static void doLike(){
try{
int num=0;
num++;
BufferedReader read3=null;
String urll="https://h5.qzone.qq.com/proxy/domain/w.qzone.qq.com/cgi-bin/likes/internal_dolike_app?g_tk="+tk;
URL url=new URL(urll);
HttpsURLConnection conn=(HttpsURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Host", "h5.qzone.qq.com");
conn.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0");
conn.setRequestProperty("Accept", "textml,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8");
conn.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2");
conn.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
conn.setRequestProperty("Connection", "keep-alive");
conn.setRequestProperty("Cache-Control","no-cache");
conn.setRequestProperty("Origin","https://user.qzone.qq.com");
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
conn.setRequestProperty("Sec-Fetch-Dest", "iframe");
conn.setRequestProperty("Sec-Fetch-Mode", "navigate");
conn.addRequestProperty("Upgrade-Insecure-Requests","1");
conn.addRequestProperty("TE","trailers");
conn.setRequestProperty("Sec-Fetch-Site", "same-origin");
conn.setRequestProperty("Cookie",cookie.toString());
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream outt = conn.getOutputStream();
String mes="qzreferrer=https%3A%2F%2Fuser.qzone.qq.com%2Fproxy%2Fdomain%2Fic2.qzone.qq.com%2Fcgi-bin%2Ffeeds%2Ffeeds_html_module%3Fg_iframeUser%3D1%26i_uin%3D477154712%26i_login_uin%3D"+uin+"%26mode%3D4%26previewV8%3D1%26style%3D35%26version%3D8%26needDelOpr%3Dtrue%26transparence%3Dtrue%26hideExtend%3Dfalse%26showcount%3D5%26MORE_FEEDS_CGI%3Dhttp%253A%252F%252Fic2.s8.qzone.qq.com%252Fcgi-bin%252Ffeeds%252Ffeeds_html_act_all%26refer%3D2%26paramstring%3Dos-winxp%7C100&opuin="+uin+"&unikey=http%3A%2F%2Fuser.qzone.qq.com%2F477154712%2Fmood%2F"+finFidKey.get(ii)+"&curkey=http%3A%2F%2Fuser.qzone.qq.com%2F477154712%2Fmood%2F"+finFidKey.get(ii)+"&from=1&appid=311&typeid=0&abstime="+finabsTime.get(ii)+"&fid="+finFidKey.get(ii)+"&active=0&fupdate=1";
outt.write(mes.getBytes());
InputStream in = conn.getInputStream();
InputStreamReader inn = new InputStreamReader(in,"utf-8");
BufferedReader bufferedReader = new BufferedReader(inn);
String line;
String builder=null;
Long t=new Long(finabsTime.get(ii)+"");
Date date=new Date(t*1000L);
System.out.println(date);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
String timeString = sdf.format(date);
while ((line = bufferedReader.readLine()) != null){
builder+=line;
System.out.println("点赞结果"+builder.toString());
}
if(builder.matches(".*succ.*")){
System.out.println("序号"+num+"说说key:"+finFidKey.get(ii)+" 说说发布时间:"+timeString+""+"----点赞成功");
} else{
System.out.println("序号"+num+"说说key:"+finFidKey.get(ii)+" 说说发布时间:"+timeString+""+"----点赞失败");
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
标签:QQ,协议,setRequestProperty,qq,tk,qzone,点赞,conn
From: https://blog.csdn.net/qq_37454479/article/details/142374551