mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28:14 +08:00
🌱 幻想真境剧诗数据获取
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file web/api/TGApi.ts
|
||||
* @description 应用用到的 API
|
||||
* @since Beta v0.5.3
|
||||
* @since Beta v0.6.2
|
||||
*/
|
||||
|
||||
import { BBSUserInfoApi } from "./BBS.js";
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
TakumiCalculateSyncAvatarDetailApi,
|
||||
TakumiRecordCharacterListApi,
|
||||
TakumiRecordCharacterDetailApi,
|
||||
TakumiRecordCombatApi,
|
||||
} from "./Takumi.js";
|
||||
|
||||
// 应用 API
|
||||
@@ -50,6 +51,7 @@ const TGApi = {
|
||||
getUserBase: TakumiRecordIndexApi, // 获取用户基本信息
|
||||
getDailyNotes: TakumiRecordDailyNotesApi, // 获取实时便笺
|
||||
getAbyss: TakumiRecordAbyssApi, // 获取深境螺旋信息
|
||||
getRoleCombat: TakumiRecordCombatApi, // 获取幻想真境剧诗
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file web/api/Takumi.ts
|
||||
* @description 定义 Takumi API
|
||||
* @since Beta v0.5.3
|
||||
* @since Beta v0.6.2
|
||||
*/
|
||||
|
||||
const TakumiApi = "https://api-takumi.mihoyo.com/"; // 基础 API
|
||||
@@ -12,13 +12,14 @@ const TakumiRecordApi = "https://api-takumi-record.mihoyo.com/"; // 游戏记录
|
||||
const TakumiRecordGenshinApi = `${TakumiRecordApi}game_record/app/genshin/api/`; // 原神游戏记录 API
|
||||
|
||||
export const TakumiTokensApi = `${TakumiAuthApi}getMultiTokenByLoginTicket`; // 登录票据 API
|
||||
export const TakumiRecordDailyNotesApi = `${TakumiRecordApi}game_record/app/genshin/api/dailyNote`; // 游戏记录便笺 API
|
||||
export const TakumiRecordDailyNotesApi = `${TakumiRecordGenshinApi}dailyNote`; // 游戏记录便笺 API
|
||||
export const TakumiRecordCardApi = `${TakumiRecordApi}game_record/app/card/wapi/getGameRecordCard`; // 游戏记录卡片 API
|
||||
export const TakumiRecordIndexApi = `${TakumiRecordGenshinApi}index`; // 原神游戏记录索引 API
|
||||
export const TakumiRecordCharactersApi = `${TakumiRecordGenshinApi}character`; // 原神游戏记录角色 API
|
||||
export const TakumiRecordCharacterListApi = `${TakumiRecordCharactersApi}/list`; // 原神游戏记录角色列表 API
|
||||
export const TakumiRecordCharacterDetailApi = `${TakumiRecordCharactersApi}/detail`; // 原神游戏记录角色详情 API
|
||||
export const TakumiRecordAbyssApi = `${TakumiRecordGenshinApi}spiralAbyss`; // 原神游戏记录深境螺旋 API
|
||||
export const TakumiRecordCombatApi = `${TakumiRecordGenshinApi}role_combat`;
|
||||
export const TakumiSTokenBindingRolesApi = `${TakumiBindingApi}getUserGameRolesBySToken`; // 获取绑定角色 API-根据 stoken
|
||||
export const TakumiCookieBindingRolesApi = `${TakumiBindingApi}getUserGameRolesByCookie`; // 获取绑定角色 API-根据 Cookie
|
||||
|
||||
|
||||
39
src/web/request/getRoleCombat.ts
Normal file
39
src/web/request/getRoleCombat.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @file web/request/getRoleCombat.ts
|
||||
* @description 真境剧诗
|
||||
* @since Beta v0.6.2
|
||||
*/
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGApi from "../api/TGApi.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
|
||||
/**
|
||||
* @description 获取剧诗信息
|
||||
* @since Beta v.0.6.2
|
||||
* @param {TGApp.App.Account.Cookie} cookie
|
||||
* @param {TGApp.Sqlite.Account.Game} account
|
||||
* @returns {Promise<TGApp.Game.Combat.Combat[]|TGApp.BBS.Response.Base|false>}
|
||||
*/
|
||||
export async function getRoleCombat(
|
||||
cookie: TGApp.App.Account.Cookie,
|
||||
account: TGApp.Sqlite.Account.Game,
|
||||
): Promise<TGApp.Game.Combat.Combat[] | TGApp.BBS.Response.Base | false> {
|
||||
const url = TGApi.GameData.getRoleCombat;
|
||||
const params = { role_id: account.gameUid, server: account.region, active: 1, need_detail: true };
|
||||
const ck = {
|
||||
account_id: cookie.account_id,
|
||||
cookie_token: cookie.cookie_token,
|
||||
ltoken: cookie.ltoken,
|
||||
ltuid: cookie.ltuid,
|
||||
};
|
||||
const header = TGUtils.User.getHeader(ck, "GET", params, "common");
|
||||
const resp = await TGHttp<TGApp.Game.Combat.Response | TGApp.BBS.Response.Base>(url, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: params,
|
||||
});
|
||||
if (resp.retcode != 0) return <TGApp.BBS.Response.Base>resp;
|
||||
if (!resp.data.is_unlock) return false;
|
||||
return resp.data.data;
|
||||
}
|
||||
@@ -67,10 +67,10 @@ function getDS(method: string, data: string, saltType: string, isSign: boolean):
|
||||
|
||||
/**
|
||||
* @description 获取请求头
|
||||
* @since Beta v0.5.3
|
||||
* @since Beta v0.6.2
|
||||
* @param {Record<string, string>} cookie cookie
|
||||
* @param {string} method 请求方法
|
||||
* @param {Record<string, string|number>|string} data 请求数据
|
||||
* @param {Record<string, string|number|string[]|boolean>|string} data 请求数据
|
||||
* @param {string} saltType salt 类型
|
||||
* @param {boolean} isSign 是否为签名
|
||||
* @returns {Record<string, string>} 请求头
|
||||
@@ -78,7 +78,7 @@ function getDS(method: string, data: string, saltType: string, isSign: boolean):
|
||||
export function getRequestHeader(
|
||||
cookie: Record<string, string>,
|
||||
method: string,
|
||||
data: Record<string, string | number | string[]> | string,
|
||||
data: Record<string, string | number | string[] | boolean> | string,
|
||||
saltType: string,
|
||||
isSign: boolean = false,
|
||||
): Record<string, string> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file web/utils/tools.ts
|
||||
* @description 应用用到的工具函数
|
||||
* @since Beta v0.5.3
|
||||
* @since Beta v0.6.2
|
||||
*/
|
||||
|
||||
import TGConstant from "../constant/TGConstant.js";
|
||||
@@ -42,11 +42,11 @@ export function transCookie(cookie: Record<string, string>): string {
|
||||
|
||||
/**
|
||||
* @description ds 算法需要数据转换后的字符串是按照字典序排序的
|
||||
* @since Beta v0.5.3
|
||||
* @since Beta v0.6.2
|
||||
* @param {Record<string, string|number>} obj object
|
||||
* @returns {string} query string
|
||||
*/
|
||||
export function transParams(obj: Record<string, string | number | string[]>): string {
|
||||
export function transParams(obj: Record<string, string | number | string[] | boolean>): string {
|
||||
let res = "";
|
||||
const keys = Object.keys(obj).sort();
|
||||
for (const key of keys) {
|
||||
@@ -58,6 +58,8 @@ export function transParams(obj: Record<string, string | number | string[]>): st
|
||||
/**
|
||||
* @description 根据 uid 获取 server
|
||||
* @since Beta v0.4.3
|
||||
* @todo instead of account.region
|
||||
* @deprecated
|
||||
* @param {string} uid uid
|
||||
* @returns {string} server
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user