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