From 9e217f72bb2f2860b2753002c9af479a517ac1ce Mon Sep 17 00:00:00 2001 From: Polaris_cn Date: Sun, 21 Apr 2024 03:35:56 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BF=AE=E5=A4=8D=E5=A4=A7?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E5=8A=9F=E8=83=BD=20(#685)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 根据api进行修改,等待测试 * 待实现:观看剧集内容 --- .../Interfaces/IVipBigPointApi.cs | 28 +- .../VipBigPointAppService.cs | 1072 ++++++++--------- test/AppServiceTest/VipServiceTest.cs | 22 +- 3 files changed, 537 insertions(+), 585 deletions(-) diff --git a/src/Ray.BiliBiliTool.Agent/BiliBiliAgent/Interfaces/IVipBigPointApi.cs b/src/Ray.BiliBiliTool.Agent/BiliBiliAgent/Interfaces/IVipBigPointApi.cs index d1743803c..3e762e179 100644 --- a/src/Ray.BiliBiliTool.Agent/BiliBiliAgent/Interfaces/IVipBigPointApi.cs +++ b/src/Ray.BiliBiliTool.Agent/BiliBiliAgent/Interfaces/IVipBigPointApi.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; +using System.Threading.Tasks; using Ray.BiliBiliTool.Agent.Attributes; using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos; using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos.VipTask; @@ -12,45 +10,49 @@ namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces /// 大会员大积分 /// [Header("Host", "api.bilibili.com")] + [Header("User-Agent", + "Mozilla/5.0 (Linux; Android 9; SM-N9700 Build/PQ3A.190605.04081832; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/91.0.4472.114 Safari/537.36 Mobile os/android model/SM-N9700 build/7300400 osVer/9 sdkInt/28 network/2 BiliApp/7300400 mobi_app/android channel/alifenfa Buvid/XY77D6C72ECDC63147110C5C8D1DA34D38CD1 sessionID/9795ed5c innerVer/7300400 c_locale/zh_CN s_locale/zh_CN disable_rcmd/0 7.30.0 os/android model/SM-N9700 mobi_app/android build/7300400 channel/alifenfa innerVer/7300400 osVer/9 network/2")] [LogFilter] public interface IVipBigPointApi { [Header("Referer", "https://big.bilibili.com/mobile/bigPoint/task")] - [Header("User-Agent", "Mozilla/5.0 (Linux; Android 6.0.1; MuMu Build/V417IR; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.158 Mobile Safari/537.36 os/android model/MuMu build/6720300 osVer/6.0.1 sdkInt/23 network/2 BiliApp/6720300 mobi_app/android channel/html5_search_baidu Buvid/XZFC135F5263B6897C8A4BE7AEB125BBF10F8 sessionID/72d3f4c9 innerVer/6720310 c_locale/zh_CN s_locale/zh_CN disable_rcmd/0 6.72.0 os/android model/MuMu mobi_app/android build/6720300 channel/html5_search_baidu innerVer/6720310 osVer/6.0.1 network/2")] [HttpGet("/x/vip_point/task/combine")] Task> GetTaskList(); - + [Header("Referer", "https://www.bilibili.com")] [HttpPost("/pgc/activity/score/task/sign")] Task Sign([FormContent] SignRequest request); [Header("Referer", "https://big.bilibili.com/mobile/bigPoint/task")] - [Header("User-Agent", "Mozilla/5.0 (Linux; Android 6.0.1; MuMu Build/V417IR; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.158 Mobile Safari/537.36 os/android model/MuMu build/6720300 osVer/6.0.1 sdkInt/23 network/2 BiliApp/6720300 mobi_app/android channel/html5_search_baidu Buvid/XZFC135F5263B6897C8A4BE7AEB125BBF10F8 sessionID/72d3f4c9 innerVer/6720310 c_locale/zh_CN s_locale/zh_CN disable_rcmd/0 6.72.0 os/android model/MuMu mobi_app/android build/6720300 channel/html5_search_baidu innerVer/6720310 osVer/6.0.1 network/2")] [HttpPost("/pgc/activity/score/task/receive")] Task Receive([JsonContent] ReceiveOrCompleteTaskRequest request); [Header("Referer", "https://big.bilibili.com/mobile/bigPoint/task")] - [Header("User-Agent", "Mozilla/5.0 (Linux; Android 6.0.1; MuMu Build/V417IR; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.158 Mobile Safari/537.36 os/android model/MuMu build/6720300 osVer/6.0.1 sdkInt/23 network/2 BiliApp/6720300 mobi_app/android channel/html5_search_baidu Buvid/XZFC135F5263B6897C8A4BE7AEB125BBF10F8 sessionID/72d3f4c9 innerVer/6720310 c_locale/zh_CN s_locale/zh_CN disable_rcmd/0 6.72.0 os/android model/MuMu mobi_app/android build/6720300 channel/html5_search_baidu innerVer/6720310 osVer/6.0.1 network/2")] + [HttpPost("/pgc/activity/score/task/receive/v2")] + Task ReceiveV2([FormContent] ReceiveOrCompleteTaskRequest request); + + + [Header("Referer", "https://big.bilibili.com/mobile/bigPoint/task")] [HttpPost("/pgc/activity/score/task/complete")] Task Complete([JsonContent] ReceiveOrCompleteTaskRequest request); [Header("Referer", "https://big.bilibili.com/mobile/bigPoint/task")] - [Header("User-Agent", "Mozilla/5.0 (Linux; Android 6.0.1; MuMu Build/V417IR; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.158 Mobile Safari/537.36 os/android model/MuMu build/6720300 osVer/6.0.1 sdkInt/23 network/2 BiliApp/6720300 mobi_app/android channel/html5_search_baidu Buvid/XZFC135F5263B6897C8A4BE7AEB125BBF10F8 sessionID/72d3f4c9 innerVer/6720310 c_locale/zh_CN s_locale/zh_CN disable_rcmd/0 6.72.0 os/android model/MuMu mobi_app/android build/6720300 channel/html5_search_baidu innerVer/6720310 osVer/6.0.1 network/2")] + [HttpPost("/pgc/activity/score/task/complete/v2")] + Task CompleteV2([FormContent] ReceiveOrCompleteTaskRequest request); + + + [Header("Referer", "https://big.bilibili.com/mobile/bigPoint/task")] [HttpPost("/pgc/activity/deliver/task/complete")] Task ViewComplete([FormContent] ViewRequest request); [Header("Referer", "https://big.bilibili.com/mobile/bigPoint/task")] - [Header("User-Agent", "Mozilla/5.0 (Linux; Android 6.0.1; MuMu Build/V417IR; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.158 Mobile Safari/537.36 os/android model/MuMu build/6720300 osVer/6.0.1 sdkInt/23 network/2 BiliApp/6720300 mobi_app/android channel/html5_search_baidu Buvid/XZFC135F5263B6897C8A4BE7AEB125BBF10F8 sessionID/72d3f4c9 innerVer/6720310 c_locale/zh_CN s_locale/zh_CN disable_rcmd/0 6.72.0 os/android model/MuMu mobi_app/android build/6720300 channel/html5_search_baidu innerVer/6720310 osVer/6.0.1 network/2")] [HttpGet("/x/vip/privilege/my")] Task> GetVouchersInfo(); [Header("Referer", "https://big.bilibili.com/mobile/bigPoint/task")] - [Header("User-Agent", "Mozilla/5.0 (Linux; Android 6.0.1; MuMu Build/V417IR; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.158 Mobile Safari/537.36 os/android model/MuMu build/6720300 osVer/6.0.1 sdkInt/23 network/2 BiliApp/6720300 mobi_app/android channel/html5_search_baidu Buvid/XZFC135F5263B6897C8A4BE7AEB125BBF10F8 sessionID/72d3f4c9 innerVer/6720310 c_locale/zh_CN s_locale/zh_CN disable_rcmd/0 6.72.0 os/android model/MuMu mobi_app/android build/6720300 channel/html5_search_baidu innerVer/6720310 osVer/6.0.1 network/2")] - [Header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")] + // [Header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")] [HttpPost("/x/vip/experience/add")] Task GetVipExperience([FormContent] VipExperienceRequest request); - - } } diff --git a/src/Ray.BiliBiliTool.Application/VipBigPointAppService.cs b/src/Ray.BiliBiliTool.Application/VipBigPointAppService.cs index d8de26c41..6d4f63c81 100644 --- a/src/Ray.BiliBiliTool.Application/VipBigPointAppService.cs +++ b/src/Ray.BiliBiliTool.Application/VipBigPointAppService.cs @@ -17,722 +17,652 @@ using Ray.BiliBiliTool.DomainService.Dtos; using Ray.BiliBiliTool.DomainService.Interfaces; -namespace Ray.BiliBiliTool.Application +namespace Ray.BiliBiliTool.Application; + +public class VipBigPointAppService : AppService, IVipBigPointAppService { - public class VipBigPointAppService : AppService, IVipBigPointAppService + private readonly ILogger _logger; + private readonly IConfiguration _configuration; + private readonly IVipBigPointApi _vipApi; + private readonly IAccountDomainService _loginDomainService; + private readonly IVideoDomainService _videoDomainService; + private readonly IAccountDomainService _accountDomainService; + private readonly BiliCookie _biliCookie; + private readonly IVipMallApi _vipMallApi; + private readonly IVideoApi _videoApi; + private readonly VipBigPointOptions _vipBigPointOptions; + + public VipBigPointAppService( + IConfiguration configuration, + ILogger logger, + IVipBigPointApi vipApi, + IAccountDomainService loginDomainService, + IVideoDomainService videoDomainService, + BiliCookie biliCookie, + IAccountDomainService accountDomainService, + IVipMallApi vipMallApi, + IVideoApi videoApi, + IOptionsMonitor vipBigPointOptions) { - private readonly ILogger _logger; - private readonly IConfiguration _configuration; - private readonly IVipBigPointApi _vipApi; - private readonly IAccountDomainService _loginDomainService; - private readonly IVideoDomainService _videoDomainService; - private readonly IAccountDomainService _accountDomainService; - private readonly BiliCookie _biliCookie; - private readonly IVipMallApi _vipMallApi; - private readonly IVideoApi _videoApi; - private readonly VipBigPointOptions _vipBigPointOptions; - - public VipBigPointAppService( - IConfiguration configuration, - ILogger logger, - IVipBigPointApi vipApi, - IAccountDomainService loginDomainService, - IVideoDomainService videoDomainService, - BiliCookie biliCookie, - IAccountDomainService accountDomainService, - IVipMallApi vipMallApi, - IVideoApi videoApi, - IOptionsMonitor vipBigPointOptions) - { - _configuration = configuration; - _logger = logger; - _vipApi = vipApi; - _loginDomainService = loginDomainService; - _videoDomainService = videoDomainService; - _biliCookie = biliCookie; - _accountDomainService = accountDomainService; - _vipMallApi = vipMallApi; - _videoApi = videoApi; - _vipBigPointOptions = vipBigPointOptions.CurrentValue; - } - - public async Task VipExpress() - { - _logger.LogInformation("大会员经验领取任务开始"); - var re = await _vipApi.GetVouchersInfo(); - if (re.Code == 0) - { - var state = re.Data.List.Find(x => x.Type == 9).State; - - switch (state) - { - case 2: - _logger.LogInformation("大会员经验观看任务未完成"); - _logger.LogInformation("开始观看视频"); - // 观看视频,暂时没有好办法解决,先这样使着 - DailyTaskInfo dailyTaskInfo = await _accountDomainService.GetDailyTaskStatus(); - await _videoDomainService.WatchAndShareVideo(dailyTaskInfo); - // 跳转到未兑换,执行兑换任务 - goto case 0; - - case 1: - _logger.LogInformation("大会员经验已兑换"); - break; + _configuration = configuration; + _logger = logger; + _vipApi = vipApi; + _loginDomainService = loginDomainService; + _videoDomainService = videoDomainService; + _biliCookie = biliCookie; + _accountDomainService = accountDomainService; + _vipMallApi = vipMallApi; + _videoApi = videoApi; + _vipBigPointOptions = vipBigPointOptions.CurrentValue; + } - case 0: - _logger.LogInformation("大会员经验未兑换"); - //兑换api - var response = await _vipApi.GetVipExperience(new VipExperienceRequest() - { - csrf = _biliCookie.BiliJct - }); - if (response.Code != 0) - { - _logger.LogInformation("大会员经验领取失败,错误信息:{message}", response.Message); - break; - } - _logger.LogInformation("领取成功,经验+10 √"); + /// + /// 领取大会员专属经验包 + /// + public async Task VipExpress() + { + _logger.LogInformation("大会员经验领取任务开始"); + var re = await _vipApi.GetVouchersInfo(); + if (re.Code == 0) + { + var state = re.Data.List.Find(x => x.Type == 9).State; + + switch (state) + { + case 2: + _logger.LogInformation("大会员经验观看任务未完成"); + _logger.LogInformation("开始观看视频"); + // 观看视频,暂时没有好办法解决,先这样使着 + DailyTaskInfo dailyTaskInfo = await _accountDomainService.GetDailyTaskStatus(); + await _videoDomainService.WatchAndShareVideo(dailyTaskInfo); + // 跳转到未兑换,执行兑换任务 + goto case 0; + + case 1: + _logger.LogInformation("大会员经验已兑换"); + break; + + case 0: + _logger.LogInformation("大会员经验未兑换"); + //兑换api + var response = await _vipApi.GetVipExperience(new VipExperienceRequest() + { + csrf = _biliCookie.BiliJct + }); + if (response.Code != 0) + { + _logger.LogInformation("大会员经验领取失败,错误信息:{message}", response.Message); break; + } - default: - _logger.LogDebug("大会员经验领取失败,未知错误"); - break; - } + _logger.LogInformation("领取成功,经验+10 √"); + break; + default: + _logger.LogDebug("大会员经验领取失败,未知错误"); + break; } - } + } - [TaskInterceptor("大会员大积分", TaskLevel.One)] - public override async Task DoTaskAsync(CancellationToken cancellationToken) - { - // TODO 解决taskInfo在一个任务出错后,后续的任务均会报空引用错误 - var ui = await GetUserInfo(); + [TaskInterceptor("大会员大积分", TaskLevel.One)] + public override async Task DoTaskAsync(CancellationToken cancellationToken) + { + // TODO 解决taskInfo在一个任务出错后,后续的任务均会报空引用错误 + var ui = await GetUserInfo(); - if (ui.GetVipType() == VipType.None) - { - _logger.LogInformation("当前不是大会员或已过期,跳过任务"); - return; - } + if (ui.GetVipType() == VipType.None) + { + _logger.LogInformation("当前不是大会员或已过期,跳过任务"); + return; + } - var re = await _vipApi.GetTaskList(); + var re = await _vipApi.GetTaskList(); - if (re.Code != 0) throw new Exception(re.ToJsonStr()); + if (re.Code != 0) throw new Exception(re.ToJsonStr()); - VipTaskInfo taskInfo = re.Data; - taskInfo.LogInfo(_logger); + VipTaskInfo taskInfo = re.Data; + taskInfo.LogInfo(_logger); - await VipExpress(); + await VipExpress(); - //签到 - taskInfo = await Sign(taskInfo); + //签到 + taskInfo = await Sign(taskInfo); - //福利任务 - taskInfo = await Bonus(taskInfo); + //福利任务 + taskInfo = await Bonus(taskInfo); - //体验任务 - taskInfo = await Privilege(taskInfo); + //体验任务 + taskInfo = await Privilege(taskInfo); - //日常任务 + //日常任务 - //浏览追番频道页10秒 - taskInfo = await ViewAnimate(taskInfo); + //浏览追番频道页10秒 + taskInfo = await ViewAnimate(taskInfo); - //浏览影视频道页10秒 - // taskInfo = await ViewFilmChannel(taskInfo); + //浏览会员购页面10秒 + taskInfo = await ViewVipMall(taskInfo); - //浏览会员购页面10秒 - taskInfo = await ViewVipMall(taskInfo); + //浏览装扮商城 + taskInfo = await ViewDressMall(taskInfo); - //浏览装扮商城 - taskInfo = await ViewDressMall(taskInfo); + //观看剧集内容 + taskInfo = await ViewVideo(taskInfo); - //观看任意正片内容 - taskInfo = await ViewVideo(taskInfo); + //领取购买任务 + taskInfo = await BuyVipVideo(taskInfo); + taskInfo = await BuyVipMall(taskInfo); - + taskInfo.LogInfo(_logger); + } - //领取购买任务 - taskInfo = await BuyVipVideo(taskInfo); - // taskInfo = await BuyVipProduct(taskInfo); - taskInfo = await BuyVipMall(taskInfo); - - taskInfo.LogInfo(_logger); + [TaskInterceptor("测试Cookie")] + private async Task GetUserInfo() + { + UserInfo userInfo = await _loginDomainService.LoginByCookie(); + if (userInfo == null) throw new Exception("登录失败,请检查Cookie"); //终止流程 - - } + return userInfo; + } - [TaskInterceptor("测试Cookie")] - private async Task GetUserInfo() + [TaskInterceptor("签到", TaskLevel.Two, false)] + private async Task Sign(VipTaskInfo info) + { + if (info.Task_info.Sing_task_item.IsTodaySigned) { - UserInfo userInfo = await _loginDomainService.LoginByCookie(); - if (userInfo == null) throw new Exception("登录失败,请检查Cookie");//终止流程 - - return userInfo; + _logger.LogInformation("已完成,跳过"); + _logger.LogInformation("今日获得签到积分:{score}", info.Task_info.Sing_task_item.TodayHistory?.Score); + _logger.LogInformation("累计签到{count}天", info.Task_info.Sing_task_item.Count); + return info; } - [TaskInterceptor("签到", TaskLevel.Two, false)] - private async Task Sign(VipTaskInfo info) - { - if (info.Task_info.Sing_task_item.IsTodaySigned) - { - _logger.LogInformation("已完成,跳过"); - _logger.LogInformation("今日获得签到积分:{score}", info.Task_info.Sing_task_item.TodayHistory?.Score); - _logger.LogInformation("累计签到{count}天", info.Task_info.Sing_task_item.Count); - return info; - } + var re = await _vipApi.Sign(new SignRequest()); + if (re.Code != 0) throw new Exception(re.ToJsonStr()); - var re = await _vipApi.Sign(new SignRequest()); - if (re.Code != 0) throw new Exception(re.ToJsonStr()); + //确认 + var infoResult = await _vipApi.GetTaskList(); + if (infoResult.Code != 0) throw new Exception(infoResult.ToJsonStr()); + info = infoResult.Data; - //确认 - var infoResult = await _vipApi.GetTaskList(); - if (infoResult.Code != 0) throw new Exception(infoResult.ToJsonStr()); - info = infoResult.Data; + _logger.LogInformation("今日可获得签到积分:{score}", info.Task_info.Sing_task_item.TodayHistory?.Score); + _logger.LogInformation(info.Task_info.Sing_task_item.IsTodaySigned ? "签到成功" : "签到失败"); + _logger.LogInformation("累计签到{count}天", info.Task_info.Sing_task_item.Count); - _logger.LogInformation("今日可获得签到积分:{score}", info.Task_info.Sing_task_item.TodayHistory?.Score); - _logger.LogInformation(info.Task_info.Sing_task_item.IsTodaySigned ? "签到成功" : "签到失败"); - _logger.LogInformation("累计签到{count}天", info.Task_info.Sing_task_item.Count); + return info; + } + + [TaskInterceptor("福利任务", TaskLevel.Two, false)] + private async Task Bonus(VipTaskInfo info) + { + var bonusTask = GetTarget(info); + //如果状态不等于3,则做 + if (bonusTask.state == 3) + { + _logger.LogInformation("已完成,跳过"); return info; } - [TaskInterceptor("福利任务", TaskLevel.Two, false)] - private async Task Bonus(VipTaskInfo info) + //0需要领取 + if (bonusTask.state == 0) { - var bonusTask = GetTarget(info); + _logger.LogInformation("开始领取任务"); + await TryReceive(bonusTask.task_code); + } - //如果状态不等于3,则做 - if (bonusTask.state == 3) - { - _logger.LogInformation("已完成,跳过"); - return info; - } + _logger.LogInformation("开始完成任务"); + var re = await Complete(bonusTask.task_code); - //0需要领取 - if (bonusTask.state == 0) - { - _logger.LogInformation("开始领取任务"); - await TryReceive(bonusTask.task_code); - } + //确认 + if (re) + { + var infoResult = await _vipApi.GetTaskList(); + if (infoResult.Code != 0) throw new Exception(infoResult.ToJsonStr()); + info = infoResult.Data; + bonusTask = GetTarget(info); - _logger.LogInformation("开始完成任务"); - var re = await Complete(bonusTask.task_code); + _logger.LogInformation("确认:{re}", bonusTask.state == 3 && bonusTask.complete_times >= 1); + } - //确认 - if (re) - { - var infoResult = await _vipApi.GetTaskList(); - if (infoResult.Code != 0) throw new Exception(infoResult.ToJsonStr()); - info = infoResult.Data; - bonusTask = GetTarget(info); + return info; - _logger.LogInformation("确认:{re}", bonusTask.state == 3 && bonusTask.complete_times >= 1); - } + CommonTaskItem GetTarget(VipTaskInfo info) + { + return info.Task_info.Modules.First(x => x.module_title == "福利任务") + .common_task_item + .First(x => x.task_code == "bonus"); + } + } - return info; + [TaskInterceptor("体验任务", TaskLevel.Two, false)] + private async Task Privilege(VipTaskInfo info) + { + var privilegeTask = GetTarget(info); - CommonTaskItem GetTarget(VipTaskInfo info) - { - return info.Task_info.Modules.First(x => x.module_title == "福利任务") - .common_task_item - .First(x => x.task_code == "bonus"); - } + //如果状态不等于3,则做 + if (privilegeTask.state == 3) + { + _logger.LogInformation("已完成,跳过"); + return info; } - [TaskInterceptor("体验任务", TaskLevel.Two, false)] - private async Task Privilege(VipTaskInfo info) + //0需要领取 + if (privilegeTask.state == 0) { - var privilegeTask = GetTarget(info); + _logger.LogInformation("开始领取任务"); + await TryReceive(privilegeTask.task_code); + } - //如果状态不等于3,则做 - if (privilegeTask.state == 3) - { - _logger.LogInformation("已完成,跳过"); - return info; - } + _logger.LogInformation("开始完成任务"); + var re = await Complete(privilegeTask.task_code); - //0需要领取 - if (privilegeTask.state == 0) - { - _logger.LogInformation("开始领取任务"); - await TryReceive(privilegeTask.task_code); - } + //确认 + if (re) + { + var infoResult = await _vipApi.GetTaskList(); + if (infoResult.Code != 0) throw new Exception(infoResult.ToJsonStr()); + info = infoResult.Data; + privilegeTask = GetTarget(info); - _logger.LogInformation("开始完成任务"); - var re = await Complete(privilegeTask.task_code); + _logger.LogInformation("确认:{re}", privilegeTask.state == 3 && privilegeTask.complete_times >= 1); + } - //确认 - if (re) - { - var infoResult = await _vipApi.GetTaskList(); - if (infoResult.Code != 0) throw new Exception(infoResult.ToJsonStr()); - info = infoResult.Data; - privilegeTask = GetTarget(info); + CommonTaskItem GetTarget(VipTaskInfo info) + { + return info.Task_info.Modules.First(x => x.module_title == "体验任务") + .common_task_item + .First(x => x.task_code == "privilege"); + } - _logger.LogInformation("确认:{re}", privilegeTask.state == 3 && privilegeTask.complete_times >= 1); - } + return info; + } - CommonTaskItem GetTarget(VipTaskInfo info) - { - return info.Task_info.Modules.First(x => x.module_title == "体验任务") - .common_task_item - .First(x => x.task_code == "privilege"); - } + [TaskInterceptor("浏览追番频道页10秒", TaskLevel.Two, false)] + private async Task ViewAnimate(VipTaskInfo info) + { + var code = "jp_channel"; + CommonTaskItem targetTask = GetTarget(info); + + //如果状态不等于3,则做 + if (targetTask.state == 3) + { + _logger.LogInformation("已完成,跳过"); return info; } - [TaskInterceptor("浏览追番频道页10秒", TaskLevel.Two, false)] - private async Task ViewAnimate(VipTaskInfo info) + //0需要领取 + if (targetTask.state == 0) { - var code = "jp_channel"; + _logger.LogInformation("开始领取任务"); + await TryReceive(targetTask.task_code); + } - CommonTaskItem targetTask = GetTarget(info); + _logger.LogInformation("开始完成任务"); + var re = await CompleteView(code); - //如果状态不等于3,则做 - if (targetTask.state == 3) - { - _logger.LogInformation("已完成,跳过"); - return info; - } + //确认 + if (re) + { + var infoResult = await _vipApi.GetTaskList(); + if (infoResult.Code != 0) throw new Exception(infoResult.ToJsonStr()); + info = infoResult.Data; + targetTask = GetTarget(info); - //0需要领取 - if (targetTask.state == 0) - { - _logger.LogInformation("开始领取任务"); - await TryReceive(targetTask.task_code); - } - - _logger.LogInformation("开始完成任务"); - var re = await CompleteView(code); + _logger.LogInformation("确认:{re}", targetTask.state == 3 && targetTask.complete_times >= 1); + } - //确认 - if (re) - { - var infoResult = await _vipApi.GetTaskList(); - if (infoResult.Code != 0) throw new Exception(infoResult.ToJsonStr()); - info = infoResult.Data; - targetTask = GetTarget(info); + CommonTaskItem GetTarget(VipTaskInfo info) + { + return info.Task_info.Modules.First(x => x.module_title == "日常任务") + .common_task_item + .First(x => x.task_code == "animatetab"); + } - _logger.LogInformation("确认:{re}", targetTask.state == 3 && targetTask.complete_times >= 1); - } + return info; + } - CommonTaskItem GetTarget(VipTaskInfo info) - { - return info.Task_info.Modules.First(x => x.module_title == "日常任务") - .common_task_item - .First(x => x.task_code == "animatetab"); - } + [TaskInterceptor("浏览会员购页面10秒", TaskLevel.Two, false)] + private async Task ViewVipMall(VipTaskInfo info) + { + CommonTaskItem targetTask = GetTarget(info); + //如果状态不等于3,则做 + if (targetTask.state == 3) + { + _logger.LogInformation("已完成,跳过"); return info; } - [TaskInterceptor("浏览会员购页面10秒", TaskLevel.Two, false)] - private async Task ViewVipMall(VipTaskInfo info) + //0需要领取 + if (targetTask.state == 0) { - CommonTaskItem targetTask = GetTarget(info); + _logger.LogInformation("开始领取任务"); + await TryReceive(targetTask.task_code); + } - //如果状态不等于3,则做 - if (targetTask.state == 3) - { - _logger.LogInformation("已完成,跳过"); - return info; - } + _logger.LogInformation("开始完成任务"); + var re = await _vipMallApi.ViewVipMall(new ViewVipMallRequest() + { + Csrf = _biliCookie.BiliJct + }); + if (re.Code != 0) throw new Exception(re.ToJsonStr()); - //0需要领取 - if (targetTask.state == 0) - { - _logger.LogInformation("开始领取任务"); - await TryReceive(targetTask.task_code); - } + //确认 + if (re.Code == 0) + { + var infoResult = await _vipApi.GetTaskList(); + if (infoResult.Code != 0) throw new Exception(infoResult.ToJsonStr()); + info = infoResult.Data; + targetTask = GetTarget(info); - _logger.LogInformation("开始完成任务"); - var re = await _vipMallApi.ViewVipMall(new ViewVipMallRequest() - { - Csrf = _biliCookie.BiliJct - }); - if (re.Code != 0) throw new Exception(re.ToJsonStr()); + _logger.LogInformation("确认:{re}", targetTask.state == 3 && targetTask.complete_times >= 1); + } - //确认 - if (re.Code == 0) - { - var infoResult = await _vipApi.GetTaskList(); - if (infoResult.Code != 0) throw new Exception(infoResult.ToJsonStr()); - info = infoResult.Data; - targetTask = GetTarget(info); + CommonTaskItem GetTarget(VipTaskInfo info) + { + return info.Task_info.Modules.First(x => x.module_title == "日常任务") + .common_task_item + .First(x => x.task_code == "vipmallview"); + } - _logger.LogInformation("确认:{re}", targetTask.state == 3 && targetTask.complete_times >= 1); - } + return info; + } - CommonTaskItem GetTarget(VipTaskInfo info) - { - return info.Task_info.Modules.First(x => x.module_title == "日常任务") - .common_task_item - .First(x => x.task_code == "vipmallview"); - } + [TaskInterceptor("观看剧集内容", TaskLevel.Two, false)] + private async Task ViewVideo(VipTaskInfo info) + { + CommonTaskItem targetTask = GetTarget(info); + + // 如果状态不等于3,则做 + if (targetTask.state == 3) + { + _logger.LogInformation("已完成,跳过"); return info; } - [TaskInterceptor("观看任意正片内容", TaskLevel.Two, false)] - private async Task ViewVideo(VipTaskInfo info) + //0需要领取 + if (targetTask.state == 0) { - CommonTaskItem targetTask = GetTarget(info); - - // 如果状态不等于3,则做 - if (targetTask.state == 3) - { - _logger.LogInformation("已完成,跳过"); - return info; - } - - //0需要领取 - if (targetTask.state == 0) - { - _logger.LogInformation("开始领取任务"); - await TryReceive(targetTask.task_code); - } - - _logger.LogInformation("开始完成任务"); - _logger.LogInformation("观看第一个正片内容"); + _logger.LogInformation("开始领取任务"); + await TryReceive(targetTask.task_code); + } - await WatchBangumi(); + _logger.LogInformation("开始完成任务"); - _logger.LogInformation("观看第二个正片内容"); + // 观看剧集内容 + _logger.LogInformation("api变更,暂未实现"); - //等待40s - await Task.Delay(TimeSpan.FromSeconds(40)); + CommonTaskItem GetTarget(VipTaskInfo info) + { + return info.Task_info.Modules.First(x => x.module_title == "日常任务") + .common_task_item + .First(x => x.task_code == "ogvwatchnew"); + } - await WatchBangumi(); + return info; + } - CommonTaskItem GetTarget(VipTaskInfo info) - { - return info.Task_info.Modules.First(x => x.module_title == "日常任务") - .common_task_item - .First(x => x.task_code == "ogvwatch"); - } + [TaskInterceptor("购买单点付费影片(仅领取)", TaskLevel.Two, false)] + private async Task BuyVipVideo(VipTaskInfo info) + { + CommonTaskItem targetTask = GetTarget(info); + if (targetTask.state is 3 or 1) + { + var re = targetTask.state == 1 ? "已领取" : "已完成"; + _logger.LogInformation("{re},跳过", re); return info; } - [TaskInterceptor("购买单点付费影片(仅领取)", TaskLevel.Two, false)] - private async Task BuyVipVideo(VipTaskInfo info) + //0需要领取 + if (targetTask.state == 0) { - CommonTaskItem targetTask = GetTarget(info); - - if (targetTask.state is 3 or 1) - { - var re = targetTask.state == 1 ? "已领取" : "已完成"; - _logger.LogInformation("{re},跳过", re); - return info; - } - - //0需要领取 - if (targetTask.state == 0) - { - _logger.LogInformation("开始领取任务"); - await TryReceive(targetTask.task_code); - } - - return info; - - CommonTaskItem GetTarget(VipTaskInfo info) - { - return info.Task_info.Modules.First(x => x.module_title == "日常任务") - .common_task_item - .First(x => x.task_code == "tvodbuy"); - } + _logger.LogInformation("开始领取任务"); + await TryReceive(targetTask.task_code); } - [TaskInterceptor("购买指定会员购商品(仅领取)", TaskLevel.Two, false)] - private async Task BuyVipMall(VipTaskInfo info) - { - CommonTaskItem targetTask = GetTarget(info); + return info; - if (targetTask.state is 3 or 1) - { - var re = targetTask.state == 1 ? "已领取" : "已完成"; - _logger.LogInformation("{re},跳过", re); - return info; - } + CommonTaskItem GetTarget(VipTaskInfo info) + { + return info.Task_info.Modules.First(x => x.module_title == "日常任务") + .common_task_item + .First(x => x.task_code == "tvodbuy"); + } + } - //0需要领取 - if (targetTask.state == 0) - { - _logger.LogInformation("开始领取任务"); - await TryReceive(targetTask.task_code); - } + [TaskInterceptor("购买指定会员购商品(仅领取)", TaskLevel.Two, false)] + private async Task BuyVipMall(VipTaskInfo info) + { + CommonTaskItem targetTask = GetTarget(info); + if (targetTask.state is 3 or 1) + { + var re = targetTask.state == 1 ? "已领取" : "已完成"; + _logger.LogInformation("{re},跳过", re); return info; - - CommonTaskItem GetTarget(VipTaskInfo info) - { - return info.Task_info.Modules.First(x => x.module_title == "日常任务") - .common_task_item - .First(x => x.task_code == "vipmallbuy"); - } } - [TaskInterceptor("浏览装扮商城主页", TaskLevel.Two, false)] - private async Task ViewDressMall(VipTaskInfo info) + //0需要领取 + if (targetTask.state == 0) { - var code = "dress-view"; - - CommonTaskItem targetTask = GetTarget(info); - - //如果状态不等于3,则做 - if (targetTask.state == 3) - { - _logger.LogInformation("已完成,跳过"); - return info; - } + _logger.LogInformation("开始领取任务"); + await TryReceive(targetTask.task_code); + } - //0需要领取 - if (targetTask.state == 0) - { - _logger.LogInformation("开始领取任务"); - await TryReceive(targetTask.task_code); - } + return info; - _logger.LogInformation("开始完成任务"); - var re = await Complete(code); + CommonTaskItem GetTarget(VipTaskInfo info) + { + return info.Task_info.Modules.First(x => x.module_title == "日常任务") + .common_task_item + .First(x => x.task_code == "vipmallbuy"); + } + } - //确认 - if (re) - { - var infoResult = await _vipApi.GetTaskList(); - if (infoResult.Code != 0) throw new Exception(infoResult.ToJsonStr()); - info = infoResult.Data; - targetTask = GetTarget(info); + [TaskInterceptor("浏览装扮商城主页", TaskLevel.Two, false)] + private async Task ViewDressMall(VipTaskInfo info) + { + //var code = "dress-view"; - _logger.LogInformation("确认:{re}", targetTask.state == 3 && targetTask.complete_times >= 1); - } + CommonTaskItem targetTask = GetTarget(info); - CommonTaskItem GetTarget(VipTaskInfo info) - { - return info.Task_info.Modules.First(x => x.module_title == "日常任务") - .common_task_item - .First(x => x.task_code == "dress-view"); - } + //如果状态不等于3,则做 + if (targetTask.state == 3) + { + _logger.LogInformation("已完成,跳过"); return info; } - - /// - /// 领取任务 - /// - private async Task TryReceive(string taskCode) + //0需要领取 + if (targetTask.state == 0) { - BiliApiResponse re = null; - try - { - var request = new ReceiveOrCompleteTaskRequest(taskCode); - re = await _vipApi.Receive(request); - if (re.Code == 0) - _logger.LogInformation("领取任务成功"); - else - _logger.LogInformation("领取任务失败:{msg}", re.ToJsonStr()); - } - catch (Exception e) - { - _logger.LogError("领取任务异常"); - _logger.LogError(e.Message + re?.ToJsonStr()); - } + _logger.LogInformation("开始领取任务"); + await TryReceive(targetTask.task_code); } - private async Task Complete(string taskCode) + _logger.LogInformation("开始完成任务"); + var re = await CompleteV2(targetTask.task_code); + + //确认 + if (re) { - var request = new ReceiveOrCompleteTaskRequest(taskCode); - var re = await _vipApi.Complete(request); - if (re.Code == 0) - { - _logger.LogInformation("已完成"); - return true; - } + var infoResult = await _vipApi.GetTaskList(); + if (infoResult.Code != 0) throw new Exception(infoResult.ToJsonStr()); + info = infoResult.Data; + targetTask = GetTarget(info); - else - { - _logger.LogInformation("失败:{msg}", re.ToJsonStr()); - return false; - } + _logger.LogInformation("确认:{re}", targetTask.state == 3 && targetTask.complete_times >= 1); } - private async Task CompleteView(string code) + CommonTaskItem GetTarget(VipTaskInfo info) { - _logger.LogInformation("开始浏览"); - await Task.Delay(10 * 1000); + return info.Task_info.Modules.First(x => x.module_title == "日常任务") + .common_task_item + .First(x => x.task_code == "dress-view"); + } + + return info; + } - var request = new ViewRequest(code); - var re = await _vipApi.ViewComplete(request); - if (re.Code == 0) - { - _logger.LogInformation("浏览完成"); - return true; - } + /// + /// 领取任务 + /// + private async Task TryReceive(string taskCode) + { + BiliApiResponse re = null; + try + { + var request = new ReceiveOrCompleteTaskRequest(taskCode); + re = await _vipApi.Receive(request); + if (re.Code == 0) + _logger.LogInformation("领取任务成功"); else - { - _logger.LogInformation("浏览失败:{msg}", re.ToJsonStr()); - return false; - } + _logger.LogInformation("领取任务失败:{msg}", re.ToJsonStr()); } - - public async Task WatchBangumi() + catch (Exception e) { - if (_vipBigPointOptions.ViewBangumiList == null ||_vipBigPointOptions.ViewBangumiList.Count == 0) - return false; - - long randomSsid = _vipBigPointOptions.ViewBangumiList[new Random().Next(0,_vipBigPointOptions.ViewBangumiList.Count)]; - - var res = await GetBangumi(randomSsid); - if (res is null) - { - return false; - } + _logger.LogError("领取任务异常"); + _logger.LogError(e.Message + re?.ToJsonStr()); + } + } - var videoInfo = res.Value.Item1; - - // 随机播放时间 - int playedTime = new Random().Next(905, 1800); - // 观看该视频 - var request = new UploadVideoHeartbeatRequest() - { - Aid = long.Parse(videoInfo.Aid), - Bvid = videoInfo.Bvid, - Cid = videoInfo.Cid, - Mid = long.Parse(_biliCookie.UserId), - Sid = randomSsid, - Epid = res.Value.Item2, - Csrf = _biliCookie.BiliJct, - Type = 4, - Sub_type = 1, - Start_ts = DateTime.Now.ToTimeStamp() - playedTime, - Played_time = playedTime, - Realtime = playedTime, - Real_played_time = playedTime - }; - BiliApiResponse apiResponse = await _videoApi.UploadVideoHeartbeat(request); - if (apiResponse.Code == 0) - { - return true; - } + private async Task Complete(string taskCode) + { + var request = new ReceiveOrCompleteTaskRequest(taskCode); + var re = await _vipApi.Complete(request); + if (re.Code == 0) + { + _logger.LogInformation("已完成"); + return true; + } + else + { + _logger.LogInformation("失败:{msg}", re.ToJsonStr()); return false; } + } + - /// - /// 从自定义的番剧ssid中选择其中的一部中的一集 - /// - /// 番剧ssid - /// - private async Task<(VideoInfoDto,long)?> GetBangumi(long randomSsid) + private async Task CompleteV2(string taskCode) + { + var request = new ReceiveOrCompleteTaskRequest(taskCode); + var re = await _vipApi.CompleteV2(request); + if (re.Code == 0) { - try - { - if (randomSsid is 0 or long.MinValue) - return null; - var bangumiInfo = await _videoApi.GetBangumiBySsid(randomSsid); - - // 从获取的剧集中随机获得其中的一集 - - var bangumi = bangumiInfo.Result.episodes[new Random().Next(0, bangumiInfo.Result.episodes.Count)]; - var videoInfo = new VideoInfoDto() - { - Bvid = bangumi.bvid, - Aid = bangumi.aid.ToString(), - Cid = bangumi.cid, - Copyright = 1, - Duration = bangumi.duration, - Title = bangumi.share_copy - }; - _logger.LogInformation("本次播放的正片为:{title}",bangumi.share_copy); - return (videoInfo, bangumi.ep_id); - } - catch (Exception e) - { - _logger.LogError(e.Message); - } - return null; + _logger.LogInformation("已完成"); + return true; } - #region deprecated - [TaskInterceptor("浏览影视频道页10秒", TaskLevel.Two, false)] - private async Task ViewFilmChannel(VipTaskInfo info) - { - var code = "tv_channel"; - CommonTaskItem targetTask = GetTarget(info); - - //如果状态不等于3,则做 - if (targetTask.state == 3) - { - _logger.LogInformation("已完成,跳过"); - return info; - } + else + { + _logger.LogInformation("失败:{msg}", re.ToJsonStr()); + return false; + } + } - //0需要领取 - if (targetTask.state == 0) - { - _logger.LogInformation("开始领取任务"); - await TryReceive(targetTask.task_code); - } + private async Task CompleteView(string code) + { + _logger.LogInformation("开始浏览"); + await Task.Delay(10 * 1000); - _logger.LogInformation("开始完成任务"); - var re = await CompleteView(code); + var request = new ViewRequest(code); + var re = await _vipApi.ViewComplete(request); + if (re.Code == 0) + { + _logger.LogInformation("浏览完成"); + return true; + } - //确认 - if (re) - { - var infoResult = await _vipApi.GetTaskList(); - if (infoResult.Code != 0) throw new Exception(infoResult.ToJsonStr()); - info = infoResult.Data; - targetTask = GetTarget(info); + else + { + _logger.LogInformation("浏览失败:{msg}", re.ToJsonStr()); + return false; + } + } - _logger.LogInformation("确认:{re}", targetTask.state == 3 && targetTask.complete_times >= 1); - } + public async Task WatchBangumi() + { + if (_vipBigPointOptions.ViewBangumiList == null || _vipBigPointOptions.ViewBangumiList.Count == 0) + return false; - CommonTaskItem GetTarget(VipTaskInfo info) - { - return info.Task_info.Modules.First(x => x.module_title == "日常任务") - .common_task_item - .First(x => x.task_code == "filmtab"); - } + long randomSsid = + _vipBigPointOptions.ViewBangumiList[new Random().Next(0, _vipBigPointOptions.ViewBangumiList.Count)]; - return info; + var res = await GetBangumi(randomSsid); + if (res is null) + { + return false; } - [TaskInterceptor("购买指定大会员产品(仅领取)", TaskLevel.Two, false)] - private async Task BuyVipProduct(VipTaskInfo info) + var videoInfo = res.Value.Item1; + + // 随机播放时间 + int playedTime = new Random().Next(905, 1800); + // 观看该视频 + var request = new UploadVideoHeartbeatRequest() { - CommonTaskItem targetTask = GetTarget(info); + Aid = long.Parse(videoInfo.Aid), + Bvid = videoInfo.Bvid, + Cid = videoInfo.Cid, + Mid = long.Parse(_biliCookie.UserId), + Sid = randomSsid, + Epid = res.Value.Item2, + Csrf = _biliCookie.BiliJct, + Type = 4, + Sub_type = 1, + Start_ts = DateTime.Now.ToTimeStamp() - playedTime, + Played_time = playedTime, + Realtime = playedTime, + Real_played_time = playedTime + }; + BiliApiResponse apiResponse = await _videoApi.UploadVideoHeartbeat(request); + if (apiResponse.Code == 0) + { + return true; + } - if (targetTask.state is 3 or 1) - { - var re = targetTask.state == 1 ? "已领取" : "已完成"; - _logger.LogInformation("{re},跳过", re); - return info; - } + return false; + } - //0需要领取 - if (targetTask.state == 0) - { - _logger.LogInformation("开始领取任务"); - await TryReceive(targetTask.task_code); - } + /// + /// 从自定义的番剧ssid中选择其中的一部中的一集 + /// + /// 番剧ssid + /// + private async Task<(VideoInfoDto, long)?> GetBangumi(long randomSsid) + { + try + { + if (randomSsid is 0 or long.MinValue) + return null; + var bangumiInfo = await _videoApi.GetBangumiBySsid(randomSsid); - return info; + // 从获取的剧集中随机获得其中的一集 - CommonTaskItem GetTarget(VipTaskInfo info) + var bangumi = bangumiInfo.Result.episodes[new Random().Next(0, bangumiInfo.Result.episodes.Count)]; + var videoInfo = new VideoInfoDto() { - return info.Task_info.Modules.First(x => x.module_title == "日常任务") - .common_task_item - .First(x => x.task_code == "subscribe"); - } + Bvid = bangumi.bvid, + Aid = bangumi.aid.ToString(), + Cid = bangumi.cid, + Copyright = 1, + Duration = bangumi.duration, + Title = bangumi.share_copy + }; + _logger.LogInformation("本次播放的正片为:{title}", bangumi.share_copy); + return (videoInfo, bangumi.ep_id); + } + catch (Exception e) + { + _logger.LogError(e.Message); } - - #endregion - + return null; } } diff --git a/test/AppServiceTest/VipServiceTest.cs b/test/AppServiceTest/VipServiceTest.cs index 437ed4260..ca5da50ce 100644 --- a/test/AppServiceTest/VipServiceTest.cs +++ b/test/AppServiceTest/VipServiceTest.cs @@ -1,4 +1,6 @@ using Microsoft.Extensions.DependencyInjection; +using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos.VipTask; +using Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces; using Ray.BiliBiliTool.Application.Contracts; using Ray.BiliBiliTool.DomainService.Dtos; using Ray.BiliBiliTool.Infrastructure; @@ -27,6 +29,24 @@ public async Task WatchVideo() var appService = scope.ServiceProvider.GetRequiredService(); var res = await appService.WatchBangumi(); Assert.True(res); - + } + + + [Fact] + public async Task CompleteV2Test() + { + using var scope = Global.ServiceProviderRoot.CreateScope(); + var api = scope.ServiceProvider.GetRequiredService(); + var res = await api.CompleteV2(new ReceiveOrCompleteTaskRequest("dress-view")); + Assert.True(res.Code == 0); + } + + [Fact] + public async Task ReceiveV2Test() + { + using var scope = Global.ServiceProviderRoot.CreateScope(); + var api = scope.ServiceProvider.GetRequiredService(); + var res = await api.ReceiveV2(new ReceiveOrCompleteTaskRequest("ogvwatchnew")); + Assert.True(res.Code == 0); } }