♻️ 把已经测试过的请求给加上去了

This commit is contained in:
BTMuli
2023-05-19 14:48:43 +08:00
parent 43505b7d2f
commit 97ff6e1350
13 changed files with 468 additions and 261 deletions

130
src/types/UserResponse.d.ts vendored Normal file
View File

@@ -0,0 +1,130 @@
/**
* @file types UserResponse.d.ts
* @description 用户请求返回相关类型定义文件
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
declare namespace BTMuli.User.Response {
/**
* @description token 列表项
* @since Alpha v0.2.0
* @see Tokens
* @interface TokenItem
* @property {string} name token 名称
* @property {string} token token 值
* @returns {TokenItem}
*/
export interface TokenItem {
name: string
token: string
}
/**
* @description 获取 ltoken 跟 stoken 的响应
* @since Alpha v0.2.0
* @see TGRequest.User.byLoginTicket.getTokens
* @interface Tokens
* @extends {BTMuli.Genshin.Base.Response}
* @property {TokenItem[]} data.list token 列表
* @returns {Tokens}
*/
export interface Tokens extends BTMuli.Genshin.Base.Response {
data: {
list: TokenItem[]
}
}
/**
* @description 根据 stoken 获取 ltoken
* @since Alpha v0.2.0
* @see TGRequest.User.byLoginTicket.getLToken
* @interface LToken extends BTMuli.Genshin.Base.Response
* @property {string} data.ltoken
* @returns {LToken}
*/
export interface LToken extends BTMuli.Genshin.Base.Response {
data: {
ltoken: string
}
}
/**
* @description 根据 stoken 获取 cookie_token
* @since Alpha v0.2.0
* @see TGRequest.User.bySToken.getCookieToken
* @interface CookieToken extends BTMuli.Genshin.Base.Response
* @property {string} data.uid 用户 uid
* @property {string} data.cookie_token cookie_token
* @returns {CookieToken}
*/
export interface CookieToken extends BTMuli.Genshin.Base.Response {
data: {
uid: string
cookie_token: string
}
}
/**
* @description 验证 stoken 的用户信息
* @since Alpha v0.2.0
* @see TGRequest.User.bySToken.verify
* @interface VerifyUserInfo
* @property {string} aid 账号 id
* @property {string} mid mid
* @property {string} account_name 账号名称
* @property {string} email 邮箱
* @property {number} is_email_verify 是否验证邮箱 // 0 未验证 1 已验证
* @property {string} area_code 手机区号 // '+86'
* @property {string} safe_mobile 手机号 // 部分明文,中间隐藏
* @property {string} realname 真实姓名 // 最后一位明文,其他隐藏
* @property {string} identity_code 身份证号 // 头尾三位明文,其他隐藏
* @property {string} rebind_area_code 重新绑定手机区号
* @property {string} rebind_mobile 重新绑定手机号
* @property {string} rebind_mobile_time 重新绑定手机时间
* @property {unknown[]} links 账号绑定信息
* @returns {VerifyUserInfo}
*/
export interface VerifyUserInfo {
aid: string
mid: string
account_name: string
email: string
is_email_verify: number
area_code: string
safe_mobile: string
realname: string
identity_code: string
rebind_area_code: string
rebind_mobile: string
rebind_mobile_time: string
links: unknown[]
}
/**
* @description 验证 stoken 的响应
* @since Alpha v0.2.0
* @see TGRequest.User.bySToken.verify
* @interface Verify extends BTMuli.Genshin.Base.Response
* @property {VerifyUserInfo} data.user_info 用户信息
* @property {unknown} data.realname_info 实名信息
* @property {boolean} need_realperson 是否需要实名认证
* @returns {Verify}
*/
export interface Verify extends BTMuli.Genshin.Base.Response {
data: {
user_info: VerifyUserInfo
realname_info: unknown | null
need_realperson: boolean
}
}
/**
* @description 获取游戏账号的响应
* @since Alpha v0.2.0
* @see TGRequest.User.byCookie.getGameAccounts
* @interface GameAccounts
* @extends {BTMuli.Genshin.Base.Response}
* @property {BTMuli.User.Game.Account[]} data.list 游戏账号
* @returns {GameAccounts}
*/
export interface GameAccounts extends BTMuli.Genshin.Base.Response {
data: {
list: BTMuli.User.Game.Account[]
}
}
}

View File

