diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java b/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java index 6005db6..c8dbf72 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java @@ -3,8 +3,10 @@ package com.yutou.qqbot.bilibili; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; +import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.utlis.ConfigTools; import com.yutou.qqbot.utlis.HttpTools; +import com.yutou.qqbot.utlis.QRCodeUtils; import com.yutou.qqbot.utlis.StringUtils; import java.io.File; @@ -21,7 +23,7 @@ public class BiliLogin { public BiliLogin(Long qq) { biliUtils = BiliBiliUtils.getInstance(qq); - this.qq=qq; + this.qq = qq; } public JSONObject login() { @@ -33,6 +35,12 @@ public class BiliLogin { return json; } + public void loginAsQQ() { + String url = login().getString("url"); + File code = QRCodeUtils.createQRCode("bili_login", url); + QQBotManager.getInstance().sendMessage(code, qq, "B站未登录,请扫码登陆后再试"); + } + public void waitLogin(String oauthKey) { long time = System.currentTimeMillis(); String bd = "gourl=https%3A%2F%2Fpassport.bilibili.com%2Fajax%2FminiLogin%2Fredirect&oauthKey=" + oauthKey; @@ -88,10 +96,10 @@ public class BiliLogin { } public static String getCookieToken(Long qq) { - if (StringUtils.isEmpty(ConfigTools.readFile(new File(qq+"_bilibili.cookie")))) { + if (StringUtils.isEmpty(ConfigTools.readFile(new File(qq + "_bilibili.cookie")))) { return null; } - JSONObject json = JSON.parseObject(ConfigTools.readFile(new File(qq+"_bilibili.cookie"))); + JSONObject json = JSON.parseObject(ConfigTools.readFile(new File(qq + "_bilibili.cookie"))); return json.getString("bili_jct"); } @@ -100,7 +108,7 @@ public class BiliLogin { BiliLogin login = new BiliLogin(583819556L); boolean testLogin = login.testLogin(); System.out.println("testLogin = " + testLogin); - // JSONObject json = login.login(); - // QRCodeUtils.createQRCode("bili_login", json.getString("url")); + // JSONObject json = login.login(); + // QRCodeUtils.createQRCode("bili_login", json.getString("url")); } } diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index 053c18c..2a8c200 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -40,9 +40,7 @@ public class BiliBiliLive extends Model { super.onTime(qq, time); if ("00:01:00".equals(time)) { if(!new BiliLogin(qq).testLogin()){ - String url = new BiliLogin(QQBotManager.defQQ).login().getString("url"); - File code = QRCodeUtils.createQRCode("bili_login", url); - QQBotManager.getInstance().sendMessage(code, qq, "B站未登录,请扫码登陆后再试"); + new BiliLogin(QQBotManager.defQQ).loginAsQQ(); return; } signLive(QQBotManager.defQQ, qq); @@ -50,6 +48,10 @@ public class BiliBiliLive extends Model { } private void signLive(long qq, long sendQQ) { + if(!new BiliLogin(qq).testLogin()){ + new BiliLogin(qq).loginAsQQ(); + return; + } BiliBiliUtils biliUtils = BiliBiliUtils.getInstance(qq); QQBotManager.getInstance().sendMessage(sendQQ, biliUtils.liveSignIn()); Set biliLive = RedisTools.list_get("bili_live"); @@ -98,9 +100,7 @@ public class BiliBiliLive extends Model { } Integer roomId = Integer.parseInt(msg); if(!new BiliLogin(qq).testLogin()){ - String url = new BiliLogin(user).login().getString("url"); - File code = QRCodeUtils.createQRCode("bili_login", url); - QQBotManager.getInstance().sendMessage(code, qq, "B站未登录,请扫码登陆后再试"); + new BiliLogin(qq).loginAsQQ(); return; } if (biliUtils.checkLiveRoom(roomId) && roomId != 0) { diff --git a/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java b/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java index fb431c8..bfde21e 100644 --- a/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java +++ b/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java @@ -44,9 +44,7 @@ public class BiliBiliMangeSign extends Model { } QQBotManager.getInstance().sendMessage(qq, msg); } else { - String url = new BiliLogin(user).login().getString("url"); - File code = QRCodeUtils.createQRCode("bili_login", url); - QQBotManager.getInstance().sendMessage(code, qq, "B站未登录,请扫码登陆后再试"); + new BiliLogin(user).loginAsQQ(); } } else if (msg.equals(QQFromCommands.BILI_MANGA_PAY)) { StringBuilder builder = new StringBuilder();