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

View File

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

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -33,18 +33,6 @@ public class ApplicationInit implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
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();
}