添加 gt 获取 st,ckt 相关请求

This commit is contained in:
BTMuli
2023-09-03 23:08:23 +08:00
parent 733ef716e2
commit 4f6f065645
6 changed files with 164 additions and 9 deletions

View File

@@ -1,11 +1,11 @@
/**
* @file web constant TGConstant.ts
* @description 常量
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
* @author BTMuli <bt-muli@outlook.com>
* @since Beta v0.3.0
*/
import { BBS_VERSION, BBS_HEADER_AGENT } from "./bbs";
import { BBS_VERSION, BBS_HEADER_AGENT, BBS_APP_ID } from "./bbs";
import SALT from "./salt";
import SERVER from "./server";
import { GAME_BIZ } from "./utils";
@@ -14,6 +14,7 @@ const TGConstant = {
BBS: {
VERSION: BBS_VERSION,
USER_AGENT: BBS_HEADER_AGENT,
APP_ID: BBS_APP_ID,
},
Salt: SALT,
Server: SERVER,

View File

@@ -1,9 +1,10 @@
/**
* @file web constant bbs.ts
* @description 常量-应用数据
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
* @author BTMuli <bt-muli@outlook.com>
* @since Beta v0.3.0
*/
export const BBS_VERSION = "2.50.1";
export const BBS_HEADER_AGENT = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) miHoYoBBS/${BBS_VERSION}`;
export const BBS_APP_ID = "bll8iq97cem8";

View File

@@ -2,7 +2,7 @@
* @file web request getCookieToken.ts
* @description 获取 Cookie Token 的请求函数
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.5
* @since Beta v0.3.0
*/
// tauri
@@ -41,3 +41,27 @@ export async function getCookieTokenBySToken(
return res.data.data.cookie_token;
});
}
/**
* @description 根据 gameToken 获取 cookie_token
* @since Beta v0.3.0
* @param {string} accountId 账号 id
* @param {string} gameToken gameToken
* @returns {Promise<string|TGApp.BBS.Response.Base>}
*/
export async function getCookieTokenByGameToken(
accountId: string,
gameToken: string,
): Promise<string | TGApp.BBS.Response.Base> {
const url = "https://api-takumi.mihoyo.com/auth/api/getCookieAccountInfoByGameToken";
const data = { account_id: accountId, game_token: gameToken };
return await http
.fetch<TGApp.BBS.Response.getCookieTokenByGameToken>(url, {
method: "GET",
body: http.Body.json(data),
})
.then((res) => {
if (res.data.retcode !== 0) return res.data;
return res.data.data.cookie_token;
});
}

View File

@@ -0,0 +1,39 @@
/**
* @file web request getStoken.ts
* @description 获取 stoken
* @author BTMuli <bt-muli@outlook.com>
* @since Beta v0.3.0
*/
// tauri
import { http } from "@tauri-apps/api";
// constant
import TGConstant from "../constant/TGConstant";
/**
* @description 获取 stoken
* @since Beta v0.3.0
* @param {string} accountId 账户 ID
* @param {string} gameToken 游戏 Token
* @returns {Promise<string | TGApp.BBS.Response.Base>}
*/
export async function getStokenByGameToken(
accountId: string,
gameToken: string,
): Promise<TGApp.BBS.Response.getStokenByGameTokenData | TGApp.BBS.Response.Base> {
const url = "https://api-takumi.mihoyo.com/account/ma-cn-session/app/getTokenByGameToken";
const data = { account_id: accountId, game_token: gameToken };
const header = {
"x-rpc-app_id": TGConstant.BBS.APP_ID,
};
return await http
.fetch<TGApp.BBS.Response.getStokenByGameToken>(url, {
method: "POST",
headers: header,
body: http.Body.json(data),
})
.then((res) => {
if (res.data.retcode !== 0) return res.data;
return res.data.data;
});
}