mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-15 09:48:14 +08:00
♻️ 完善 ds 算法
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
* @file web request getAbyss.ts
|
* @file web request getAbyss.ts
|
||||||
* @description 获取深渊信息
|
* @description 获取深渊信息
|
||||||
* @author BTMuli<bt-muli@outlook.com>
|
* @author BTMuli<bt-muli@outlook.com>
|
||||||
* @since Alpha v0.2.0
|
* @since Beta v0.3.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// tauri
|
// tauri
|
||||||
@@ -10,11 +10,11 @@ import { http } from "@tauri-apps/api";
|
|||||||
// api
|
// api
|
||||||
import TGApi from "../api/TGApi";
|
import TGApi from "../api/TGApi";
|
||||||
// utils
|
// utils
|
||||||
import { getRequestHeader } from "../utils/getRequestHeader";
|
import TGUtils from "../utils/TGUtils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 获取深渊信息
|
* @description 获取深渊信息
|
||||||
* @since Alpha v0.2.0
|
* @since Beta v0.3.0
|
||||||
* @param {Record<string, string>} cookie cookie
|
* @param {Record<string, string>} cookie cookie
|
||||||
* @param {string} schedule_type 1: 本期, 2: 上期
|
* @param {string} schedule_type 1: 本期, 2: 上期
|
||||||
* @param {TGApp.Sqlite.Account.Game} account 游戏账号
|
* @param {TGApp.Sqlite.Account.Game} account 游戏账号
|
||||||
@@ -28,7 +28,7 @@ export async function getAbyss(
|
|||||||
const url = TGApi.GameData.getAbyss;
|
const url = TGApi.GameData.getAbyss;
|
||||||
const role_id = account.gameUid;
|
const role_id = account.gameUid;
|
||||||
const params = { role_id, schedule_type, server: account.region };
|
const params = { role_id, schedule_type, server: account.region };
|
||||||
const header = getRequestHeader(cookie, "GET", params, "common");
|
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
|
||||||
return await http
|
return await http
|
||||||
.fetch<TGApp.Game.Abyss.Response>(url, {
|
.fetch<TGApp.Game.Abyss.Response>(url, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
* @file web utils TGUtils.ts
|
* @file web utils TGUtils.ts
|
||||||
* @description 应用用到的工具函数
|
* @description 应用用到的工具函数
|
||||||
* @author BTMuli <bt-muli@outlook.com>
|
* @author BTMuli <bt-muli@outlook.com>
|
||||||
* @since Alpha v0.2.1
|
* @since Beta v0.3.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getAnnoCard } from "./getAnnoCard";
|
import { getAnnoCard } from "./getAnnoCard";
|
||||||
import { getRequestHeader, getRequestSignHeader } from "./getRequestHeader";
|
import { getRequestHeader } from "./getRequestHeader";
|
||||||
import { parseAnnoContent } from "./parseAnno";
|
import { parseAnnoContent } from "./parseAnno";
|
||||||
import { getServerByUid, transCookie } from "./tools";
|
import { getServerByUid, transCookie } from "./tools";
|
||||||
|
|
||||||
@@ -17,7 +17,6 @@ const TGUtils = {
|
|||||||
},
|
},
|
||||||
User: {
|
User: {
|
||||||
getHeader: getRequestHeader,
|
getHeader: getRequestHeader,
|
||||||
getSignHeader: getRequestSignHeader,
|
|
||||||
},
|
},
|
||||||
Tools: {
|
Tools: {
|
||||||
getServerByUid,
|
getServerByUid,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* @file web utils getRequestHeader.ts
|
* @file web utils getRequestHeader.ts
|
||||||
* @description 获取请求头
|
* @description 获取请求头
|
||||||
* @author BTMuli<bt-muli@outlook.com>
|
* @author BTMuli <bt-muli@outlook.com>
|
||||||
* @since Alpha v0.2.0
|
* @since Beta v0.3.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Node
|
// Node
|
||||||
@@ -13,8 +13,8 @@ import { transCookie, transParams } from "./tools";
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 获取 salt
|
* @description 获取 salt
|
||||||
* @since Alpha v0.2.0
|
* @since Beta v0.3.0
|
||||||
* @version 2.49.1
|
* @version 2.50.1
|
||||||
* @param {string} saltType salt 类型
|
* @param {string} saltType salt 类型
|
||||||
* @returns {string} salt
|
* @returns {string} salt
|
||||||
*/
|
*/
|
||||||
@@ -24,6 +24,8 @@ function getSalt(saltType: string): string {
|
|||||||
return TGConstant.Salt.Other.X4;
|
return TGConstant.Salt.Other.X4;
|
||||||
case "prod":
|
case "prod":
|
||||||
return TGConstant.Salt.Other.prod;
|
return TGConstant.Salt.Other.prod;
|
||||||
|
case "lk2":
|
||||||
|
return TGConstant.Salt.BBS.LK2;
|
||||||
default:
|
default:
|
||||||
return TGConstant.Salt.Other.X4;
|
return TGConstant.Salt.Other.X4;
|
||||||
}
|
}
|
||||||
@@ -57,33 +59,35 @@ export function getRandomString(length: number): string {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 获取 ds
|
* @description 获取 ds
|
||||||
* @since Alpha v0.2.0
|
* @since Beta v0.3.0
|
||||||
* @version 2.49.1
|
* @version 2.50.1
|
||||||
* @param {string} method 请求方法
|
* @param {string} method 请求方法
|
||||||
* @param {string} data 请求数据
|
* @param {string} data 请求数据
|
||||||
* @param {string} saltType salt 类型
|
* @param {string} saltType salt 类型
|
||||||
* @param {boolean} isSign 是否为签名
|
* @param {boolean} isSign 是否为签名
|
||||||
* @returns {string} ds
|
* @returns {string} ds
|
||||||
*/
|
*/
|
||||||
function getDS(method: string, data: string, saltType: string, isSign: boolean = false): string {
|
function getDS(method: string, data: string, saltType: string, isSign: boolean): string {
|
||||||
const salt = getSalt(saltType);
|
const salt = getSalt(saltType);
|
||||||
const time = Math.floor(Date.now() / 1000).toString();
|
const time = Math.floor(Date.now() / 1000).toString();
|
||||||
let random = getRandomNumber(100000, 200000).toString();
|
let random = getRandomNumber(100000, 200000).toString();
|
||||||
if (isSign) random = getRandomString(6);
|
if (isSign) random = getRandomString(6);
|
||||||
const body = method === "GET" ? "" : data;
|
const body = method === "GET" ? "" : data;
|
||||||
const query = method === "GET" ? data : "";
|
const query = method === "GET" ? data : "";
|
||||||
const hashStr = `salt=${salt}&t=${time}&r=${random}&b=${body}&q=${query}`;
|
let hashStr = `salt=${salt}&t=${time}&r=${random}&b=${body}&q=${query}`;
|
||||||
|
if (isSign) hashStr = `salt=${salt}&t=${time}&r=${random}`;
|
||||||
const md5Str = md5.update(hashStr).hex();
|
const md5Str = md5.update(hashStr).hex();
|
||||||
return `${time},${random},${md5Str}`;
|
return `${time},${random},${md5Str}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 获取请求头
|
* @description 获取请求头
|
||||||
* @since Alpha v0.2.0
|
* @since Beta v0.3.0
|
||||||
* @param {Record<string, string>} cookie cookie
|
* @param {Record<string, string>} cookie cookie
|
||||||
* @param {string} method 请求方法
|
* @param {string} method 请求方法
|
||||||
* @param {Record<string, string|number>|string} data 请求数据
|
* @param {Record<string, string|number>|string} data 请求数据
|
||||||
* @param {string} saltType salt 类型
|
* @param {string} saltType salt 类型
|
||||||
|
* @param {boolean} isSign 是否为签名
|
||||||
* @returns {Record<string, string>} 请求头
|
* @returns {Record<string, string>} 请求头
|
||||||
*/
|
*/
|
||||||
export function getRequestHeader(
|
export function getRequestHeader(
|
||||||
@@ -91,12 +95,13 @@ export function getRequestHeader(
|
|||||||
method: string,
|
method: string,
|
||||||
data: Record<string, string | number> | string,
|
data: Record<string, string | number> | string,
|
||||||
saltType: string,
|
saltType: string,
|
||||||
|
isSign: boolean = false,
|
||||||
): Record<string, string> {
|
): Record<string, string> {
|
||||||
let ds;
|
let ds;
|
||||||
if (typeof data === "string") {
|
if (typeof data === "string") {
|
||||||
ds = getDS(method, data, saltType);
|
ds = getDS(method, data, saltType, isSign);
|
||||||
} else {
|
} else {
|
||||||
ds = getDS(method, transParams(data), saltType);
|
ds = getDS(method, transParams(data), saltType, isSign);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
"User-Agent": TGConstant.BBS.USER_AGENT,
|
"User-Agent": TGConstant.BBS.USER_AGENT,
|
||||||
@@ -108,29 +113,3 @@ export function getRequestHeader(
|
|||||||
Cookie: transCookie(cookie),
|
Cookie: transCookie(cookie),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description 获取签名请求头
|
|
||||||
* @since Alpha v0.2.0
|
|
||||||
* @param {Record<string, string>} cookie cookie
|
|
||||||
* @param {string} method 请求方法
|
|
||||||
* @param {Record<string, string|number>} data 请求数据
|
|
||||||
* @param {string} saltType salt 类型
|
|
||||||
* @returns {Record<string, string>} 请求头
|
|
||||||
*/
|
|
||||||
export function getRequestSignHeader(
|
|
||||||
cookie: Record<string, string>,
|
|
||||||
method: string,
|
|
||||||
data: Record<string, string | number>,
|
|
||||||
saltType: string,
|
|
||||||
): Record<string, string> {
|
|
||||||
return {
|
|
||||||
"User-Agent": TGConstant.BBS.USER_AGENT,
|
|
||||||
"x-rpc-app_version": TGConstant.BBS.VERSION,
|
|
||||||
"x-rpc-client_type": "5",
|
|
||||||
"x-requested-with": "com.mihoyo.hyperion",
|
|
||||||
Referer: "https://webstatic.mihoyo.com",
|
|
||||||
DS: getDS(method, transParams(data), saltType, true),
|
|
||||||
Cookie: transCookie(cookie),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user