Skip to content

Commit

Permalink
增加了bilibili赛事预测
Browse files Browse the repository at this point in the history
  • Loading branch information
wyt1215819315 committed Sep 5, 2021
1 parent ce63b75 commit ad0d5b3
Show file tree
Hide file tree
Showing 12 changed files with 370 additions and 23 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# AutoPlan_Helper
这是一个自动化的托管系统,目前支持网易云签到刷歌,bilibili,米游社原神签到

目前项目属于测试阶段,可能会有些莫名其妙的bug,敬请谅解

如果觉得好用,点个**star**

### 开源地址
[wyt1215819315 / autoplan](https://github.com/wyt1215819315/autoplan)

### 目前已经实现
1. b站每日自动经验任务
1. b站赛事预测赚硬币任务
2. 网易云自动签到刷歌任务
3. 米游社原神签到领奖励任务以及米游币任务

### 测试服务器地址
<a href="https://auto.oldwu.top/" target="_blank">点击打开</a>

本人不会利用任何cookie,但是为了安全考虑,建议还是自己搭建运行环境

### 项目结构
采用Springboot + Thymeleaf + layui制作

Expand All @@ -23,7 +30,8 @@

### 使用说明
#### bilibili
已实现扫码登
支持b站签到任务以及赛事预测任务
已实现扫码登录

cookie登录请参考<a href="https://github.com/JunzhouLiu/BILIBILI-HELPER-PRE">BILIBILI-HELPER-PRE</a>以获取cookie值
#### 网易云
Expand Down Expand Up @@ -75,9 +83,7 @@ mybatis:
3. 由于BILIBILI-HELPER-PRE项目大多采用static变量,因此无法多线程运行,也无法手动执行

### 未来
1. 参数编辑功能
2. 统一推送,即不用填写多个,仅需在个人中心绑定一个即可
3. bilibili赛事预测
4. 手动执行b站任务

### 更新日志
Expand All @@ -87,10 +93,12 @@ mybatis:
* 21.9.2 增加了编辑参数编辑功能
* 21.9.3 增加了网易云任务和米游社任务的手动执行开关
* 21.9.4 增加了米游社cookie字段,使其能够执行米游币任务
* 21.9.5 修复了非管理员无法使用单次执行任务的问题,修复了米游社任务无权限访问的问题
* 21.9.5 修复了非管理员无法使用单次执行任务的问题,修复了米游社任务无权限访问的问题,修复了bilibili直播送礼物报错的问题
* 21.9.6 增加了bilibili赛事预测

### 鸣谢
1. <a href="https://github.com/JunzhouLiu/BILIBILI-HELPER-PRE">BILIBILI-HELPER-PRE</a>
1. <a href="https://github.com/JunzhouLiu/bilibili-match-prediction">bilibili-match-prediction</a>
2. <a href="https://github.com/secriy/CloudMusic-LevelUp">CloudMusic-LevelUp</a>
3. <a href="https://github.com/PonKing66/genshi-helper">genshi-helper</a>
4. <a href="https://github.com/y1ndan/genshinhelper">genshinhelper</a>
Expand Down
9 changes: 6 additions & 3 deletions auto_plan.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Target Server Version : 80018
File Encoding : 65001
Date: 05/09/2021 12:48:38
Date: 05/09/2021 17:09:52
*/

SET NAMES utf8mb4;
Expand Down Expand Up @@ -42,11 +42,14 @@ CREATE TABLE `auto_bilibili` (
`skipDailyTask` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'false' COMMENT '是否跳过每日任务',
`SERVERPUSHKEY` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '推送地址',
`enddate` datetime(0) NULL DEFAULT NULL,
`match_enable` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'false' COMMENT '预测是否开启',
`match_predictNumberOfCoins` int(11) NOT NULL DEFAULT 10 COMMENT '单次预测投注硬币',
`match_minimumNumberOfCoins` int(11) NOT NULL DEFAULT 200 COMMENT '预测保留硬币',
`other` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `userid`(`userid`) USING BTREE,
CONSTRAINT `auto_bilibili_ibfk_1` FOREIGN KEY (`userid`) REFERENCES `sys_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for auto_log
Expand Down Expand Up @@ -142,7 +145,7 @@ CREATE TABLE `bili_user` (
UNIQUE INDEX `uid`(`uid`) USING BTREE,
INDEX `auto_id`(`auto_id`) USING BTREE,
CONSTRAINT `bili_user_ibfk_1` FOREIGN KEY (`auto_id`) REFERENCES `auto_bilibili` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for sys_role
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/misec/apiquery/ApiList.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,13 @@ public class ApiList {
*/
public static String getBvidByCreate = "https://api.bilibili.com/x/space/arc/search";
public static String getCoinLog ="https://api.bilibili.com/x/member/web/coin/log?jsonp=jsonp";


/**
* 赛事预测部分
*/
public static String queryQuestions = "https://api.bilibili.com/x/esports/guess/collection/question";

public static String queryMatchInfo = "https://api.bilibili.com/x/esports/guess/collection/statis";
public static String doAdd = "https://api.bilibili.com/x/esports/guess/add";
}
26 changes: 26 additions & 0 deletions src/main/java/com/misec/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public class Config {
private String chargeForLove;
private Integer reserveCoins;
private Integer taskIntervalTime;
//预测部分
private Boolean enablePredict;
private Integer predictNumberOfCoins;
private Integer minimumNumberOfCoins;

private static AutoBilibiliDao bilibiliDao;
@Autowired
Expand All @@ -68,6 +72,13 @@ public void getDao(AutoBilibiliDao bilibiliDao){
private Config() {
}

public Integer getPredictNumberOfCoins() {
if (predictNumberOfCoins > 10) {
predictNumberOfCoins = 10;
}
return predictNumberOfCoins;
}

public static Config getInstance() {
return CONFIG;
}
Expand All @@ -83,6 +94,9 @@ public String toString() {
",\nUA:" + userAgent + "\n" +
",\n是否跳过每日任务:" + skipDailyTask +
",\n任务执行间隔时间" + taskIntervalTime +
",\n赛事预测总开关" + enablePredict +
",\n赛事预测单次投注硬币" + predictNumberOfCoins +
",\n赛事预测保留硬币" + minimumNumberOfCoins +
'}';
}

Expand All @@ -107,6 +121,9 @@ public void getConfigJsonFromDateBase(int autoId) {
config.setChargeForLove(autoBilibili.getChargeforlove());
config.setReserveCoins(autoBilibili.getReservecoins());
config.setTaskIntervalTime(autoBilibili.getTaskintervaltime());
config.setEnablePredict(Boolean.parseBoolean(autoBilibili.getMatchEnable()));
config.setPredictNumberOfCoins(autoBilibili.getMatchPredictnumberofcoins());
config.setMinimumNumberOfCoins(autoBilibili.getMatchMinimumnumberofcoins());
Config.CONFIG.merge(config);
}

Expand Down Expand Up @@ -202,5 +219,14 @@ public void merge(Config config) {
taskIntervalTime = 1;
}
}
if (config.getEnablePredict() != null){
enablePredict = config.getEnablePredict();
}
if (config.getPredictNumberOfCoins() != null){
predictNumberOfCoins = config.getPredictNumberOfCoins();
}
if (config.getMinimumNumberOfCoins() != null){
minimumNumberOfCoins = config.getMinimumNumberOfCoins();
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/misec/task/DailyTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.JsonObject;
import com.misec.apiquery.ApiList;
import com.misec.config.Config;
import com.misec.login.ServerVerify;
import com.misec.utils.HttpUtil;
import com.misec.utils.SleepTime;
Expand Down Expand Up @@ -37,6 +38,10 @@ public DailyTask() {
dailyTasks.add(new GiveGift());
dailyTasks.add(new ChargeMe());
dailyTasks.add(new GetVipPrivilege());
Config config = Config.getInstance();
if (config.getEnablePredict()){
dailyTasks.add(new MatchGame());
}
Collections.shuffle(dailyTasks);
dailyTasks.add(0, new UserCheck());
dailyTasks.add(1, new CoinLogs());
Expand Down
164 changes: 164 additions & 0 deletions src/main/java/com/misec/task/MatchGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package com.misec.task;


import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.misec.apiquery.ApiList;
import com.misec.apiquery.OftenApi;
import com.misec.config.Config;
import com.misec.login.Verify;
import com.misec.utils.HttpUtil;
import com.oldwu.log.OldwuLog;
import lombok.extern.log4j.Log4j2;

import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
* @author junzhou
*/
@Log4j2
public class MatchGame implements Task {

@Override
public void run() {

if (OftenApi.getCoinBalance() < Config.getInstance().getMinimumNumberOfCoins()) {
OldwuLog.log(Config.getInstance().getMinimumNumberOfCoins() + "个硬币都没有,参加你\uD83D\uDC34预测呢?任务结束");
log.info("{}个硬币都没有,参加什么预测呢?任务结束", Config.getInstance().getMinimumNumberOfCoins());
return;
}
JsonObject resultJson = queryContestQuestion(getTime(), 1, 50);
JsonObject jsonObject = resultJson.get("data").getAsJsonObject();
if (resultJson.get("code").getAsInt() == 0) {
JsonArray list = jsonObject.get("list").getAsJsonArray();
JsonObject pageinfo = jsonObject.get("page").getAsJsonObject();
if (pageinfo.get("total").getAsInt() == 0) {
log.info("今日无赛事或者本日赛事已经截止预测");
OldwuLog.log("今日无赛事或者本日赛事已经截止预测");
return;
}
if (list != null) {
int coinNumber = Config.getInstance().getPredictNumberOfCoins();
int contestId;
String contestName;
int questionId;
String questionTitle;
int teamId;
String teamName;
int seasonId;
String seasonName;

for (JsonElement listinfo : list) {
log.info("-----预测开始-----");
OldwuLog.log("-----预测开始-----");
JsonObject contestJson = listinfo.getAsJsonObject().getAsJsonObject("contest");
JsonObject questionJson = listinfo.getAsJsonObject().getAsJsonArray("questions")
.get(0).getAsJsonObject();
contestId = contestJson.get("id").getAsInt();
contestName = contestJson.get("game_stage").getAsString();
questionId = questionJson.get("id").getAsInt();
questionTitle = questionJson.get("title").getAsString();
seasonId = contestJson.get("season").getAsJsonObject()
.get("id").getAsInt();
seasonName = contestJson.get("season").getAsJsonObject()
.get("title").getAsString();

log.info(seasonName + " " + contestName + ":" + questionTitle);
OldwuLog.log(seasonName + " " + contestName + ":" + questionTitle);

if (questionJson.get("is_guess").getAsInt() == 1) {
log.info("此问题已经参与过预测了,无需再次预测");
OldwuLog.log("此问题已经参与过预测了,无需再次预测");
continue;
}

JsonObject teamA = questionJson.get("details").getAsJsonArray().get(0).getAsJsonObject();
JsonObject teamB = questionJson.get("details").getAsJsonArray().get(1).getAsJsonObject();

log.info("当前赔率为: {}:{}", teamA.get("odds").getAsDouble(), teamB.get("odds").getAsDouble());
OldwuLog.log("当前赔率为: " + teamA.get("odds").getAsDouble() + ":" + teamB.get("odds").getAsDouble());

if (teamA.get("odds").getAsDouble() >= teamB.get("odds").getAsDouble()) {
teamId = teamB.get("detail_id").getAsInt();
teamName = teamB.get("option").getAsString();
} else {
teamId = teamA.get("detail_id").getAsInt();
teamName = teamA.get("option").getAsString();
}

log.info("拟预测的队伍是:{},预测硬币数为:{}", teamName, coinNumber);
OldwuLog.log("拟预测的队伍是:" + teamName + ",预测硬币数为:" + coinNumber);
doPrediction(contestId, questionId, teamId, coinNumber);
try {
taskSuspend();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
} else {
log.info("获取赛事信息失败");
OldwuLog.error("获取赛事信息失败");
}

}

private void taskSuspend() throws InterruptedException {
Random random = new Random();
int sleepTime = (int) ((random.nextDouble() + 0.5) * 3000);
log.info("-----随机暂停{}ms-----\n", sleepTime);
Thread.sleep(sleepTime);
}

private JsonObject queryContestQuestion(String today, int pn, int ps) {

String gid = "";
String sids = "";
String urlParam = "?pn=" + pn +
"&ps=" + ps
+ "&gid=" + gid
+ "&sids=" + sids
+ "&stime=" + today + URLEncoder.encode(" 00:00:00")
+ "&etime=" + today + URLEncoder.encode(" 23:59:59")
+ "&pn=" + pn
+ "&ps=" + ps
+ "&stime=" + today + "+00:00:00"
+ "&etime=" + today + "+23:59:59";
return HttpUtil.doGet(ApiList.queryQuestions + urlParam);
}

private void doPrediction(int oid, int main_id, int detail_id, int count) {
String requestbody = "oid=" + oid +
"&main_id=" + main_id
+ "&detail_id=" + detail_id
+ "&count=" + count
+ "&is_fav=0"
+ "&csrf=" + Verify.getInstance().getBiliJct();

JsonObject result = HttpUtil.doPost(ApiList.doAdd, requestbody);

if (result.get("code").getAsInt() != 0) {
log.info(result.get("message").getAsString());
OldwuLog.log(result.get("message").getAsString());
} else {
log.info("预测成功");
OldwuLog.log("预测成功");
}

}

private String getTime() {
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(d);
}

@Override
public String getName() {
return "赛事预测";
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/oldwu/entity/AutoBilibili.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,11 @@ public class AutoBilibili implements Serializable {

private String other;

//预测部分
private String matchEnable;
private Integer matchPredictnumberofcoins;
private Integer matchMinimumnumberofcoins;


private static final long serialVersionUID = 1L;
}
14 changes: 13 additions & 1 deletion src/main/java/com/oldwu/service/BiliService.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public Map<String, Object> checkForm(AutoBilibili autoBilibili, boolean skipCook
}
}
Integer taskintervaltime = autoBilibili.getTaskintervaltime();
if (taskintervaltime == null || taskintervaltime < 1) {
if (taskintervaltime == null || taskintervaltime < 1 || taskintervaltime > 100) {
autoBilibili.setTaskintervaltime(10);
}
Integer numberofcoins = autoBilibili.getNumberofcoins();
Expand Down Expand Up @@ -308,6 +308,18 @@ public Map<String, Object> checkForm(AutoBilibili autoBilibili, boolean skipCook
if (StringUtils.isBlank(serverpushkey)) {
autoBilibili.setServerpushkey(null);
}
String matchEnable = autoBilibili.getMatchEnable();
if (StringUtils.isBlank(matchEnable) || !matchEnable.equals("true") && !matchEnable.equals("false")) {
autoBilibili.setMatchEnable("false");
}
Integer predictnumberofcoins = autoBilibili.getMatchPredictnumberofcoins();
if (predictnumberofcoins == null || predictnumberofcoins < 0) {
autoBilibili.setMatchPredictnumberofcoins(10);
}
Integer minimumnumberofcoins = autoBilibili.getMatchMinimumnumberofcoins();
if (minimumnumberofcoins == null || minimumnumberofcoins < 0) {
autoBilibili.setMatchPredictnumberofcoins(200);
}
map.put("flag", true);
map.put("msg", "check complete");
// map.put("data", autoBilibili);
Expand Down
Loading

0 comments on commit ad0d5b3

Please sign in to comment.