修复cookie没有时间的问题

阿B请求URL添加超时设置
更新直播数据新增延迟
机器人新增退出接口
机器人新增停止服务指令
This commit is contained in:
yutou 2021-04-14 18:27:56 +08:00
parent bd80d17441
commit e94033b3fd
6 changed files with 18 additions and 17 deletions

View File

@ -263,7 +263,6 @@ public class Live implements ApplicationContextAware {
json.put("clientver", "2.6.36"); json.put("clientver", "2.6.36");
json.put("type", 2); json.put("type", 2);
json.put("key", http.getJSONObject("data").getString("token")); json.put("key", http.getJSONObject("data").getString("token"));
com.yutou.bilibili.Tools.Log.i(json.toJSONString());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
outputStream.write(LiveUtils.toLH(json.toJSONString().length() + 16)); outputStream.write(LiveUtils.toLH(json.toJSONString().length() + 16));
outputStream.write(new byte[]{0, 16, 0, 1, 0, 0, 0, 7, 0, 0, 0, 1}); outputStream.write(new byte[]{0, 16, 0, 1, 0, 0, 0, 7, 0, 0, 0, 1});

View File

@ -178,7 +178,7 @@ public class LiveUtils {
}*/ }*/
private static long oldBiliBiliHttpTime = 0; private static long oldBiliBiliHttpTime = 0;
public static JSONObject http_get(String url) { public synchronized static JSONObject http_get(String url) {
try { try {
if (System.currentTimeMillis() - oldBiliBiliHttpTime < 1000) { if (System.currentTimeMillis() - oldBiliBiliHttpTime < 1000) {
try { try {
@ -311,6 +311,8 @@ public class LiveUtils {
connection.setRequestProperty("Upgrade-Insecure-Requests", "1"); connection.setRequestProperty("Upgrade-Insecure-Requests", "1");
connection.setRequestProperty("Cookie", cookie); connection.setRequestProperty("Cookie", cookie);
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"); connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36");
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);
return connection; return connection;
} }
@ -445,6 +447,11 @@ public class LiveUtils {
if (json != null) { if (json != null) {
infoMap.put(upInfo.getRoomid(), json); infoMap.put(upInfo.getRoomid(), json);
} }
try {
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
} }
} }

View File

@ -88,6 +88,7 @@ public class SystemConfigController {
@ResponseBody @ResponseBody
@RequestMapping("/system/qq/login.do") @RequestMapping("/system/qq/login.do")
public JSONObject loginQQ(){ public JSONObject loginQQ(){
QQBotManager.getInstance().stop();
QQBotManager.getInstance().init(); QQBotManager.getInstance().init();
JSONObject json=new JSONObject(); JSONObject json=new JSONObject();
json.put("code",0); json.put("code",0);

View File

@ -72,7 +72,12 @@ public class QQBotManager implements ApplicationContextAware {
private QQBotManager() { private QQBotManager() {
qqGroup = Long.parseLong((String) ConfigTools.load(ConfigTools.CONFIG, "qq_group")); qqGroup = Long.parseLong((String) ConfigTools.load(ConfigTools.CONFIG, "qq_group"));
} }
public void stop(){
if(bot!=null){
bot.close();
bot=null;
}
}
public void init() { public void init() {
if (!((boolean) ConfigTools.load(ConfigTools.CONFIG, "qq_bot"))) { if (!((boolean) ConfigTools.load(ConfigTools.CONFIG, "qq_bot"))) {
return; return;

View File

@ -124,9 +124,10 @@ public class AppTools {
*/ */
public static void setCookie(HttpServletResponse response, String key, String value, int time) { public static void setCookie(HttpServletResponse response, String key, String value, int time) {
Cookie cookie = new Cookie(key, value); Cookie cookie = new Cookie(key, value);
if (time != -1) { if (time == -1) {
cookie.setMaxAge(time); time= 31536000;
} }
cookie.setMaxAge(time);
cookie.setPath("/"); cookie.setPath("/");
response.addCookie(cookie); response.addCookie(cookie);

View File

@ -33,18 +33,6 @@ public class ApplicationInit implements ApplicationRunner {
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
LiveUtils.LiveGiftConfig.getInstance(); LiveUtils.LiveGiftConfig.getInstance();
List<BilibiliUpInfo> list = service.getUpInfo();
for (BilibiliUpInfo data : list) {
if (data.getEnable() == 1) {
try {
Live live = new Live();
live.add(data.getRoomid(), !StringUtils.isEmpty(AppTools.readFile(new File("cookies.json"))));
live.start();
} catch (Exception e) {
com.yutou.bilibili.Tools.Log.e(e);
}
}
}
startTimer(); startTimer();
} }