diff --git a/src/utils/TGClient.ts b/src/utils/TGClient.ts index 26f728c9..25d94323 100644 --- a/src/utils/TGClient.ts +++ b/src/utils/TGClient.ts @@ -211,6 +211,9 @@ class TGClient { case "getStatusBarHeight": await this.getStatusBarHeight(callback); break; + case "genAuthKey": + await this.genAuthKey(payload, callback); + break; case "getCookieInfo": await this.getCookieInfo(payload, callback); break; @@ -249,6 +252,13 @@ class TGClient { case "share": await this.share(payload, callback); break; + case "share2": + await this.nullCallback(arg); + break; + // 监听滚动事件? payload:{direction: 0|1} 0:向上滚动 1:向下滚动 + case "onBeginDragging": + await this.nullCallback(arg); + break; // getNotificationSettings default: console.warn(`[${arg.windowLabel}] ${arg.payload}`); @@ -289,6 +299,24 @@ class TGClient { await this.callback(callback, data); } + /** + * @func genAuthKey + * @since Beta v0.3.7 + * @desc 获取米游社客户端的 authkey + * @param {Record} payload - 请求参数 + * @param {string} callback - 回调函数名 + * @returns {void} - 无返回值 + */ + async genAuthKey(payload: Record, callback: string): Promise { + const userStore = useUserStore(); + const cookie = { + mid: userStore.cookie.mid, + stoken: userStore.cookie.stoken, + }; + const res = await TGRequest.User.getAuthkey2(cookie, payload); + await this.callback(callback, res.data); + } + /** * @func getCookieInfo * @since Beta v0.3.4 diff --git a/src/web/request/TGRequest.ts b/src/web/request/TGRequest.ts index 3739d9a7..eb839744 100644 --- a/src/web/request/TGRequest.ts +++ b/src/web/request/TGRequest.ts @@ -4,7 +4,7 @@ * @since Beta v0.3.6 */ -import { genAuthkey } from "./genAuthkey"; +import { genAuthkey, genAuthkey2 } from "./genAuthkey"; import { getAbyss } from "./getAbyss"; import { getActionTicketBySToken } from "./getActionTicket"; import { getAnnoContent, getAnnoList } from "./getAnno"; @@ -33,6 +33,7 @@ const TGRequest = { }, User: { getAuthkey: genAuthkey, + getAuthkey2: genAuthkey2, getGachaLog, getRecord: getGameRecord, byLoginTicket: { diff --git a/src/web/request/genAuthkey.ts b/src/web/request/genAuthkey.ts index 94b48b51..0b747f97 100644 --- a/src/web/request/genAuthkey.ts +++ b/src/web/request/genAuthkey.ts @@ -1,7 +1,7 @@ /** * @file web/request/genAuthkey.ts * @description 生成 authkey - * @since Beta v0.3.0 + * @since Beta v0.3.7 */ import { http } from "@tauri-apps/api"; @@ -39,3 +39,25 @@ export async function genAuthkey( return res.data; }); } + +/** + * @description 生成 authkey + * @since Beta v0.3.0 + * @param {Record} cookie cookie // stoken_v2 & mid + * @param {object} payload payload + * @returns {Promise} authkey + */ +export async function genAuthkey2( + cookie: Record, + payload: Record, +): Promise { + const url = "https://api-takumi.mihoyo.com/binding/api/genAuthKey"; + const header = TGUtils.User.getHeader(cookie, "POST", JSON.stringify(payload), "lk2", true); + return await http + .fetch(url, { + method: "POST", + headers: header, + body: http.Body.json(payload), + }) + .then((res) => res.data); +}