Skip to content

Commit

Permalink
inter knot monthly reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Sep 25, 2024
1 parent a4ff538 commit 45e46d8
Show file tree
Hide file tree
Showing 22 changed files with 1,547 additions and 7 deletions.
61 changes: 61 additions & 0 deletions src/Starward.Core/GameRecord/GameRecordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.Security.Cryptography;
using System.Text;
using Starward.Core.GameRecord.Genshin.ImaginariumTheater;
using Starward.Core.GameRecord.ZZZ.InterKnotReport;


#if !DEBUG
using System.Net.Http.Json;
Expand Down Expand Up @@ -382,6 +384,65 @@ protected virtual async Task CommonSendAsync(HttpRequestMessage request, Cancell
#endregion




#region ZZZ



/// <summary>
/// 获取绝区零账号信息
/// </summary>
/// <param name="cookie"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public abstract Task<List<GameRecordRole>> GetZZZGameRolesAsync(string cookie, CancellationToken cancellationToken = default);




/// <summary>
/// 绳网月报总结
/// </summary>
/// <param name="role"></param>
/// <param name="month">202409</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public abstract Task<InterKnotReportSummary> GetInterKnotReportSummaryAsync(GameRecordRole role, string month = "", CancellationToken cancellationToken = default);


/// <summary>
/// 绳网月报收入详情
/// </summary>
/// <param name="role"></param>
/// <param name="month">202409</param>
/// <param name="type"></param>
/// <param name="page">从1开始</param>
/// <param name="page_size">最大100</param>
/// <param name="cancellationToken"></param>
/// <returns>返回一页收入记录</returns>
public abstract Task<InterKnotReportDetail> GetInterKnotReportDetailByPageAsync(GameRecordRole role, string month, string type, int page, int page_size = 100, CancellationToken cancellationToken = default);


/// <summary>
/// 绳网月报收入详情
/// </summary>
/// <param name="role"></param>
/// <param name="month">202409</param>
/// <param name="type"></param>
/// <param name="page_size">最大100</param>
/// <param name="cancellationToken"></param>
/// <returns>返回该月所有收入记录</returns>
public abstract Task<InterKnotReportDetail> GetInterKnotReportDetailAsync(GameRecordRole role, string month, string type, int page_size = 100, CancellationToken cancellationToken = default);




#endregion




// 寰宇蝗灾
// https://api-takumi-record.mihoyo.com/game_record/app/hkrpg/api/rogue_locust?server=prod_gf_cn&role_id={uid}&need_detail=true

Expand Down
3 changes: 3 additions & 0 deletions src/Starward.Core/GameRecord/GameRecordJsonContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Starward.Core.GameRecord.StarRail.PureFiction;
using Starward.Core.GameRecord.StarRail.SimulatedUniverse;
using Starward.Core.GameRecord.StarRail.TrailblazeCalendar;
using Starward.Core.GameRecord.ZZZ.InterKnotReport;
using System.Text.Json.Serialization;

namespace Starward.Core.GameRecord;
Expand All @@ -26,6 +27,8 @@ namespace Starward.Core.GameRecord;
[JsonSerializable(typeof(miHoYoApiWrapper<SimulatedUniverseTime>))]
[JsonSerializable(typeof(miHoYoApiWrapper<DeviceFpResult>))]
[JsonSerializable(typeof(miHoYoApiWrapper<ImaginariumTheaterWarpper>))]
[JsonSerializable(typeof(miHoYoApiWrapper<InterKnotReportSummary>))]
[JsonSerializable(typeof(miHoYoApiWrapper<InterKnotReportDetail>))]
internal partial class GameRecordJsonContext : JsonSerializerContext
{

Expand Down
107 changes: 106 additions & 1 deletion src/Starward.Core/GameRecord/HoyolabClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Starward.Core.GameRecord.StarRail.PureFiction;
using Starward.Core.GameRecord.StarRail.SimulatedUniverse;
using Starward.Core.GameRecord.StarRail.TrailblazeCalendar;
using Starward.Core.GameRecord.ZZZ.InterKnotReport;

namespace Starward.Core.GameRecord;

Expand All @@ -15,7 +16,7 @@ public class HoyolabClient : GameRecordClient

public override string UAContent => $"Mozilla/5.0 (Linux; Android 13; Pixel 5 Build/TQ3A.230901.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/118.0.0.0 Mobile Safari/537.36 miHoYoBBSOversea/{AppVersion}";

public override string AppVersion => "2.54.0";
public override string AppVersion => "2.59.0";

protected override string ApiSalt => "okr4obncj8bw5a65hbnn5oo6ixjc3l9w";

Expand Down Expand Up @@ -84,6 +85,7 @@ public override async Task<List<GameRecordRole>> GetAllGameRolesAsync(string coo
var list = new List<GameRecordRole>();
list.AddRange(await GetGenshinGameRolesAsync(cookie, cancellationToken));
list.AddRange(await GetStarRailGameRolesAsync(cookie, cancellationToken));
list.AddRange(await GetZZZGameRolesAsync(cookie, cancellationToken));
return list;
}

Expand Down Expand Up @@ -496,4 +498,107 @@ public override async Task<TrailblazeCalendarDetail> GetTrailblazeCalendarDetail
#endregion




#region ZZZ


/// <summary>
/// 获取绝区零账号信息
/// </summary>
/// <param name="cookie"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<List<GameRecordRole>> GetZZZGameRolesAsync(string cookie, CancellationToken cancellationToken = default)
{
if (string.IsNullOrWhiteSpace(cookie))
{
throw new ArgumentNullException(nameof(cookie));
}
var url = "https://api-account-os.hoyolab.com/binding/api/getUserGameRolesByCookieToken?game_biz=nap_global";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(Cookie, cookie);
request.Headers.Add(X_Request_With, com_mihoyo_hoyolab);
request.Headers.Add(Referer, "https://act.hoyolab.com");
var data = await CommonSendAsync<GameRecordRoleWrapper>(request, cancellationToken);
data.List?.ForEach(x => x.Cookie = cookie);
return data.List ?? new List<GameRecordRole>();
}



/// <summary>
/// 绳网月报总结
/// </summary>
/// <param name="role"></param>
/// <param name="month">202409</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<InterKnotReportSummary> GetInterKnotReportSummaryAsync(GameRecordRole role, string month = "", CancellationToken cancellationToken = default)
{
var url = $"https://sg-public-api.hoyolab.com/event/nap_ledger/month_info?uid={role.Uid}&region={role.Region}&month={month}";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(Cookie, role.Cookie);
request.Headers.Add(Referer, "https://act.hoyolab.com/");
request.Headers.Add(X_Request_With, com_mihoyo_hoyolab);
return await CommonSendAsync<InterKnotReportSummary>(request, cancellationToken);
}

/// <summary>
/// 绳网月报收入详情
/// </summary>
/// <param name="role"></param>
/// <param name="month">202409</param>
/// <param name="type"></param>
/// <param name="page">从1开始</param>
/// <param name="page_size">最大100</param>
/// <param name="cancellationToken"></param>
/// <returns>返回一页收入记录</returns>
public override async Task<InterKnotReportDetail> GetInterKnotReportDetailByPageAsync(GameRecordRole role, string month, string type, int page, int page_size = 100, CancellationToken cancellationToken = default)
{
var url = $"https://sg-public-api.hoyolab.com/event/nap_ledger/month_detail?uid={role.Uid}&region={role.Region}&month={month}&type={type}&current_page={page}&page_size={page_size}";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(Cookie, role.Cookie);
request.Headers.Add(Referer, "https://act.hoyolab.com/");
request.Headers.Add(X_Request_With, com_mihoyo_hoyolab);
return await CommonSendAsync<InterKnotReportDetail>(request, cancellationToken);
}


/// <summary>
/// 绳网月报收入详情
/// </summary>
/// <param name="role"></param>
/// <param name="month">202409</param>
/// <param name="type"></param>
/// <param name="page_size">最大100</param>
/// <param name="cancellationToken"></param>
/// <returns>返回该月所有收入记录</returns>
public override async Task<InterKnotReportDetail> GetInterKnotReportDetailAsync(GameRecordRole role, string month, string type, int page_size = 100, CancellationToken cancellationToken = default)
{
page_size = Math.Clamp(page_size, 20, 100);
var data = await GetInterKnotReportDetailByPageAsync(role, month, type, 1, page_size, cancellationToken);
if (data.List.Count < page_size)
{
return data;
}
for (int i = 2; ; i++)
{
var addData = await GetInterKnotReportDetailByPageAsync(role, month, type, i, page_size, cancellationToken);
data.List.AddRange(addData.List);
if (addData.List.Count < page_size)
{
break;
}
}
return data;
}



#endregion




}
112 changes: 111 additions & 1 deletion src/Starward.Core/GameRecord/HyperionClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Starward.Core.GameRecord.StarRail.PureFiction;
using Starward.Core.GameRecord.StarRail.SimulatedUniverse;
using Starward.Core.GameRecord.StarRail.TrailblazeCalendar;
using Starward.Core.GameRecord.ZZZ.InterKnotReport;

namespace Starward.Core.GameRecord;

Expand All @@ -16,7 +17,7 @@ public class HyperionClient : GameRecordClient

public override string UAContent => $"Mozilla/5.0 (Linux; Android 13; Pixel 5 Build/TQ3A.230901.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/118.0.0.0 Mobile Safari/537.36 miHoYoBBS/{AppVersion}";

public override string AppVersion => "2.71.1";
public override string AppVersion => "2.75.2";

protected override string ApiSalt => "t0qEgfub6cvueAPgR5m9aQWWVciEer7v";

Expand Down Expand Up @@ -81,6 +82,7 @@ public override async Task<List<GameRecordRole>> GetAllGameRolesAsync(string coo
var list = new List<GameRecordRole>();
list.AddRange(await GetGenshinGameRolesAsync(cookie, cancellationToken));
list.AddRange(await GetStarRailGameRolesAsync(cookie, cancellationToken));
list.AddRange(await GetZZZGameRolesAsync(cookie, cancellationToken));
return list;
}

Expand Down Expand Up @@ -556,4 +558,112 @@ public override async Task<TrailblazeCalendarDetail> GetTrailblazeCalendarDetail



#region ZZZ



/// <summary>
/// 获取绝区零账号信息
/// </summary>
/// <param name="cookie"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<List<GameRecordRole>> GetZZZGameRolesAsync(string cookie, CancellationToken cancellationToken = default)
{
if (string.IsNullOrWhiteSpace(cookie))
{
throw new ArgumentNullException(nameof(cookie));
}
var url = "https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=nap_cn";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(Cookie, cookie);
request.Headers.Add(DS, CreateSecret2(url));
request.Headers.Add(X_Request_With, com_mihoyo_hyperion);
request.Headers.Add(x_rpc_app_version, AppVersion);
request.Headers.Add(x_rpc_client_type, "5");
request.Headers.Add(Referer, "https://webstatic.mihoyo.com/");
var data = await CommonSendAsync<GameRecordRoleWrapper>(request, cancellationToken);
data.List?.ForEach(x => x.Cookie = cookie);
return data.List ?? new List<GameRecordRole>();
}



/// <summary>
/// 绳网月报总结
/// </summary>
/// <param name="role"></param>
/// <param name="month">202409</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<InterKnotReportSummary> GetInterKnotReportSummaryAsync(GameRecordRole role, string month = "", CancellationToken cancellationToken = default)
{
var url = $"https://api-takumi.mihoyo.com/event/nap_ledger/month_info?uid={role.Uid}&region={role.Region}&month={month}";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(Cookie, role.Cookie);
request.Headers.Add(Referer, "https://act.mihoyo.com/");
request.Headers.Add(x_rpc_app_version, AppVersion);
request.Headers.Add(x_rpc_device_id, DeviceId);
request.Headers.Add(x_rpc_device_fp, DeviceFp);
return await CommonSendAsync<InterKnotReportSummary>(request, cancellationToken);
}

/// <summary>
/// 绳网月报收入详情
/// </summary>
/// <param name="role"></param>
/// <param name="month">202409</param>
/// <param name="type"></param>
/// <param name="page">从1开始</param>
/// <param name="page_size">最大100</param>
/// <param name="cancellationToken"></param>
/// <returns>返回一页收入记录</returns>
public override async Task<InterKnotReportDetail> GetInterKnotReportDetailByPageAsync(GameRecordRole role, string month, string type, int page, int page_size = 100, CancellationToken cancellationToken = default)
{
var url = $"https://api-takumi.mihoyo.com/event/nap_ledger/month_detail?uid={role.Uid}&region={role.Region}&month={month}&type={type}&current_page={page}&page_size={page_size}";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(Cookie, role.Cookie);
request.Headers.Add(Referer, "https://act.mihoyo.com/");
request.Headers.Add(x_rpc_app_version, AppVersion);
request.Headers.Add(x_rpc_device_id, DeviceId);
request.Headers.Add(x_rpc_device_fp, DeviceFp);
return await CommonSendAsync<InterKnotReportDetail>(request, cancellationToken);
}


/// <summary>
/// 绳网月报收入详情
/// </summary>
/// <param name="role"></param>
/// <param name="month">202409</param>
/// <param name="type"></param>
/// <param name="page_size">最大100</param>
/// <param name="cancellationToken"></param>
/// <returns>返回该月所有收入记录</returns>
public override async Task<InterKnotReportDetail> GetInterKnotReportDetailAsync(GameRecordRole role, string month, string type, int page_size = 100, CancellationToken cancellationToken = default)
{
page_size = Math.Clamp(page_size, 20, 100);
var data = await GetInterKnotReportDetailByPageAsync(role, month, type, 1, page_size, cancellationToken);
if (data.List.Count < page_size)
{
return data;
}
for (int i = 2; ; i++)
{
var addData = await GetInterKnotReportDetailByPageAsync(role, month, type, i, page_size, cancellationToken);
data.List.AddRange(addData.List);
if (addData.List.Count < page_size)
{
break;
}
}
return data;
}




#endregion


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Starward.Core.GameRecord.ZZZ.InterKnotReport;

public abstract class InterKnotReportDataType
{

/// <summary>
/// 菲林
/// </summary>
public const string PolychromesData = nameof(PolychromesData);

/// <summary>
/// 加密母带 & 原装母带
/// </summary>
public const string MatserTapeData = nameof(MatserTapeData);

/// <summary>
/// 邦布券
/// </summary>
public const string BooponsData = nameof(BooponsData);



public static string ToLocalization(string type)
{
return type switch
{
_ => type,
};
}



}
Loading

0 comments on commit 45e46d8

Please sign in to comment.