@@ -1,19 +1,21 @@
/**
* @file core request TGRequest.ts
* @file web request TGRequest.ts
* @description 应用用到的请求函数
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
import { getAnnoList, getAnnoContent } from "./getAnno";
import {
getTokensByLoginTicket, getLtokenBySToken,
getCookieTokenBySToken, vetifySToken,
} from "./getTokens";
import {
getGameCardByCookie, getGameAccountsByCookie,
getAccountsBySToken, getGameRoleListByCookie,
} from "./getGameData";
import { getCookieTokenBySToken } from "./getCookieToken";
// import * from "./getEnkaData.ts";
import { getGameAccountsBySToken, getGameAccountsByCookie } from "./getGameAccounts";
import { getLTokenBySToken } from "./getLToken";
// import * from "./getRoleList.ts";
// import * from "./getTickets.ts";
import { getTokensByLoginTicket } from "./getTokens";
// import * from "./getUserCard";
import initCookie from "./initCookie";
import { verifyLToken } from "./verifyLToken";
const TGRequest = {
Anno: {
@@ -21,19 +23,20 @@ const TGRequest = {
getContent: getAnnoContent,
},
User: {
init: initCookie,
byLoginTicket: {
getLTokens: getTokensByLoginTicket,
getTokens: getTokensByLoginTicket,
},
byCookie: {
getAccounts: getGameAccountsByCookie,
getGameCard: getGameCardByCookie,
getCharacter: getGameRoleListByCookie,
},
byLToken: {
verify: verifyLToken,
},
bySToken: {
verify: vetifySToken,
getLToken: getLtokenBySToken,
getAccounts: getAccountsBySToken,
getAccounts: getGameAccountsBySToken,
getCookieToken: getCookieTokenBySToken,
getLToken: getLTokenBySToken,
},
},
};

View File

@@ -0,0 +1,41 @@
/**
* @file web request getCookieToken.ts
* @description 获取 Cookie Token 的请求函数
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
// tauri
import { http } from "@tauri-apps/api";
// Node
import qs from "qs";
// api
import TGApi from "../api/TGApi";
// utils
import TGUtils from "../utils/TGUtils";
import { transCookie } from "../utils/tools";
/**
* @description 根据 stoken 获取 cookie_token
* @since Alpha v0.2.0
* @param {string} stuid 登录用户 uid
* @param {string} stoken stoken
* @returns {Promise<string|BTMuli.Genshin.Base.Response>}
*/
export async function getCookieTokenBySToken (stuid: string, stoken: string): Promise<string | BTMuli.Genshin.Base.Response> {
const url = TGApi.GameTokens.getCookieToken;
const cookie = {
stuid,
stoken,
};
const params = { stoken };
const header = TGUtils.User.getHeader(transCookie(cookie), "GET", qs.stringify(params), "common");
return await http.fetch<BTMuli.User.Response.CookieToken>(url, {
method: "GET",
headers: header,
body: http.Body.json(params),
}).then((res) => {
if (res.data.retcode !== 0) return res.data;
return res.data.data.cookie_token;
});
}

View File

