Skip to content

Commit

Permalink
修复由于wbi鉴权导致的LiveFansMedal错误 (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
Polaris-cn10086 authored Jun 1, 2023
1 parent 01e9983 commit 3bd6931
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos;

public class GetSpaceInfoDto
{
public long mid { get; set; }
}
public class GetSpaceInfoFullDto : GetSpaceInfoDto
{
public string w_rid { get; set; }

public long wts { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface IUserInfoApi : IBiliBiliApi
/// </summary>
/// <param name="userId">uid</param>
/// <returns></returns>
[HttpGet("/x/space/wbi/acc/info?mid={userId}")]
Task<BiliApiResponse<GetSpaceInfoResponse>> GetSpaceInfo(long userId);
[HttpGet("/x/space/wbi/acc/info")]
Task<BiliApiResponse<GetSpaceInfoResponse>> GetSpaceInfo([PathQuery] GetSpaceInfoFullDto request);
}
}
34 changes: 31 additions & 3 deletions src/Ray.BiliBiliTool.DomainService/LiveDomainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class LiveDomainService : ILiveDomainService
private readonly DailyTaskOptions _dailyTaskOptions;
private readonly SecurityOptions _securityOptions;
private readonly BiliCookie _biliCookie;

private readonly IWbiDomainService _wbiDomainService;

public LiveDomainService(ILogger<LiveDomainService> logger,
ILiveApi liveApi,
Expand All @@ -44,6 +44,7 @@ public LiveDomainService(ILogger<LiveDomainService> logger,
IOptionsMonitor<LiveLotteryTaskOptions> liveLotteryTaskOptions,
IOptionsMonitor<LiveFansMedalTaskOptions> liveFansMedalTaskOptions,
IOptionsMonitor<SecurityOptions> securityOptions,
IWbiDomainService wbiDomainService,
BiliCookie biliCookie)
{
_logger = logger;
Expand All @@ -55,6 +56,7 @@ public LiveDomainService(ILogger<LiveDomainService> logger,
_dailyTaskOptions = dailyTaskOptions.CurrentValue;
_liveFansMedalTaskOptions = liveFansMedalTaskOptions.CurrentValue;
_securityOptions = securityOptions.CurrentValue;
_wbiDomainService = wbiDomainService;
_biliCookie = biliCookie;

}
Expand Down Expand Up @@ -407,7 +409,20 @@ public async Task SendDanmakuToFansMedalLive()

// 通过空间主页信息获取直播间 id
var liveHostUserId = medal.Medal_info.Target_id;
var spaceInfo = await _userInfoApi.GetSpaceInfo(liveHostUserId);
var req = new GetSpaceInfoDto()
{
mid = liveHostUserId
};


var w_ridDto = await _wbiDomainService.GetWridAsync(req);
var fullDto = new GetSpaceInfoFullDto()
{
mid = liveHostUserId,
w_rid = w_ridDto.w_rid,
wts = w_ridDto.wts
};
var spaceInfo = await _userInfoApi.GetSpaceInfo(fullDto);
if (spaceInfo.Code != 0)
{
_logger.LogError("【获取直播间信息】失败");
Expand Down Expand Up @@ -578,7 +593,20 @@ private async Task<List<FansMedalInfoDto>> GetFansMedalInfoList()

// 通过空间主页信息获取直播间 id
var liveHostUserId = medal.Medal_info.Target_id;
var spaceInfo = await _userInfoApi.GetSpaceInfo(liveHostUserId);
var req = new GetSpaceInfoDto()
{
mid = liveHostUserId
};


var w_ridDto = await _wbiDomainService.GetWridAsync(req);
var fullDto = new GetSpaceInfoFullDto()
{
mid = liveHostUserId,
w_rid = w_ridDto.w_rid,
wts = w_ridDto.wts
};
var spaceInfo = await _userInfoApi.GetSpaceInfo(fullDto);
if (spaceInfo.Code != 0)
{
_logger.LogError("【获取空间信息】失败");
Expand Down
23 changes: 21 additions & 2 deletions test/BiliAgentTest/LiveApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading.Tasks;
using Ray.BiliBiliTool.Infrastructure.Cookie;
using Xunit;
using Ray.BiliBiliTool.DomainService.Interfaces;

namespace BiliAgentTest
{
Expand Down Expand Up @@ -123,15 +124,33 @@ public void WearMedalWall_Normal_Success()
}

[Fact]
public void GetSpaceInfo_Normal_Success()
public async Task GetSpaceInfo_Normal_Success()
{
using var scope = Global.ServiceProviderRoot.CreateScope();

var ck = scope.ServiceProvider.GetRequiredService<CookieStrFactory>();
var api = scope.ServiceProvider.GetRequiredService<IUserInfoApi>();
var biliCookie = scope.ServiceProvider.GetRequiredService<BiliCookie>();

BiliApiResponse<GetSpaceInfoResponse> re = api.GetSpaceInfo(919174).Result;
var domainService = scope.ServiceProvider.GetRequiredService<IWbiDomainService>();

var req = new GetSpaceInfoDto()
{
mid = 919174L
};

var w_ridDto = await domainService.GetWridAsync(req);

var fullDto = new GetSpaceInfoFullDto()
{
mid = 919174L,
w_rid = w_ridDto.w_rid,
wts = w_ridDto.wts
};



BiliApiResponse<GetSpaceInfoResponse> re = api.GetSpaceInfo(fullDto).Result;

Assert.True(re.Code == 0);
Assert.NotNull(re.Data);
Expand Down

0 comments on commit 3bd6931

Please sign in to comment.