修复B站签到未登录时的状态

This commit is contained in:
Yutousama 2023-01-06 01:31:01 +08:00
parent 938d3d532a
commit 3bc4c164e0
3 changed files with 20 additions and 14 deletions

View File

@ -3,8 +3,10 @@ package com.yutou.qqbot.bilibili;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.utlis.ConfigTools; import com.yutou.qqbot.utlis.ConfigTools;
import com.yutou.qqbot.utlis.HttpTools; import com.yutou.qqbot.utlis.HttpTools;
import com.yutou.qqbot.utlis.QRCodeUtils;
import com.yutou.qqbot.utlis.StringUtils; import com.yutou.qqbot.utlis.StringUtils;
import java.io.File; import java.io.File;
@ -21,7 +23,7 @@ public class BiliLogin {
public BiliLogin(Long qq) { public BiliLogin(Long qq) {
biliUtils = BiliBiliUtils.getInstance(qq); biliUtils = BiliBiliUtils.getInstance(qq);
this.qq=qq; this.qq = qq;
} }
public JSONObject login() { public JSONObject login() {
@ -33,6 +35,12 @@ public class BiliLogin {
return json; 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) { public void waitLogin(String oauthKey) {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
String bd = "gourl=https%3A%2F%2Fpassport.bilibili.com%2Fajax%2FminiLogin%2Fredirect&oauthKey=" + oauthKey; 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) { 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; 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"); return json.getString("bili_jct");
} }
@ -100,7 +108,7 @@ public class BiliLogin {
BiliLogin login = new BiliLogin(583819556L); BiliLogin login = new BiliLogin(583819556L);
boolean testLogin = login.testLogin(); boolean testLogin = login.testLogin();
System.out.println("testLogin = " + testLogin); System.out.println("testLogin = " + testLogin);
// JSONObject json = login.login(); // JSONObject json = login.login();
// QRCodeUtils.createQRCode("bili_login", json.getString("url")); // QRCodeUtils.createQRCode("bili_login", json.getString("url"));
} }
} }

View File

@ -40,9 +40,7 @@ public class BiliBiliLive extends Model {
super.onTime(qq, time); super.onTime(qq, time);
if ("00:01:00".equals(time)) { if ("00:01:00".equals(time)) {
if(!new BiliLogin(qq).testLogin()){ if(!new BiliLogin(qq).testLogin()){
String url = new BiliLogin(QQBotManager.defQQ).login().getString("url"); new BiliLogin(QQBotManager.defQQ).loginAsQQ();
File code = QRCodeUtils.createQRCode("bili_login", url);
QQBotManager.getInstance().sendMessage(code, qq, "B站未登录,请扫码登陆后再试");
return; return;
} }
signLive(QQBotManager.defQQ, qq); signLive(QQBotManager.defQQ, qq);
@ -50,6 +48,10 @@ public class BiliBiliLive extends Model {
} }
private void signLive(long qq, long sendQQ) { private void signLive(long qq, long sendQQ) {
if(!new BiliLogin(qq).testLogin()){
new BiliLogin(qq).loginAsQQ();
return;
}
BiliBiliUtils biliUtils = BiliBiliUtils.getInstance(qq); BiliBiliUtils biliUtils = BiliBiliUtils.getInstance(qq);
QQBotManager.getInstance().sendMessage(sendQQ, biliUtils.liveSignIn()); QQBotManager.getInstance().sendMessage(sendQQ, biliUtils.liveSignIn());
Set<String> biliLive = RedisTools.list_get("bili_live"); Set<String> biliLive = RedisTools.list_get("bili_live");
@ -98,9 +100,7 @@ public class BiliBiliLive extends Model {
} }
Integer roomId = Integer.parseInt(msg); Integer roomId = Integer.parseInt(msg);
if(!new BiliLogin(qq).testLogin()){ if(!new BiliLogin(qq).testLogin()){
String url = new BiliLogin(user).login().getString("url"); new BiliLogin(qq).loginAsQQ();
File code = QRCodeUtils.createQRCode("bili_login", url);
QQBotManager.getInstance().sendMessage(code, qq, "B站未登录,请扫码登陆后再试");
return; return;
} }
if (biliUtils.checkLiveRoom(roomId) && roomId != 0) { if (biliUtils.checkLiveRoom(roomId) && roomId != 0) {

View File

@ -44,9 +44,7 @@ public class BiliBiliMangeSign extends Model {
} }
QQBotManager.getInstance().sendMessage(qq, msg); QQBotManager.getInstance().sendMessage(qq, msg);
} else { } else {
String url = new BiliLogin(user).login().getString("url"); new BiliLogin(user).loginAsQQ();
File code = QRCodeUtils.createQRCode("bili_login", url);
QQBotManager.getInstance().sendMessage(code, qq, "B站未登录,请扫码登陆后再试");
} }
} else if (msg.equals(QQFromCommands.BILI_MANGA_PAY)) { } else if (msg.equals(QQFromCommands.BILI_MANGA_PAY)) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();