@@ -0,0 +1,72 @@
/**
* @file web request getGameAccounts.ts
* @description 获取游戏账号信息相关请求函数
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
// tauri
import { http } from "@tauri-apps/api";
// Node
import qs from "qs";
// api
import TGApi from "../api/TGApi";
// utils
import TGUtils from "../utils/TGUtils";
import { transCookie } from "../utils/tools";
import TGConstant from "../constant/TGConstant";
/**
* @description 通过 stoken 获取游戏账号
* @since Alpha v0.2.0
* @param {string} stoken stoken
* @param {string} stuid 登录用户 uid
* @returns {Promise<BTMuli.User.Game.Account[]|BTMuli.Genshin.Base.Response>}
*/
export async function getGameAccountsBySToken (stoken: string, stuid: string): Promise<BTMuli.User.Game.Account[] | BTMuli.Genshin.Base.Response> {
const url = TGApi.GameData.bySToken.getAccounts;
const cookie = {
stuid,
stoken,
};
const params = { stoke: stoken, game_biz: TGConstant.Utils.GAME_BIZ };
const header = TGUtils.User.getHeader(transCookie(cookie), "GET", qs.stringify(params), "common");
return await getGameAccounts(url, cookie, params);
}
/**
* @description 通过 cookie 获取游戏账号
* @since Alpha v0.2.0
* @param {string} cookie_token cookie_token
* @param {string} account_id 游戏账号 id
* @returns {Promise<BTMuli.User.Game.Account[]|BTMuli.Genshin.Base.Response>}
*/
export async function getGameAccountsByCookie (cookie_token: string, account_id: string): Promise<BTMuli.User.Game.Account[] | BTMuli.Genshin.Base.Response> {
const url = TGApi.GameData.byCookie.getAccounts;
const cookie = {
account_id,
cookie_token,
};
const params = { game_biz: TGConstant.Utils.GAME_BIZ };
return await getGameAccounts(url, cookie, params);
}
/**
* @description 获取游戏账号信息
* @since Alpha v0.2.0
* @param {string} url 请求地址
* @param {Record<string, string>} cookie cookie
* @param {Record<string, string>} params 请求参数
* @returns {Promise<BTMuli.User.Game.Account[]|BTMuli.Genshin.Base.Response>}
*/
async function getGameAccounts (url: string, cookie: Record<string, string>, params: Record<string, string>): Promise<BTMuli.User.Game.Account[] | BTMuli.Genshin.Base.Response> {
const header = TGUtils.User.getHeader(transCookie(cookie), "GET", qs.stringify(params), "common");
return await http.fetch<BTMuli.User.Response.GameAccounts>(url, {
method: "GET",
headers: header,
body: http.Body.json(params),
}).then(res => {
if (res.data.retcode !== 0) return res.data;
return res.data.data.list;
});
}

View File

@@ -1,101 +0,0 @@
/**
* @file core utils getGameData.ts
* @description 获取游戏数据的函数
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
// tauri
import { http } from "@tauri-apps/api";
import qs from "qs";
// utils
import TGApi from "../api/TGApi";
import TGUtils from "../utils/TGUtils";
import TGConstant from "../constant/TGConstant";
/**
* @description 获取用户游戏数据
* @since Alpha v0.2.0
* @param {string} cookie 用户的 Cookie
* @param {string} uid 用户的 UID
* @returns {Promise<unknown>} 用户基本信息
*/
export async function getGameCardByCookie (cookie: string, uid: string): Promise<unknown> {
const url = `${TGApi.GameData.getUserCard}`;
const params = { uid };
const header = TGUtils.User.getHeader(cookie, "GET", qs.stringify(params), "common");
console.log("header:", header);
return await http.fetch(url, {
method: "GET",
headers: header,
body: http.Body.json(params),
}).then((res) => {
console.log(res);
return res.data;
});
}
/**
* @description 获取用户绑定角色-通过stoken
* @since Alpha v0.2.0
* @todo 暂时不考虑使用
* @param {string} cookie 用户的 Cookie
* @param {string} stoken stoken
* @returns {Promise<unknown>} 用户绑定角色
*/
export async function getAccountsBySToken (cookie: string, stoken: string): Promise<unknown> {
const url = TGApi.GameData.bySToken.getAccounts;
// eslint-disable-next-line camelcase
const params = { stoken, game_biz: TGConstant.Utils.GAME_BIZ };
const header = TGUtils.User.getHeader(cookie, "GET", JSON.stringify(params), "common");
return await http.fetch(url, {
method: "GET",
headers: header,
body: http.Body.json(params),
}).then((res) => {
console.log(res.data);
return res.data;
});
}
/**
* @description 获取用户绑定游戏账号-通过cookie
* @since Alpha v0.2.0
* @param {string} cookie 用户的 Cookie
* @returns {Promise<BTMuli.Genshin.Base.Response| BTMuli.User.Game.Account[]>} 用户绑定角色
*/
export async function getGameAccountsByCookie (cookie: string): Promise<BTMuli.Genshin.Base.Response | BTMuli.User.Game.Account[]> {
const url = TGApi.GameData.byCookie.getAccounts;
const params = { game_biz: TGConstant.Utils.GAME_BIZ };
const header = TGUtils.User.getHeader(cookie, "GET", qs.stringify(params), "common");
return await http.fetch<BTMuli.User.Response.GameAccounts>(url, {
method: "GET",
headers: header,
}).then((res) => {
console.log(res.data);
if (res.data.retcode !== 0) return res.data;
return res.data.data.list;
});
}
/**
* @description 获取用户角色列表
* @since Alpha v0.2.0
* @param {string} cookie 用户的 Cookie
* @param {string} uid 用户 uid
* @returns {Promise<unknown>} 用户角色列表
*/
export async function getGameRoleListByCookie (cookie: string, uid: string): Promise<unknown> {
const url = TGApi.GameData.byCookie.getCharacter;
// eslint-disable-next-line camelcase
const data = { role_id: uid, server: TGUtils.Tools.getServerByUid(uid) };
const header = TGUtils.User.getHeader(cookie, "", JSON.stringify(data), "common");
return await http.fetch(url, {
method: "POST",
headers: header,
body: http.Body.json(data),
}).then((res) => {
console.log(res.data);
return res.data;
});
}

