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(); }