mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
✏️ 根据实际请求修正参数
This commit is contained in:
@@ -4,8 +4,6 @@
|
||||
* @since Beta v0.5.3
|
||||
*/
|
||||
|
||||
import { app } from "@tauri-apps/api";
|
||||
|
||||
import TGHttp from "../../utils/TGHttp.js";
|
||||
import TGApi from "../api/TGApi.js";
|
||||
import TGUtils from "../utils/TGUtils.js";
|
||||
@@ -23,12 +21,7 @@ export async function getAvatarList(
|
||||
): Promise<TGApp.Game.Avatar.Avatar[] | TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameData.byCookie.getAvatarList;
|
||||
const data = { uid, region: TGUtils.Tools.getServerByUid(uid) };
|
||||
const version = await app.getVersion();
|
||||
const header = {
|
||||
"User-Agent": `TeyvatGuide/${version}`,
|
||||
Referer: "https://webstatic.mihoyo.com/",
|
||||
Cookie: TGUtils.Tools.transCookie(cookie),
|
||||
};
|
||||
const header = TGUtils.User.getHeader(cookie, "POST", data, "common");
|
||||
const resp = await TGHttp<TGApp.Game.Avatar.ListResponse | TGApp.BBS.Response.Base>(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
@@ -43,22 +36,21 @@ export async function getAvatarList(
|
||||
* @since Beta v0.5.3
|
||||
* @param {Record<string, string>} cookie Cookie
|
||||
* @param {string} uid 用户 uid
|
||||
* @param {number} avatarId 角色 id
|
||||
* @param {string[]} avatarIds 角色 id 列表
|
||||
* @return {Promise<TGApp.Game.Avatar.AvatarDetail|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
export async function getAvatarDetail(
|
||||
cookie: Record<string, string>,
|
||||
uid: string,
|
||||
avatarId: number,
|
||||
avatarIds: string[],
|
||||
): Promise<TGApp.Game.Avatar.AvatarDetail | TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameData.byCookie.getAvatarDetail;
|
||||
const params = { uid, region: TGUtils.Tools.getServerByUid(uid), avatar_id: avatarId };
|
||||
const version = await app.getVersion();
|
||||
const header = {
|
||||
"User-Agent": `TeyvatGuide/${version}`,
|
||||
Referer: "https://webstatic.mihoyo.com/",
|
||||
Cookie: TGUtils.Tools.transCookie(cookie),
|
||||
const params = {
|
||||
role_id: uid,
|
||||
server: TGUtils.Tools.getServerByUid(uid),
|
||||
character_ids: avatarIds,
|
||||
};
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
|
||||
const resp = await TGHttp<TGApp.Game.Avatar.DetailResponse | TGApp.BBS.Response.Base>(url, {
|
||||
method: "GET",
|
||||
query: params,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file web/utils/getRequestHeader.ts
|
||||
* @description 获取请求头
|
||||
* @since Beta v0.3.9
|
||||
* @since Beta v0.5.3
|
||||
*/
|
||||
|
||||
import Md5 from "js-md5";
|
||||
@@ -67,7 +67,7 @@ function getDS(method: string, data: string, saltType: string, isSign: boolean):
|
||||
|
||||
/**
|
||||
* @description 获取请求头
|
||||
* @since Beta v0.3.6
|
||||
* @since Beta v0.5.3
|
||||
* @param {Record<string, string>} cookie cookie
|
||||
* @param {string} method 请求方法
|
||||
* @param {Record<string, string|number>|string} data 请求数据
|
||||
@@ -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,
|
||||
data: Record<string, string | number | string[]> | string,
|
||||
saltType: string,
|
||||
isSign: boolean = false,
|
||||
): Record<string, string> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file web utils tools.ts
|
||||
* @file web/utils/tools.ts
|
||||
* @description 应用用到的工具函数
|
||||
* @since Beta v0.4.3
|
||||
* @since Beta v0.5.3
|
||||
*/
|
||||
|
||||
import TGConstant from "../constant/TGConstant.js";
|
||||
@@ -42,11 +42,11 @@ export function transCookie(cookie: Record<string, string>): string {
|
||||
|
||||
/**
|
||||
* @description ds 算法需要数据转换后的字符串是按照字典序排序的
|
||||
* @since Alpha v0.1.5
|
||||
* @since Beta v0.5.3
|
||||
* @param {Record<string, string|number>} obj object
|
||||
* @returns {string} query string
|
||||
*/
|
||||
export function transParams(obj: Record<string, string | number>): string {
|
||||
export function transParams(obj: Record<string, string | number | string[]>): string {
|
||||
let res = "";
|
||||
const keys = Object.keys(obj).sort();
|
||||
for (const key of keys) {
|
||||
|
||||
Reference in New Issue
Block a user