java全民K歌每日领取鲜花脚本
小白一枚,最近老妈迷恋上全民k歌,每天手动获取鲜花太麻烦,抓包写了领取鲜花的java脚本,大佬勿喷,感谢!ck在网页版全民k歌获取:https://kg.qq.com/
uid也在ck里面
package com.xxl.job.executor.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
public class QuanMinKg {
public static void main(String[] args) throws IOException {
String ck = "";
String t_uUid = "";
String Url_a = "https://node.kg.qq.com/webapp/proxy?ns=proto_profile&cmd=profile.getProfile&mapExt=JTdCJTIyZmlsZSUyMiUzQSUyMnByb2ZpbGVfd2ViYXBwSmNlJTIyJTJDJTIyY21kTmFtZSUyMiUzQSUyMlByb2ZpbGVHZXQlMjIlMkMlMjJhcHBpZCUyMiUzQTEwMDA2MjYlMkMlMjJkY2FwaSUyMiUzQSU3QiUyMmludGVyZmFjZUlkJTIyJTNBMjA1MzU5NTk3JTdEJTJDJTIybDVhcGklMjIlM0ElN0IlMjJtb2RpZCUyMiUzQTI5NDAxNyUyQyUyMmNtZCUyMiUzQTI2MjE0NCU3RCUyQyUyMmlwJTIyJTNBJTIyMTAwLjExMy4xNjIuMTc4JTIyJTJDJTIycG9ydCUyMiUzQSUyMjEyNDA2JTIyJTdE&t_uUid=" + t_uUid;
String Url_b = "https://node.kg.qq.com/webapp/proxy?ns=KG_TASK&cmd=task.getLottery&ns_inbuf=&mapExt=JTdCJTIyZmlsZSUyMiUzQSUyMnRhc2tKY2UlMjIlMkMlMjJjbWROYW1lJTIyJTNBJTIyTG90dGVyeVJlcSUyMiUyQyUyMnduc0NvbmZpZyUyMiUzQSU3QiUyMmFwcGlkJTIyJTNBMTAwMDU1NyU3RCUyQyUyMmw1YXBpJTIyJTNBJTdCJTIybW9kaWQlMjIlM0E1MDM5MzclMkMlMjJjbWQlMjIlM0E1ODk4MjQlN0QlN0Q%3D&t_uid=" + t_uUid + "&t_iShowEntry=1&t_type=";
String t_type[] = {"1", "2"};
String Url_e = "https://node.kg.qq.com/webapp/proxy?ns=KG_TASK&cmd=task.getLottery&mapExt=JTdCJTIyZmlsZSUyMiUzQSUyMnRhc2tKY2UlMjIlMkMlMjJjbWROYW1lJTIyJTNBJTIyTG90dGVyeVJlcSUyMiUyQyUyMmw1YXBpJTIyJTNBJTdCJTIybW9kaWQlMjIlM0E1MDM5MzclMkMlMjJjbWQlMjIlM0E1ODk4MjQlN0QlMkMlMjJsNWFwaV9leHAxJTIyJTNBJTdCJTIybW9kaWQlMjIlM0E4MTcwODklMkMlMjJjbWQlMjIlM0EzODAxMDg4JTdEJTdE&t_uid=" + t_uUid + "&t_type=103";
String Url_c = "https://node.kg.qq.com/webapp/proxy?ns=KG_TASK&cmd=task.signinGetAward&mapExt=JTdCJTIyZmlsZSUyMiUzQSUyMnRhc2tKY2UlMjIlMkMlMjJjbWROYW1lJTIyJTNBJTIyR2V0U2lnbkluQXdhcmRSZXElMjIlMkMlMjJ3bnNDb25maWclMjIlM0ElN0IlMjJhcHBpZCUyMiUzQTEwMDA2MjYlN0QlMkMlMjJsNWFwaSUyMiUzQSU3QiUyMm1vZGlkJTIyJTNBNTAzOTM3JTJDJTIyY21kJTIyJTNBNTg5ODI0JTdEJTdE&t_uid=" + t_uUid + "&t_iShowEntry=";
String t_iShowEntry[] = {"1", "2", "4", "16", "128", "512"};
String Url_1 = "https://node.kg.qq.com/webapp/proxy?ns=proto_music_station&cmd=message.batch_get_music_cards&mapExt=JTdCJTIyY21kTmFtZSUyMiUzQSUyMkdldEJhdGNoTXVzaWNDYXJkc1JlcSUyMiUyQyUyMmZpbGUlMjIlM0ElMjJwcm90b19tdXNpY19zdGF0aW9uSmNlJTIyJTJDJTIyd25zRGlzcGF0Y2hlciUyMiUzQXRydWUlN0Q&t_uUid=" + t_uUid + "&g_tk_openkey=";
String Url_d = "https://node.kg.qq.com/webapp/proxy?ns=KG_TASK&cmd=task.getLottery&mapExt=JTdCJTIyZmlsZSUyMiUzQSUyMnRhc2tKY2UlMjIlMkMlMjJjbWROYW1lJTIyJTNBJTIyTG90dGVyeVJlcSUyMiUyQyUyMnduc0NvbmZpZyUyMiUzQSU3QiUyMmFwcGlkJTIyJTNBMTAwMDU1NyU3RCUyQyUyMmw1YXBpJTIyJTNBJTdCJTIybW9kaWQlMjIlM0E1MDM5MzclMkMlMjJjbWQlMjIlM0E1ODk4MjQlN0QlN0Q&t_uid=" + t_uUid + "&t_iShowEntry=4&t_type=104";
String Url_2 = "https://node.kg.qq.com/webapp/proxy?t_stReward%3Aobject=%7B%22uInteractiveType%22%3A1%2C%22uRewardType%22%3A0%2C%22uFlowerNum%22%3A15%7D&ns=proto_music_station&cmd=message.get_reward&mapExt=JTdCJTIyY21kTmFtZSUyMiUzQSUyMkdldFJld2FyZFJlcSUyMiUyQyUyMmZpbGUlMjIlM0ElMjJwcm90b19tdXNpY19zdGF0aW9uSmNlJTIyJTJDJTIyd25zRGlzcGF0Y2hlciUyMiUzQXRydWUlN0Q&t_uUid=" + t_uUid + "&t_strUgcId=";
String Url_3 = "https://node.kg.qq.com/webapp/proxy?t_stReward%3Aobject=%7B%22uInteractiveType%22%3A0%2C%22uRewardType%22%3A0%2C%22uFlowerNum%22%3A10%7D&ns=proto_music_station&cmd=message.get_reward&mapExt=JTdCJTIyY21kTmFtZSUyMiUzQSUyMkdldFJld2FyZFJlcSUyMiUyQyUyMmZpbGUlMjIlM0ElMjJwcm90b19tdXNpY19zdGF0aW9uSmNlJTIyJTJDJTIyd25zRGlzcGF0Y2hlciUyMiUzQXRydWUlN0Q&t_uUid=" + t_uUid + "&t_strUgcId=";
//获取信息
JSONObject jsonObject = httpQuery(Url_a, ck);
Integer num_a = jsonObject.getJSONObject("data").getJSONObject("profile.getProfile").getInteger("uFlowerNum");
String uname = jsonObject.getJSONObject("data").getJSONObject("profile.getProfile").getJSONObject("stPersonInfo").getString("sKgNick");
for (int a = 0; a < t_iShowEntry.length; a++) {
httpQuery(Url_c + t_iShowEntry, ck);
}
for (int b = 0; b < t_type.length; b++) {
httpQuery(Url_b + t_type, ck);
}
for (int c = 1; c <= 15; c++) {
JSONObject jsonObject2 = httpQuery(Url_1 + c, ck);
JSONArray vctMusicCards = jsonObject2.getJSONObject("data").getJSONObject("message.batch_get_music_cards").getJSONArray("vctMusicCards");
for (int i = 0; i < vctMusicCards.size(); i++) {
String strKey = vctMusicCards.getJSONObject(i).getString("strKey");
String strUgcId = vctMusicCards.getJSONObject(i).getString("strUgcId");
Integer bigInteger = vctMusicCards.getJSONObject(i).getJSONObject("stReward").getInteger("uFlowerNum");
String Url = strUgcId + "&t_strKey=" + strKey;
if (bigInteger > 10) {
httpQuery(Url_2 + Url, ck);
}
if (bigInteger > 1) {
httpQuery(Url_3 + Url, ck);
}
}
}
httpQuery(Url_d, ck);
httpQuery(Url_e, ck);
JSONObject jsonObject3 = httpQuery(Url_a, ck);
Integer num_b = jsonObject3.getJSONObject("data").getJSONObject("profile.getProfile").getInteger("uFlowerNum");
Integer num_c = num_b - num_a;
String tx = null;
if (num_c == 0) {
tx = "当前账户名 : " + uname + " 您今日已经领取过鲜花,当前账户鲜花数量为 " + num_b;
} else {
tx = "当前账户名 : " + uname + " 成功领取过鲜花,领取鲜花数量为 " + num_c + " 当前账户鲜花数量为 " + num_b;
}
System.out.println(tx);
}
private static JSONObject httpQuery(String url, String ck) throws IOException {
// ============================= 【HttpClient】 ====================================
// 创建httpclient实例
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String content = null;
try {
// 创建httpget实例
HttpGet httpget = new HttpGet(url);
// 模拟浏览器
httpget.setHeader("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0");
httpget.setHeader("Cookie", ck);
// 使用代{过}{滤}理 IP
//HttpHost proxy = new HttpHost("118.114.77.47", 8080);
RequestConfig config = RequestConfig.custom()
//设置连接超时
.setConnectTimeout(10000) // 设置连接超时时间 10秒钟
.setSocketTimeout(10000) // 设置读取超时时间10秒钟
.build();
httpget.setConfig(config);
// 执行get请求
response = httpclient.execute(httpget);
org.apache.http.HttpEntity entity = response.getEntity();
// 获取返回实体
content = EntityUtils.toString(entity, "utf-8");
return JSONObject.parseObject(content);
} catch (IOException e) {
e.printStackTrace();
} finally {
response.close(); // response关闭
httpclient.close(); // httpClient关闭
}
return JSONObject.parseObject(content);
}
}
本帖最后由 二十瞬 于 2023-4-1 16:56 编辑
首先谢谢楼主,然后我把代码转成了Python,方便结合一些工具自动执行。
顺便改成了 支持多账号,我已经测试能运行。现在只需要填写 cks数组,不需要uid。
例如 cks=["ck1","ck2"]. 希望往前面顶一顶,大家能看到
```
import requests
import os
import sys
baseUrl = "https://node.kg.qq.com"
os.environ['NO_PROXY'] = baseUrl
cks = [
""
]
def httpQuery(url, ck):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0',
'Cookie': ck
}
try:
response = requests.get(url, headers=headers, timeout=10)
response.raise_for_status()
except requests.exceptions.RequestException as e:
raise SystemExit(e)
else:
# print(f"请求返回结果:{response.text}")
return response.json()
def get_uid_from_cookie(cookie):
cookies = cookie.split("; ")
for c in cookies:
parts = c.split("=")
if parts == "uid":
return parts
return None
def go(ck):
t_uUid = get_uid_from_cookie(ck);
Url_a = baseUrl + "/webapp/proxy?ns=proto_profile&cmd=profile.getProfile&mapExt=JTdCJTIyZmlsZSUyMiUzQSUyMnByb2ZpbGVfd2ViYXBwSmNlJTIyJTJDJTIyY21kTmFtZSUyMiUzQSUyMlByb2ZpbGVHZXQlMjIlMkMlMjJhcHBpZCUyMiUzQTEwMDA2MjYlMkMlMjJkY2FwaSUyMiUzQSU3QiUyMmludGVyZmFjZUlkJTIyJTNBMjA1MzU5NTk3JTdEJTJDJTIybDVhcGklMjIlM0ElN0IlMjJtb2RpZCUyMiUzQTI5NDAxNyUyQyUyMmNtZCUyMiUzQTI2MjE0NCU3RCUyQyUyMmlwJTIyJTNBJTIyMTAwLjExMy4xNjIuMTc4JTIyJTJDJTIycG9ydCUyMiUzQSUyMjEyNDA2JTIyJTdE&t_uUid=" + t_uUid
Url_b = baseUrl + "/webapp/proxy?ns=KG_TASK&cmd=task.getLottery&ns_inbuf=&mapExt=JTdCJTIyZmlsZSUyMiUzQSUyMnRhc2tKY2UlMjIlMkMlMjJjbWROYW1lJTIyJTNBJTIyTG90dGVyeVJlcSUyMiUyQyUyMnduc0NvbmZpZyUyMiUzQSU3QiUyMmFwcGlkJTIyJTNBMTAwMDU1NyU3RCUyQyUyMmw1YXBpJTIyJTNBJTdCJTIybW9kaWQlMjIlM0E1MDM5MzclMkMlMjJjbWQlMjIlM0E1ODk4MjQlN0QlN0Q%3D&t_uid=" + t_uUid + "&t_iShowEntry=1&t_type="
t_type = ["1", "2"]
Url_e = baseUrl + "/webapp/proxy?ns=KG_TASK&cmd=task.getLottery&mapExt=JTdCJTIyZmlsZSUyMiUzQSUyMnRhc2tKY2UlMjIlMkMlMjJjbWROYW1lJTIyJTNBJTIyTG90dGVyeVJlcSUyMiUyQyUyMmw1YXBpJTIyJTNBJTdCJTIybW9kaWQlMjIlM0E1MDM5MzclMkMlMjJjbWQlMjIlM0E1ODk4MjQlN0QlMkMlMjJsNWFwaV9leHAxJTIyJTNBJTdCJTIybW9kaWQlMjIlM0E4MTcwODklMkMlMjJjbWQlMjIlM0EzODAxMDg4JTdEJTdE&t_uid=" + t_uUid + "&t_type=103"
Url_c = baseUrl + "/webapp/proxy?ns=KG_TASK&cmd=task.signinGetAward&mapExt=JTdCJTIyZmlsZSUyMiUzQSUyMnRhc2tKY2UlMjIlMkMlMjJjbWROYW1lJTIyJTNBJTIyR2V0U2lnbkluQXdhcmRSZXElMjIlMkMlMjJ3bnNDb25maWclMjIlM0ElN0IlMjJhcHBpZCUyMiUzQTEwMDA2MjYlN0QlMkMlMjJsNWFwaSUyMiUzQSU3QiUyMm1vZGlkJTIyJTNBNTAzOTM3JTJDJTIyY21kJTIyJTNBNTg5ODI0JTdEJTdE&t_uid=" + t_uUid + "&t_iShowEntry="
t_iShowEntry = ["1", "2", "4", "16", "128", "512"]
Url_1 = baseUrl + "/webapp/proxy?ns=proto_music_station&cmd=message.batch_get_music_cards&mapExt=JTdCJTIyY21kTmFtZSUyMiUzQSUyMkdldEJhdGNoTXVzaWNDYXJkc1JlcSUyMiUyQyUyMmZpbGUlMjIlM0ElMjJwcm90b19tdXNpY19zdGF0aW9uSmNlJTIyJTJDJTIyd25zRGlzcGF0Y2hlciUyMiUzQXRydWUlN0Q&t_uUid=" + t_uUid + "&g_tk_openkey="
Url_d = baseUrl + "/webapp/proxy?ns=KG_TASK&cmd=task.getLottery&mapExt=JTdCJTIyZmlsZSUyMiUzQSUyMnRhc2tKY2UlMjIlMkMlMjJjbWROYW1lJTIyJTNBJTIyTG90dGVyeVJlcSUyMiUyQyUyMnduc0NvbmZpZyUyMiUzQSU3QiUyMmFwcGlkJTIyJTNBMTAwMDU1NyU3RCUyQyUyMmw1YXBpJTIyJTNBJTdCJTIybW9kaWQlMjIlM0E1MDM5MzclMkMlMjJjbWQlMjIlM0E1ODk4MjQlN0QlN0Q&t_uid=" + t_uUid + "&t_iShowEntry=4&t_type=104"
Url_2 = baseUrl + "/webapp/proxy?t_stReward%3Aobject=%7B%22uInteractiveType%22%3A1%2C%22uRewardType%22%3A0%2C%22uFlowerNum%22%3A15%7D&ns=proto_music_station&cmd=message.get_reward&mapExt=JTdCJTIyY21kTmFtZSUyMiUzQSUyMkdldFJld2FyZFJlcSUyMiUyQyUyMmZpbGUlMjIlM0ElMjJwcm90b19tdXNpY19zdGF0aW9uSmNlJTIyJTJDJTIyd25zRGlzcGF0Y2hlciUyMiUzQXRydWUlN0Q&t_uUid=" + t_uUid + "&t_strUgcId="
Url_3 = baseUrl + "/webapp/proxy?t_stReward%3Aobject=%7B%22uInteractiveType%22%3A0%2C%22uRewardType%22%3A0%2C%22uFlowerNum%22%3A10%7D&ns=proto_music_station&cmd=message.get_reward&mapExt=JTdCJTIyY21kTmFtZSUyMiUzQSUyMkdldFJld2FyZFJlcSUyMiUyQyUyMmZpbGUlMjIlM0ElMjJwcm90b19tdXNpY19zdGF0aW9uSmNlJTIyJTJDJTIyd25zRGlzcGF0Y2hlciUyMiUzQXRydWUlN0Q&t_uUid=" + t_uUid + "&t_strUgcId="
# 获取信息
jsonObject = httpQuery(Url_a, ck)
num_a = jsonObject["data"]["profile.getProfile"]["uFlowerNum"]
uname = jsonObject["data"]["profile.getProfile"]["stPersonInfo"]["sKgNick"]
for a in range(len(t_iShowEntry)):
httpQuery(Url_c + t_iShowEntry, ck)
for b in range(len(t_type)):
httpQuery(Url_b + t_type, ck)
for c in range(1, 16):
jsonObject2 = httpQuery(Url_1 + str(c), ck)
vctMusicCards = jsonObject2["data"]["message.batch_get_music_cards"]["vctMusicCards"]
for i in range(len(vctMusicCards)):
strKey = vctMusicCards["strKey"]
strUgcId = vctMusicCards["strUgcId"]
bigInteger = vctMusicCards["stReward"]["uFlowerNum"]
Url = strUgcId + "&t_strKey=" + strKey
if bigInteger > 10:
httpQuery(Url_2 + Url, ck)
if bigInteger > 1:
httpQuery(Url_3 + Url, ck)
httpQuery(Url_d, ck)
httpQuery(Url_e, ck)
jsonObject3 = httpQuery(Url_a, ck)
num_b = jsonObject3["data"]["profile.getProfile"]["uFlowerNum"]
num_c = num_b - num_a
if num_c == 0:
tx = "账户: " + uname + " 今日已经领取过鲜花,当前账户鲜花数为 " + str(num_b)
else:
tx = "账户: " + uname + "成功领取过鲜花,领取鲜花数为 " + str(num_c) + " 当前鲜花数为 " + str(
num_b)
print(tx)
if __name__ == '__main__':
i = 0
for ck in cks:
i = i + 1
print(f"ck{i}开始领取鲜花")
go(ck)
print(f"ck{i}领取鲜花结束")
sys.exit()
``` ∫護着妳佉遠方 发表于 2023-1-9 16:49
看的教程都是HttpClient库,没有Python简洁
RestTemplate 是从 Spring3.0 开始支持的一个 HTTP 请求工具,它提供了常见的REST请求方案的模版,例如 GET 请求、POST 请求、PUT 请求、DELETE 请求以及一些通用的请求执行方法 exchange 以及 execute。RestTemplate 继承自 InterceptingHttpAccessor 并且实现了 RestOperations 接口,其中 RestOperations 接口定义了基本的 RESTful 操作,这些操作在 RestTemplate 中都得到了实现。接下来我们就来看看这些操作方法的使用。
现在一样简单了。。。越来越智能化。。写代码只用轮子 咋用?创建html吗,? wzx11 发表于 2022-11-13 09:50
咋用?创建html吗,?
这是个main方法..复制进去就可以用 感谢分享 感谢分享 感谢分享! 很好的一个软件,怎么用没写清楚,很无奈啊不会用,但是还是要支持你一下
最好搞一个刷收听率的出来{:1_918:} xzt35910 发表于 2023-1-5 20:57
很好的一个软件,怎么用没写清楚,很无奈啊不会用,但是还是要支持你一下
最好搞一个刷收听率的出来{:1_91 ...
java脚本
这就是个main方法 新建一个类,然后把这个复制进去就可以了 Java写爬虫类的东西还是太麻烦了,学习一段时间后放弃了,选择了Python,Java创建一个http请求有点繁琐,没有Python简洁,解析也比较麻烦,就是多线程使用起来有点舒服,比较熟悉 ∫護着妳佉遠方 发表于 2023-1-7 15:53
Java写爬虫类的东西还是太麻烦了,学习一段时间后放弃了,选择了Python,Java创建一个http请求有点繁琐,没 ...
java8 提供了RestTempLate工具类 可以执行post,get请求