From e94033b3fdae6e13374dafa319e997d8d2191475 Mon Sep 17 00:00:00 2001 From: yutou Date: Wed, 14 Apr 2021 18:27:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcookie=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E7=9A=84=E9=97=AE=E9=A2=98=20=E9=98=BFB?= =?UTF-8?q?=E8=AF=B7=E6=B1=82URL=E6=B7=BB=E5=8A=A0=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=20=E6=9B=B4=E6=96=B0=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=96=B0=E5=A2=9E=E5=BB=B6=E8=BF=9F=20?= =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E6=96=B0=E5=A2=9E=E9=80=80=E5=87=BA?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20=E6=9C=BA=E5=99=A8=E4=BA=BA=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=81=9C=E6=AD=A2=E6=9C=8D=E5=8A=A1=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yutou/bilibili/BiliBili/Live.java | 1 - .../java/com/yutou/bilibili/BiliBili/LiveUtils.java | 9 ++++++++- .../bilibili/Controllers/SystemConfigController.java | 1 + .../java/com/yutou/bilibili/QQBot/QQBotManager.java | 7 ++++++- src/main/java/com/yutou/bilibili/Tools/AppTools.java | 5 +++-- .../com/yutou/bilibili/Tools/ApplicationInit.java | 12 ------------ 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/yutou/bilibili/BiliBili/Live.java b/src/main/java/com/yutou/bilibili/BiliBili/Live.java index a8f8c50..419bdb7 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/Live.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/Live.java @@ -263,7 +263,6 @@ public class Live implements ApplicationContextAware { json.put("clientver", "2.6.36"); json.put("type", 2); json.put("key", http.getJSONObject("data").getString("token")); - com.yutou.bilibili.Tools.Log.i(json.toJSONString()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); outputStream.write(LiveUtils.toLH(json.toJSONString().length() + 16)); outputStream.write(new byte[]{0, 16, 0, 1, 0, 0, 0, 7, 0, 0, 0, 1}); diff --git a/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java b/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java index 14c5068..6ee39f4 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java @@ -178,7 +178,7 @@ public class LiveUtils { }*/ private static long oldBiliBiliHttpTime = 0; - public static JSONObject http_get(String url) { + public synchronized static JSONObject http_get(String url) { try { if (System.currentTimeMillis() - oldBiliBiliHttpTime < 1000) { try { @@ -311,6 +311,8 @@ public class LiveUtils { connection.setRequestProperty("Upgrade-Insecure-Requests", "1"); 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.setReadTimeout(5000); + connection.setConnectTimeout(5000); return connection; } @@ -445,6 +447,11 @@ public class LiveUtils { if (json != null) { infoMap.put(upInfo.getRoomid(), json); } + try { + Thread.sleep(300); + } catch (InterruptedException e) { + e.printStackTrace(); + } } } diff --git a/src/main/java/com/yutou/bilibili/Controllers/SystemConfigController.java b/src/main/java/com/yutou/bilibili/Controllers/SystemConfigController.java index 68a55bb..d908ece 100644 --- a/src/main/java/com/yutou/bilibili/Controllers/SystemConfigController.java +++ b/src/main/java/com/yutou/bilibili/Controllers/SystemConfigController.java @@ -88,6 +88,7 @@ public class SystemConfigController { @ResponseBody @RequestMapping("/system/qq/login.do") public JSONObject loginQQ(){ + QQBotManager.getInstance().stop(); QQBotManager.getInstance().init(); JSONObject json=new JSONObject(); json.put("code",0); diff --git a/src/main/java/com/yutou/bilibili/QQBot/QQBotManager.java b/src/main/java/com/yutou/bilibili/QQBot/QQBotManager.java index 7ee5b86..82faf19 100644 --- a/src/main/java/com/yutou/bilibili/QQBot/QQBotManager.java +++ b/src/main/java/com/yutou/bilibili/QQBot/QQBotManager.java @@ -72,7 +72,12 @@ public class QQBotManager implements ApplicationContextAware { private QQBotManager() { qqGroup = Long.parseLong((String) ConfigTools.load(ConfigTools.CONFIG, "qq_group")); } - + public void stop(){ + if(bot!=null){ + bot.close(); + bot=null; + } + } public void init() { if (!((boolean) ConfigTools.load(ConfigTools.CONFIG, "qq_bot"))) { return; diff --git a/src/main/java/com/yutou/bilibili/Tools/AppTools.java b/src/main/java/com/yutou/bilibili/Tools/AppTools.java index d967959..3e7feac 100644 --- a/src/main/java/com/yutou/bilibili/Tools/AppTools.java +++ b/src/main/java/com/yutou/bilibili/Tools/AppTools.java @@ -124,9 +124,10 @@ public class AppTools { */ public static void setCookie(HttpServletResponse response, String key, String value, int time) { Cookie cookie = new Cookie(key, value); - if (time != -1) { - cookie.setMaxAge(time); + if (time == -1) { + time= 31536000; } + cookie.setMaxAge(time); cookie.setPath("/"); response.addCookie(cookie); diff --git a/src/main/java/com/yutou/bilibili/Tools/ApplicationInit.java b/src/main/java/com/yutou/bilibili/Tools/ApplicationInit.java index 5f8cb5a..91c283d 100644 --- a/src/main/java/com/yutou/bilibili/Tools/ApplicationInit.java +++ b/src/main/java/com/yutou/bilibili/Tools/ApplicationInit.java @@ -33,18 +33,6 @@ public class ApplicationInit implements ApplicationRunner { @Override public void run(ApplicationArguments args) throws Exception { LiveUtils.LiveGiftConfig.getInstance(); - List 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(); }