diff --git a/README.md b/README.md index 979bed07..f75d90cb 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,24 @@ # AutoPlan_Helper 这是一个自动化的托管系统,目前支持网易云签到刷歌,bilibili,米游社原神签到 +目前项目属于测试阶段,可能会有些莫名其妙的bug,敬请谅解 + +如果觉得好用,点个**star**吧 + ### 开源地址 [wyt1215819315 / autoplan](https://github.com/wyt1215819315/autoplan) ### 目前已经实现 1. b站每日自动经验任务 +1. b站赛事预测赚硬币任务 2. 网易云自动签到刷歌任务 3. 米游社原神签到领奖励任务以及米游币任务 ### 测试服务器地址 点击打开 +本人不会利用任何cookie,但是为了安全考虑,建议还是自己搭建运行环境 + ### 项目结构 采用Springboot + Thymeleaf + layui制作 @@ -23,7 +30,8 @@ ### 使用说明 #### bilibili -已实现扫码登 +支持b站签到任务以及赛事预测任务 +已实现扫码登录 cookie登录请参考BILIBILI-HELPER-PRE以获取cookie值 #### 网易云 @@ -75,9 +83,7 @@ mybatis: 3. 由于BILIBILI-HELPER-PRE项目大多采用static变量,因此无法多线程运行,也无法手动执行 ### 未来 -1. 参数编辑功能 2. 统一推送,即不用填写多个,仅需在个人中心绑定一个即可 -3. bilibili赛事预测 4. 手动执行b站任务 ### 更新日志 @@ -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. BILIBILI-HELPER-PRE +1. bilibili-match-prediction 2. CloudMusic-LevelUp 3. genshi-helper 4. genshinhelper diff --git a/auto_plan.sql b/auto_plan.sql index 62d7da00..ad4117e3 100644 --- a/auto_plan.sql +++ b/auto_plan.sql @@ -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; @@ -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 @@ -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 diff --git a/src/main/java/com/misec/apiquery/ApiList.java b/src/main/java/com/misec/apiquery/ApiList.java index 53d84041..dfe2dcf8 100644 --- a/src/main/java/com/misec/apiquery/ApiList.java +++ b/src/main/java/com/misec/apiquery/ApiList.java @@ -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"; } diff --git a/src/main/java/com/misec/config/Config.java b/src/main/java/com/misec/config/Config.java index 288a5f7a..99a5bbac 100644 --- a/src/main/java/com/misec/config/Config.java +++ b/src/main/java/com/misec/config/Config.java @@ -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 @@ -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; } @@ -83,6 +94,9 @@ public String toString() { ",\nUA:" + userAgent + "\n" + ",\n是否跳过每日任务:" + skipDailyTask + ",\n任务执行间隔时间" + taskIntervalTime + + ",\n赛事预测总开关" + enablePredict + + ",\n赛事预测单次投注硬币" + predictNumberOfCoins + + ",\n赛事预测保留硬币" + minimumNumberOfCoins + '}'; } @@ -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); } @@ -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(); + } } } diff --git a/src/main/java/com/misec/task/DailyTask.java b/src/main/java/com/misec/task/DailyTask.java index a591972c..687e7074 100644 --- a/src/main/java/com/misec/task/DailyTask.java +++ b/src/main/java/com/misec/task/DailyTask.java @@ -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; @@ -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()); diff --git a/src/main/java/com/misec/task/MatchGame.java b/src/main/java/com/misec/task/MatchGame.java new file mode 100644 index 00000000..8b7c6b69 --- /dev/null +++ b/src/main/java/com/misec/task/MatchGame.java @@ -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 "赛事预测"; + } +} diff --git a/src/main/java/com/oldwu/entity/AutoBilibili.java b/src/main/java/com/oldwu/entity/AutoBilibili.java index dfec70cb..661a2081 100644 --- a/src/main/java/com/oldwu/entity/AutoBilibili.java +++ b/src/main/java/com/oldwu/entity/AutoBilibili.java @@ -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; } \ No newline at end of file diff --git a/src/main/java/com/oldwu/service/BiliService.java b/src/main/java/com/oldwu/service/BiliService.java index 5c992a42..7c729972 100644 --- a/src/main/java/com/oldwu/service/BiliService.java +++ b/src/main/java/com/oldwu/service/BiliService.java @@ -261,7 +261,7 @@ public Map 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(); @@ -308,6 +308,18 @@ public Map 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); diff --git a/src/main/resources/config.json b/src/main/resources/config.json index 133147ab..cccae462 100644 --- a/src/main/resources/config.json +++ b/src/main/resources/config.json @@ -10,5 +10,8 @@ "devicePlatform": "ios", "coinAddPriority": 1, "skipDailyTask": false, + "enablePredict": false, + "predictNumberOfCoins": 10, + "minimumNumberOfCoins": 200, "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36 Edg/91.0.864.54" } \ No newline at end of file diff --git a/src/main/resources/mapper/AutoBilibiliDao.xml b/src/main/resources/mapper/AutoBilibiliDao.xml index b6208bcf..7cd5d5ee 100644 --- a/src/main/resources/mapper/AutoBilibiliDao.xml +++ b/src/main/resources/mapper/AutoBilibiliDao.xml @@ -22,11 +22,14 @@ + + + id, userid, `name`, sessdata, bili_jct, dedeuserid, taskIntervalTime, numberOfCoins, reserveCoins, selectLike, monthEndAutoCharge, giveGift, upLive, chargeForLove, devicePlatform, - coinAddPriority, userAgent, skipDailyTask, SERVERPUSHKEY, other + coinAddPriority, userAgent, skipDailyTask, SERVERPUSHKEY, other,match_enable,match_predictNumberOfCoins,match_minimumNumberOfCoins + + + + + + +