mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-04-15 21:03:29 +08:00
🏷️ 更新游戏启动 Ticket 返回类型,增强类型安全性
This commit is contained in:
@@ -741,7 +741,12 @@ async function tryLaunchGame(): Promise<void> {
|
||||
}
|
||||
const gamePath = `${gameDir.value}${path.sep()}${find.name}`;
|
||||
const resp = await passportReq.authTicket(account.value, cookie.value);
|
||||
if (typeof resp !== "string") {
|
||||
if (typeof resp !== "object") {
|
||||
showSnackbar.error(resp);
|
||||
await TGLogger.Error(`[sidebar][tryLaunchGame] resp: ${resp}`);
|
||||
return;
|
||||
}
|
||||
if ("retcode" in resp) {
|
||||
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
|
||||
await TGLogger.Error(
|
||||
`[sidebar][tryLaunchGame] 尝试获取authTicket失败,当前用户:${account.value.uid}-${account.value.gameUid}`,
|
||||
@@ -751,7 +756,7 @@ async function tryLaunchGame(): Promise<void> {
|
||||
}
|
||||
showSnackbar.success(`成功获取ticket:${resp},正在启动应用...`);
|
||||
try {
|
||||
await invoke("launch_game", { path: gamePath, ticket: resp });
|
||||
await invoke("launch_game", { path: gamePath, ticket: resp.ticket });
|
||||
} catch (error) {
|
||||
showSnackbar.error(`${error}`);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,12 @@ async function tryPlayGame(): Promise<void> {
|
||||
}
|
||||
const gamePath = `${gameDir.value}${path.sep()}${find.name}`;
|
||||
const resp = await passportReq.authTicket(account.value, cookie.value);
|
||||
if (typeof resp !== "string") {
|
||||
if (typeof resp !== "object") {
|
||||
showSnackbar.error(resp);
|
||||
await TGLogger.Error(`[sidebar][tryLaunchGame] resp: ${resp}`);
|
||||
return;
|
||||
}
|
||||
if ("retcode" in resp) {
|
||||
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
|
||||
await TGLogger.Error(
|
||||
`[config][gameBadge] 尝试获取authTicket失败,当前用户:${account.value.uid}-${account.value.gameUid}`,
|
||||
@@ -60,7 +65,7 @@ async function tryPlayGame(): Promise<void> {
|
||||
}
|
||||
showSnackbar.success(`成功获取ticket:${resp},正在启动应用...`);
|
||||
try {
|
||||
await invoke("launch_game", { path: gamePath, ticket: resp });
|
||||
await invoke("launch_game", { path: gamePath, ticket: resp.ticket });
|
||||
} catch (error) {
|
||||
showSnackbar.error(`${error}`);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Passport 相关请求
|
||||
* @since Beta v0.7.2
|
||||
* @since Beta v0.9.9
|
||||
*/
|
||||
import { getRequestHeader } from "@utils/getRequestHeader.js";
|
||||
import TGBbs from "@utils/TGBbs.js";
|
||||
@@ -37,7 +37,7 @@ function rsaEncrypt(data: string): string {
|
||||
|
||||
/**
|
||||
* 获取登录ticket
|
||||
* @since Beta v0.6.0
|
||||
* @since Beta v0.9.9
|
||||
* @param account - 账户
|
||||
* @param cookie - cookie
|
||||
* @returns ticket
|
||||
@@ -45,7 +45,7 @@ function rsaEncrypt(data: string): string {
|
||||
async function createAuthTicketByGameBiz(
|
||||
account: TGApp.Sqlite.Account.Game,
|
||||
cookie: TGApp.App.Account.Cookie,
|
||||
): Promise<TGApp.BBS.Response.Base | string> {
|
||||
): Promise<TGApp.BBS.Response.Base | TGApp.Game.Login.GameAuthTicketRes> {
|
||||
const params: Record<string, string> = {
|
||||
game_biz: account.gameBiz,
|
||||
stoken: cookie.stoken,
|
||||
@@ -56,13 +56,12 @@ async function createAuthTicketByGameBiz(
|
||||
"x-rpc-client_type": "3",
|
||||
"x-rpc-app_id": "ddxf5dufpuyo",
|
||||
};
|
||||
type ResType = { ticket: string };
|
||||
const resp = await TGHttp<TGApp.BBS.Response.BaseWithData<ResType>>(
|
||||
const resp = await TGHttp<TGApp.Game.Login.GameAuthTicketResp>(
|
||||
`${pAbu}account/ma-cn-verifier/app/createAuthTicketByGameBiz`,
|
||||
{ method: "POST", headers: headers, query: params },
|
||||
);
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.ticket;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
15
src/types/Game/Login.d.ts
vendored
15
src/types/Game/Login.d.ts
vendored
@@ -99,4 +99,19 @@ declare namespace TGApp.Game.Login {
|
||||
/** 是否需要实名 */
|
||||
need_realperson: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* 游戏启动 Ticket 返回响应
|
||||
* @since Beta v0.9.9
|
||||
*/
|
||||
type GameAuthTicketResp = TGApp.BBS.Response.BaseWithData<GameAuthTicketRes>;
|
||||
|
||||
/**
|
||||
* 游戏启动 Ticket 返回
|
||||
* @since Beta v0.9.9
|
||||
*/
|
||||
type GameAuthTicketRes = {
|
||||
/** Ticket */
|
||||
ticket: string;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user