/// <summary> /// 每月1号领取大会员福利(B币券、大会员权益) /// </summary> /// <param name="useInfo"></param> public void ReceiveVipPrivilege(UseInfo useInfo) { if (_dailyTaskOptions.DayOfReceiveVipPrivilege == 0) { _logger.LogInformation("已配置为不进行自动领取会员权益,跳过领取任务"); return; } int targetDay = _dailyTaskOptions.DayOfReceiveVipPrivilege == -1 ? 1 : _dailyTaskOptions.DayOfReceiveVipPrivilege; if (DateTime.Today.Day != targetDay) { _logger.LogInformation("目标领取日期为{targetDay}号,今天是{day}号,跳过领取任务", targetDay, DateTime.Today.Day); return; } //大会员类型 int vipType = useInfo.GetVipType(); if (vipType == 2) { ReceiveVipPrivilege(1); ReceiveVipPrivilege(2); } else { _logger.LogInformation("普通会员和月度大会员每月不赠送B币券,所以不需要领取权益喽"); } }
/// <summary> /// 获取大会员漫画权益 /// </summary> /// <param name="reason_id">权益号,由https://api.bilibili.com/x/vip/privilege/my得到权益号数组,取值范围为数组中的整数 /// 这里为方便直接取1,为领取漫读劵,暂时不取其他的值</param> public void ReceiveMangaVipReward(int reason_id, UseInfo userIfo) { int day = DateTime.Today.Day; if (day != _dailyTaskOptions.DayOfReceiveVipPrivilege) { //一个月执行一次就行 _logger.LogInformation("目标领取日期为{target}号,今天是{day}号,跳过领取任务", _dailyTaskOptions.DayOfReceiveVipPrivilege, day); return; } if (userIfo.GetVipType() == 0) { _logger.LogInformation("不是会员或会员已过期,跳过领取任务"); return; } var response = _mangaApi.ReceiveMangaVipReward(reason_id).Result; if (response.Code == 0) { _logger.LogInformation($"大会员成功领取{response.Data.Amount}张漫读劵"); } else { _logger.LogInformation($"大会员领取漫读劵失败,原因为:{response.Message}"); } }
/// <summary> /// 月底自动给自己充电 /// 仅充会到期的B币券,低于2的时候不会充 /// </summary> public void Charge(UseInfo userInfo) { if (_dailyTaskOptions.DayOfAutoCharge == 0) { _logger.LogInformation("已配置为不进行自动充电,跳过充电任务"); return; } int targetDay = _dailyTaskOptions.DayOfAutoCharge == -1 ? DateTime.Today.LastDayOfMonth().Day : _dailyTaskOptions.DayOfAutoCharge; if (DateTime.Today.Day != targetDay) { _logger.LogInformation("目标充电日期为{targetDay}号,今天是{today}号,跳过充电任务", targetDay, DateTime.Today.Day); return; } //B币券余额 decimal couponBalance = userInfo.Wallet.Coupon_balance; if (couponBalance < 2) { _logger.LogInformation("不是年度大会员或已过期,无法充电"); return; } //大会员类型 int vipType = userInfo.GetVipType(); if (vipType != 2) { _logger.LogInformation("不是年度大会员或已过期,无法充电"); return; } BiliApiResponse <ChargeResponse> response = _dailyTaskApi.Charge(couponBalance * 10, _cookieOptions.UserId, _cookieOptions.UserId, _cookieOptions.BiliJct).Result; if (response.Code == 0) { if (response.Data.Status == 4) { _logger.LogInformation("给自己充电成功啦,送的B币券没有浪费哦"); _logger.LogInformation("本次给自己充值了: {num}个电池哦", couponBalance * 10); //获取充电留言token ChargeComments(response.Data.Order_no); } else { _logger.LogDebug("充电失败了啊 原因:{reason}", response.ToJson()); } } else { _logger.LogDebug("充电失败了啊 原因:{reason}", response.Message); } }