MCPcopy Create free account
hub / github.com/OreosLab/bili / run

Method run

src/main/java/top/misec/task/ChargeMe.java:30–105  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28public class ChargeMe implements Task {
29
30 @Override
31 public void run() {
32 Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+8"));
33 int day = cal.get(Calendar.DATE);
34 //被充电用户的userID
35 String userId = ConfigLoader.helperConfig.getTaskConfig().getChargeForLove();
36
37 String userName = OftenApi.queryUserNameByUid(userId);
38
39 //B币券余额
40 double couponBalance;
41 //大会员类型
42 int vipType = queryVipStatusType();
43
44 if (vipType == 0 || vipType == 1) {
45 log.info("普通会员和月度大会员每月不赠送B币券,所以没法给自己充电哦");
46 return;
47 }
48
49 if (!Boolean.TRUE.equals(ConfigLoader.helperConfig.getTaskConfig().getMonthEndAutoCharge())) {
50 log.info("未开启月底给自己充电功能");
51 return;
52 }
53
54 if ("0".equals(userId) || "".equals(userId)) {
55 log.info("充电对象uid配置错误,请参考最新的文档");
56 return;
57 }
58
59 if (day < ConfigLoader.helperConfig.getTaskConfig().getChargeDay()) {
60 log.info("今天是本月的第: {}天,还没到充电日子呢", day);
61 return;
62 }
63
64
65 log.info("月底自动充电对象是: {}", HelpUtil.userNameEncode(userName));
66
67 if (userInfo != null) {
68 couponBalance = userInfo.getWallet().getCoupon_balance();
69 } else {
70 JsonObject queryJson = HttpUtils.doGet(ApiList.CHARGE_QUERY + "?mid=" + userId);
71 couponBalance = queryJson.getAsJsonObject("data").getAsJsonObject("bp_wallet").get("coupon_balance").getAsDouble();
72 }
73
74 /*
75 判断条件 是月底&&是年大会员&&b币券余额大于2&&配置项允许自动充电.
76 */
77 if (day == ConfigLoader.helperConfig.getTaskConfig().getChargeDay() && couponBalance >= 2) {
78 String requestBody = "bp_num=" + couponBalance
79 + "&is_bp_remains_prior=true"
80 + "&up_mid=" + userId
81 + "&otype=up"
82 + "&oid=" + userId
83 + "&csrf=" + ConfigLoader.helperConfig.getBiliVerify().getBiliJct();
84
85 JsonObject jsonObject = HttpUtils.doPost(ApiList.AUTO_CHARGE, requestBody);
86
87 int resultCode = jsonObject.get(STATUS_CODE_STR).getAsInt();

Callers

nothing calls this directly

Calls 7

queryUserNameByUidMethod · 0.95
userNameEncodeMethod · 0.95
doGetMethod · 0.95
doPostMethod · 0.95
chargeCommentsMethod · 0.95
queryVipStatusTypeMethod · 0.80
getBiliJctMethod · 0.80

Tested by

no test coverage detected