From 4fef4d94e1c0996d9e0a0e69c66ff25743727a38 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Mon, 4 Sep 2023 14:54:05 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=AE=9E=E8=A3=85=20authKey=20?= =?UTF-8?q?=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/user.ts | 8 ------- src/types/Game/Gacha.d.ts | 26 +++++++++++++++++++++ src/web/request/TGRequest.ts | 2 ++ src/web/request/genAuthkey.ts | 43 +++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 src/types/Game/Gacha.d.ts create mode 100644 src/web/request/genAuthkey.ts diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index f742cdd9..110ba0a2 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -51,13 +51,6 @@ export const useUserStore = defineStore( return cookie.value[key] || ""; } - function getCookieGroup1(): TGApp.BBS.Constant.CookieGroup1 { - return { - login_ticket: getCookieItem("login_ticket"), - login_uid: getCookieItem("login_uid"), - }; - } - function getCookieGroup2(): TGApp.BBS.Constant.CookieGroup2 { return { account_id: getCookieItem("account_id"), @@ -89,7 +82,6 @@ export const useUserStore = defineStore( setBriefInfo, setCurAccount, getCurAccount, - getCookieGroup1, getCookieGroup2, getCookieGroup3, getCookieGroup4, diff --git a/src/types/Game/Gacha.d.ts b/src/types/Game/Gacha.d.ts new file mode 100644 index 00000000..90beb457 --- /dev/null +++ b/src/types/Game/Gacha.d.ts @@ -0,0 +1,26 @@ +/** + * @file types Game Gacha.d.ts + * @description 游戏抽卡相关类型定义文件 + * @author BTMuli + * @since Beta v0.3.0 + */ + +declare namespace TGApp.Game.Gacha { + /** + * @description 获取 authkey 返回类型 + * @interface AuthkeyResponse + * @since Beta v0.3.0 + * @extends TGApp.BBS.Response.Base + * @property {number} data.sign_type - 签名类型 + * @property {number} data.authkey_ver - authkey 版本 + * @property {string} data.authkey - authkey + * @return AuthkeyResponse + */ + export interface AuthkeyResponse extends TGApp.BBS.Response.Base { + data: { + sign_type: number; + authkey_ver: number; + authkey: string; + }; + } +} diff --git a/src/web/request/TGRequest.ts b/src/web/request/TGRequest.ts index d67612bb..b83d2116 100644 --- a/src/web/request/TGRequest.ts +++ b/src/web/request/TGRequest.ts @@ -5,6 +5,7 @@ * @since Beta v0.3.0 */ +import { genAuthkey } from "./genAuthkey"; import { getAbyss } from "./getAbyss"; import { getAnnoList, getAnnoContent } from "./getAnno"; import { getCookieTokenByGameToken, getCookieTokenBySToken } from "./getCookieToken"; @@ -26,6 +27,7 @@ const TGRequest = { getContent: getAnnoContent, }, User: { + getAuthkey: genAuthkey, getRecord: getGameRecord, byLoginTicket: { getTokens: getTokensByLoginTicket, diff --git a/src/web/request/genAuthkey.ts b/src/web/request/genAuthkey.ts new file mode 100644 index 00000000..ddc6cef4 --- /dev/null +++ b/src/web/request/genAuthkey.ts @@ -0,0 +1,43 @@ +/** + * @file web request genAuthkey.ts + * @description 生成 authkey + * @author BTMuli + * @since Beta v0.3.0 + */ + +// tauri +import { http } from "@tauri-apps/api"; +// utils +import TGUtils from "../utils/TGUtils"; +import TGConstant from "../constant/TGConstant"; + +/** + * @description 生成 authkey + * @since Beta v0.3.0 + * @param {Record} cookie cookie // stoken_v2 & mid + * @param {string} gameUid 游戏 uid + * @returns {Promise} authkey + */ +export async function genAuthkey( + cookie: Record, + gameUid: string, +): Promise { + const url = "https://api-takumi.mihoyo.com/binding/api/genAuthKey"; + const data = { + auth_appid: "webview_gacha", + game_biz: TGConstant.Utils.GAME_BIZ, + game_uid: Number(gameUid), + region: TGUtils.Tools.getServerByUid(gameUid), + }; + const header = TGUtils.User.getHeader(cookie, "POST", JSON.stringify(data), "lk2", true); + return await http + .fetch(url, { + method: "POST", + headers: header, + body: http.Body.json(data), + }) + .then((res) => { + if (res.data.retcode === 0) return res.data.data.authkey; + return res.data; + }); +}