add bilibili live signIn

add bilibili live room sign
This commit is contained in:
Yutousama 2022-10-14 13:49:43 +08:00
parent fe48b030d9
commit 8207498f2c
5 changed files with 108 additions and 1 deletions

View File

@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class QQBotApplication { public class QQBotApplication {
public static final String version="QQBot v.1.3.5.2"; public static final String version="QQBot v.1.3.6";
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("version = " + version); System.out.println("version = " + version);
SpringApplication.run(QQBotApplication.class, args); SpringApplication.run(QQBotApplication.class, args);

View File

@ -300,4 +300,33 @@ public class BiliBiliUtils {
File file=BiliBiliUtils.download(url,"16.mp4",false); File file=BiliBiliUtils.download(url,"16.mp4",false);
System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath()); System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath());
} }
public static boolean sendLiveDanmu(long roomId,String msg){
JSONObject body=new JSONObject();
body.put("msg",msg);
body.put("roomid",roomId);
body.put("color",16777215);
body.put("fontsize",25);
body.put("rnd",System.currentTimeMillis()/1000);
body.put("csrf",BiliLogin.getCookieToken());
body.put("csrf_token",BiliLogin.getCookieToken());
JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/msg/send", HttpTools.toUrlParams(body));
return post.getInteger("code")==0;
}
public static String liveSignIn(){
//{"code":0,"data":{"coin":1,"gold":19500,"silver":106394,"tid":"Silver2Coin22101413201169763005873"},"message":"兑换成功"}
JSONObject body=new JSONObject();
body.put("csrf",BiliLogin.getCookieToken());
body.put("csrf_token",BiliLogin.getCookieToken());
JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin", HttpTools.toUrlParams(body));
return post.getString("message");
}
public static boolean checkLiveRoom(int roomId){
JSONObject body=new JSONObject();
body.put("room_id",roomId);
body.put("csrf",BiliLogin.getCookieToken());
body.put("csrf_token",BiliLogin.getCookieToken());
JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/room/v1/Room/get_info", HttpTools.toUrlParams(body));
return post.getInteger("code")==0;
}
} }

View File

@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
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.StringUtils;
import java.io.File; import java.io.File;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -69,6 +70,13 @@ public class BiliLogin {
JSONObject jsonObject = BiliBiliUtils.getLoginInfo(); JSONObject jsonObject = BiliBiliUtils.getLoginInfo();
return jsonObject.getInteger("code")==0; return jsonObject.getInteger("code")==0;
} }
public static String getCookieToken(){
if (StringUtils.isEmpty(ConfigTools.readFile(new File("bilibili.cookie")))) {
return null;
}
JSONObject json = JSON.parseObject(ConfigTools.readFile(new File("bilibili.cookie")));
return json.getString("bili_jct");
}
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -0,0 +1,68 @@
package com.yutou.qqbot.models.BiliBili;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.bilibili.BiliBiliManga;
import com.yutou.qqbot.bilibili.BiliBiliUtils;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.RedisTools;
import net.mamoe.mirai.event.events.MessageEvent;
import java.util.Set;
public class BiliBiliLive extends Model {
@Override
public boolean isUserPublic() {
return false;
}
@Override
public String[] getUsePowers() {
return new String[]{
Model.QQGroupCommands.BILI_LIVE_DANMU_SEND
};
}
@Override
public String getModelName() {
return "BiliBili Live Sign in";
}
@Override
public synchronized void onTime(Long qq, String time) {
super.onTime(qq, time);
if("00:01:00".equals(time)){
QQBotManager.getInstance().sendMessage(qq, BiliBiliUtils.liveSignIn());
Set<String> biliLive = RedisTools.list_get("bili_live");
StringBuilder builder=new StringBuilder();
for (String id : biliLive) {
boolean sign = BiliBiliUtils.sendLiveDanmu(Integer.getInteger(id), "打卡");
builder.append("BiliLiveSign ").append(id).append(":").append(sign).append("\n");
}
QQBotManager.getInstance().sendMessage(qq,builder.toString());
}
}
@Override
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
super.onMessage(qq, event, isGroup);
try {
Integer roomId = Integer.getInteger(msg);
StringBuilder message;
if(BiliBiliUtils.checkLiveRoom(roomId)&&!RedisTools.list_isExist("bili_live",roomId+"")){
RedisTools.list_add("bili_live",roomId+"");
message = new StringBuilder("live sign Add Success");
}else{
message = new StringBuilder("live sign Add Error\n");
message.append("-----live sign roomId-----\n");
Set<String> biliLive = RedisTools.list_get("bili_live");
for (String id : biliLive) {
message.append(id).append("\n");
}
}
QQBotManager.getInstance().sendMessage(qq,message.toString());
}catch (Exception e){
e.printStackTrace();
}
}
}

View File

@ -35,6 +35,8 @@ public abstract class Model implements ModelInterface {
public final static String QQ_BANGUMI_INFO = "!保存动画信息>"; public final static String QQ_BANGUMI_INFO = "!保存动画信息>";
public final static String QQ_MOYU = "!摸鱼"; public final static String QQ_MOYU = "!摸鱼";
public final static String BILI_LIVE_DANMU_SEND="!b站签到";
} }
public static class QQFromCommands { public static class QQFromCommands {