View File

@@ -0,0 +1,41 @@
/**
* @file web request getLToken.ts
* @description 获取 ltoken 的请求
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
// tauri
import { http } from "@tauri-apps/api";
// Node
import qs from "qs";
// api
import TGApi from "../api/TGApi";
// utils
import TGUtils from "../utils/TGUtils";
import { transCookie } from "../utils/tools";
/**
* @description 根据 stoken 获取 ltoken
* @since Alpha v0.2.0
* @param {string} stuid 登录用户 uid
* @param {string} stoken stoken
* @returns {Promise<string|BTMuli.Genshin.Base.Response>}
*/
export async function getLTokenBySToken (stuid: string, stoken: string): Promise<string | BTMuli.Genshin.Base.Response> {
const url = TGApi.GameTokens.getLToken;
const cookie = {
stuid,
stoken,
};
const params = { stoken };
const header = TGUtils.User.getHeader(transCookie(cookie), "GET", qs.stringify(params), "common");
return await http.fetch<BTMuli.User.Response.LToken>(url, {
method: "GET",
headers: header,
body: http.Body.json(params),
}).then((res) => {
if (res.data.retcode !== 0) return res.data;
return res.data.data.ltoken;
});
}

View File

@@ -13,95 +13,31 @@ import qs from "qs";
import TGApi from "../api/TGApi";
// utils
import TGUtils from "../utils/TGUtils";
import { transCookie } from "../utils/tools";
/**
* @description 根据 login_ticket 获取游戏 Token包括 stoken 和 ltoken
* @since Alpha v0.2.0
* @param {string} cookie cookie
* @param {string} ticket 登录票证
* @param {string} uid 登录用户 uid
* @returns {Promise<BTMuli.User.Base.TokenItem[] | BTMuli.Genshin.Base.Response>}
*/
// eslint-disable-next-line camelcase
export async function getTokensByLoginTicket (cookie: string, ticket: string, uid: string): Promise<BTMuli.User.Base.TokenItem[] | BTMuli.Genshin.Base.Response> {
export async function getTokensByLoginTicket (ticket: string, uid: string): Promise<BTMuli.User.Response.TokenItem[] | BTMuli.Genshin.Base.Response> {
const cookie = {
login_ticket: ticket,
login_uid: uid,
};
const url = TGApi.GameTokens.getTokens;
// eslint-disable-next-line camelcase
const url = `${TGApi.GameTokens.getTokens}?login_ticket=${ticket}&token_types=3&uid=${uid}`;
// eslint-disable-next-line camelcase
const param = { login_ticket: ticket, token_types: 3, uid };
const header = TGUtils.User.getHeader(cookie, "GET", qs.stringify(param), "common");
console.log("header:", header);
return await http.fetch<BTMuli.User.Response.Token>(url, {
const params = { login_ticket: ticket, token_types: 3, uid };
const header = TGUtils.User.getHeader(transCookie(cookie), "GET", qs.stringify(params), "common");
return await http.fetch<BTMuli.User.Response.Tokens>(url, {
method: "GET",
headers: header,
body: http.Body.json(params),
}).then((res) => {
console.log(res);
if (res.data.retcode !== 0) return res.data;
return res.data.data.list;
});
}
/**
* @description 根据 stoken 获取 ltoken
* @since Alpha v0.2.0
* @param {string} cookie 用户 Cookie
* @param {string} stoken stoken
* @returns {Promise<unknown>}
*/
export async function getLtokenBySToken (cookie: string, stoken: string): Promise<unknown> {
const url = TGApi.GameTokens.getLToken;
const params = { stoken };
const header = TGUtils.User.getHeader(cookie, "GET", qs.stringify(params), "common");
console.log("header:", header);
return await http.fetch<BTMuli.User.Response.Token>(url, {
method: "GET",
headers: header,
body: http.Body.json(params),
}).then((res) => {
console.log(res);
if (res.data.retcode !== 0) return res.data;
});
}
/**
* @description 根据 stoken 获取 cookieToken
* @since Alpha v0.2.0
* @param {string} cookie 用户 Cookie
* @param {string} stoken stoken
* @returns {Promise<unknown>}
*/
export async function getCookieTokenBySToken (cookie: string, stoken: string): Promise<unknown> {
const url = TGApi.GameTokens.getCookieToken;
const params = { stoken };
const header = TGUtils.User.getHeader(cookie, "GET", qs.stringify(params), "common");
console.log("header:", header);
return await http.fetch(url, {
method: "GET",
headers: header,
body: http.Body.json(params),
}).then((res) => {
console.log(res.data);
return res.data;
});
}
/**
* @description 验证 stoken 有效性
* @since Alpha v0.2.0
* @param {string} cookie 用户 Cookie
* @param {string} stoken stoken
* @returns {Promise<unknown>}
*/
export async function verifySToken (cookie: string, stoken: string): Promise<unknown> {
const url = TGApi.GameTokens.verifyStoken;
const data = { stoken };
const header = TGUtils.User.getHeader(cookie, "POST", qs.stringify(data), "common");
console.log("header:", header);
return await http.fetch(url, {
method: "POST",
headers: header,
body: http.Body.json(data),
}).then((res) => {
console.log(res.data);
return res.data;
});
}

View File

@@ -0,0 +1,54 @@
/**
* @file web request initCookie.ts
* @description 首次输入 cookie 后的一系列请求
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
// utils
import TGSqlite from "../../utils/TGSqlite";
// request
import { getTokensByLoginTicket } from "./getTokens";
import { getCookieTokenBySToken } from "./getCookieToken";
import { verifyLToken } from "./verifyLToken";
/**
* @description 根据输入 cookie 获取一堆 token
* @since Alpha v0.2.0
* @param {string} ticket login_ticket
* @param {string} uid login_uid
* @returns {Promise<void>}
*/
async function initCookie (ticket: string, uid: string): Promise<void> {
const tokenRes = await getTokensByLoginTicket(ticket, uid);
const cookie: BTMuli.User.Base.Cookie = {
account_id: uid,
cookie_token: "",
login_ticket: ticket,
mid: "",
login_uid: uid,
ltoken: "",
ltuid: uid,
stoken: "",
stuid: uid,
};
if (Array.isArray(tokenRes)) {
const lToken = tokenRes.find((item) => item.name === "ltoken");
const sToken = tokenRes.find((item) => item.name === "stoken");
if (lToken) {
await TGSqlite.saveAppData("ltoken", lToken.token);
cookie.ltoken = lToken.token;
}
if (sToken) {
await TGSqlite.saveAppData("stoken", sToken.token);
cookie.stoken = sToken.token;
}
const cookieToken = await getCookieTokenBySToken(uid, cookie.stoken);
if (typeof cookieToken === "string") cookie.cookie_token = cookieToken;
const mid = await verifyLToken(cookie.ltoken, cookie.ltuid, cookie.stoken);
if (typeof mid === "string") cookie.mid = mid;
await TGSqlite.saveAppData("cookie", JSON.stringify(cookie));
}
}
export default initCookie;

View File

@@ -0,0 +1,43 @@
/**
* @file web request verifyLToken.ts
* @description 验证 stoken 的请求函数
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
// tauri
import { http } from "@tauri-apps/api";
// Node
import qs from "qs";
// api
import TGApi from "../api/TGApi";
// utils
import TGUtils from "../utils/TGUtils";
import { transCookie } from "../utils/tools";
/**
* @description 验证 stoken 有效性,返回 mid
* @since Alpha v0.2.0
* @param {string} ltoken ltoken
* @param {string} ltuid 登录用户 uid
* @param {string} stoken stoken
* @returns {Promise<string | BTMuli.Genshin.Base.Response>}
*/
export async function verifyLToken (ltoken: string, ltuid: string, stoken: string): Promise<string | BTMuli.Genshin.Base.Response> {
const url = TGApi.GameTokens.verifyLToken;
const cookie = {
ltoken,
ltuid,
};
const data = { stoken };
const header = TGUtils.User.getHeader(transCookie(cookie), "POST", qs.stringify(data), "common");
console.log("header:", header);
return await http.fetch<BTMuli.User.Response.Verify>(url, {
method: "POST",
headers: header,
body: http.Body.json(data),
}).then((res) => {
if (res.data.retcode !== 0) return res.data;
return res.data.data.user_info.mid;
});
}

View File

@@ -5,10 +5,10 @@
* @since Alpha v0.2.0
*/
import { parseAnnoContent } from "./parseAnno";
import { getAnnoCard } from "./getAnnoCard";
import { getRequestHeader } from "./getRequestHeader";
import { cookieToString, getServerByUid } from "./tools";
import { parseAnnoContent } from "./parseAnno";
import { transCookie, getServerByUid } from "./tools";
const TGUtils = {
Anno: {
@@ -19,7 +19,7 @@ const TGUtils = {
getHeader: getRequestHeader,
},
Tools: {
cookieToString,
transCookie,
getServerByUid,
},
};

View File

@@ -1,53 +0,0 @@
/**
* @file web utils getDS.ts
* @description ds 算法
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
// Node
import md5 from "js-md5";
import qs from "qs";
// Tauri.Genshin
import { random } from "./tools";
import TGConstant from "../constant/TGConstant";
/**
* @description 获取 salt
* @since Alpha v0.2.0
* @version 2.49.1
* @param {string} saltType salt 类型
* @returns {string} salt
*/
function getSalt (saltType: string) {
switch (saltType) {
case "common":
return TGConstant.Salt.Other.X4;
case "prod":
return TGConstant.Salt.Other.prod;
default:
return TGConstant.Salt.Other.X4;
}
}
/**
* @description 获取 ds
* @since Alpha v0.2.0
* @version 2.49.1
* @param {string} saltType salt 类型
* @param {string} method 请求方法
* @param {string} data 请求数据
* @returns {string} ds
*/
export function getDS (method: string, data: string, saltType: string): string {
const salt = getSalt(saltType);
const params = {
salt,
t: Math.floor(Date.now() / 1000).toString(),
r: random(100000, 200000).toString(),
b: method === "GET" ? "" : data,
q: method === "GET" ? data : "",
};
const md5Str = md5.update(qs.stringify(params)).hex();
return `${params.t},${params.r},${md5Str}`;
}

View File

@@ -5,8 +5,62 @@
* @since Alpha v0.2.0
*/
// Node
import md5 from "js-md5";
import qs from "qs";
// Tauri.Genshin
import TGConstant from "../constant/TGConstant";
import { getDS } from "./getDS";
/**
* @description 获取 salt
* @since Alpha v0.2.0
* @version 2.49.1
* @param {string} saltType salt 类型
* @returns {string} salt
*/
function getSalt (saltType: string) {
switch (saltType) {
case "common":
return TGConstant.Salt.Other.X4;
case "prod":
return TGConstant.Salt.Other.prod;
default:
return TGConstant.Salt.Other.X4;
}
}
/**
* @description 获取随机数
* @since Alpha v0.2.0
* @param {number} min 最小值
* @param {number} max 最大值
* @returns {number} 随机数
*/
function random (min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1) + min);
}
/**
* @description 获取 ds
* @since Alpha v0.2.0
* @version 2.49.1
* @param {string} saltType salt 类型
* @param {string} method 请求方法
* @param {string} data 请求数据
* @returns {string} ds
*/
function getDS (method: string, data: string, saltType: string): string {
const salt = getSalt(saltType);
const params = {
salt,
t: Math.floor(Date.now() / 1000).toString(),
r: random(100000, 200000).toString(),
b: method === "GET" ? "" : data,
q: method === "GET" ? data : "",
};
const md5Str = md5.update(qs.stringify(params)).hex();
return `${params.t},${params.r},${md5Str}`;
}
/**
* @description 获取请求头

View File

@@ -5,8 +5,6 @@
* @since Alpha v0.2.0
*/
// Node
import { stringify } from "qs";
// TauriGenshin
import TGConstant from "../constant/TGConstant";
@@ -44,17 +42,6 @@ export function getRandomString (length: number): string {
return res;
}
/**
* @description 获取随机数
* @since Alpha v0.2.0
* @param {number} min 最小值
* @param {number} max 最大值
* @returns {number} 随机数
*/
export function random (min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1) + min);
}
/**
* @description object 转换为 query string
* @since Alpha v0.2.0