From 3a7ca20b145d70fb5ead0f31a84e2be38f25fb50 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Sun, 3 Sep 2023 16:07:30 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=AE=8C=E6=88=90=E6=89=AB?= =?UTF-8?q?=E7=A0=81=E8=8E=B7=E5=8F=96=20gameToken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/tauri.conf.json | 1 + src/components/overlay/to-gameLogin.vue | 166 ++++++++++++++++++++++++ src/plugins/Mys/types/GameLogin.d.ts | 90 +++++++++++++ src/plugins/Mys/utils/doGameLogin.ts | 58 +++++++++ src/store/modules/user.ts | 15 ++- 5 files changed, 323 insertions(+), 7 deletions(-) create mode 100644 src/components/overlay/to-gameLogin.vue create mode 100644 src/plugins/Mys/types/GameLogin.d.ts create mode 100644 src/plugins/Mys/utils/doGameLogin.ts diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 6db1ef04..87f88d34 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -28,6 +28,7 @@ "https://bbs-api.miyoushe.com/*", "https://bbs.mihoyo.com/*", "https://hk4e-api.mihoyo.com/*", + "https://hk4e-sdk.mihoyo.com/*", "https://passport-api.mihoyo.com/*", "https://passport-api.miyoushe.com/*", "https://passport-api-v4.mihoyo.com/*", diff --git a/src/components/overlay/to-gameLogin.vue b/src/components/overlay/to-gameLogin.vue new file mode 100644 index 00000000..bfb9d7c7 --- /dev/null +++ b/src/components/overlay/to-gameLogin.vue @@ -0,0 +1,166 @@ + + + diff --git a/src/plugins/Mys/types/GameLogin.d.ts b/src/plugins/Mys/types/GameLogin.d.ts new file mode 100644 index 00000000..00edd38a --- /dev/null +++ b/src/plugins/Mys/types/GameLogin.d.ts @@ -0,0 +1,90 @@ +/** + * @file plugins Mys types GameLogin.d.ts + * @description Mys 插件 Game 登录类型定义文件 + * @author BTMuli + * @since Beta v0.3.0 + */ + +/** + * @description Mys 插件 Game 登录类型 + * @since Beta v0.3.0 + * @namespace GameLogin + * @return GameLogin + */ +declare namespace TGApp.Plugins.Mys.GameLogin { + /** + * @description 获取登录二维码返回数据 + * @since Beta v0.3.0 + * @interface GetLoginQrResponse + * @extends TGApp.Plugins.Mys.Base.Response + * @property {GetLoginQrData} data 数据 + * @return GetLoginQrResponse + */ + export interface GetLoginQrResponse extends TGApp.Plugins.Mys.Base.Response { + data: GetLoginQrData; + } + + /** + * @description 获取登录二维码返回数据 + * @since Beta v0.3.0 + * @interface GetLoginQrData + * @property {string} url 二维码链接 + * @return GetLoginQrData + */ + export interface GetLoginQrData { + url: string; + } + + /** + * @description 获取登录状态返回数据 + * @since Beta v0.3.0 + * @interface GetLoginStatusResponse + * @extends TGApp.Plugins.Mys.Base.Response + * @property {GetLoginStatusData} data 数据 + * @return GetLoginStatusResponse + */ + export interface GetLoginStatusResponse extends TGApp.Plugins.Mys.Base.Response { + data: GetLoginStatusData; + } + + /** + * @description 获取登录状态返回数据 + * @since Beta v0.3.0 + * @interface GetLoginStatusData + * @property {string} stat 状态 // Init: 未扫码,Scanned: 已扫码,Confirmed: 已确认 + * @property {StatusPayload} payload 状态数据 + * @return GetLoginStatusData + */ + export interface GetLoginStatusData { + stat: string; + payload: StatusPayload; + } + + /** + * @description 获取登录状态返回数据 + * @since Beta v0.3.0 + * @interface StatusPayload + * @property {string} ext 未知 + * @property {string} proto 未知 + * @property {string} raw 序列化数据,反序列化后是 {uid: string, token: string} + * @return StatusPayload + */ + export interface StatusPayload { + ext: string; + proto: string; + raw: string; + } + + /** + * @description 反序列化后的登录状态数据 + * @since Beta v0.3.0 + * @interface StatusPayloadRaw + * @property {string} uid 用户 UID + * @property {string} token 用户 token + * @return StatusPayloadRaw + */ + export interface StatusPayloadRaw { + uid: string; + token: string; + } +} diff --git a/src/plugins/Mys/utils/doGameLogin.ts b/src/plugins/Mys/utils/doGameLogin.ts new file mode 100644 index 00000000..b3020279 --- /dev/null +++ b/src/plugins/Mys/utils/doGameLogin.ts @@ -0,0 +1,58 @@ +/** + * @file plugins Mys utils doGameLogin + * @description 获取 gameToken,曲线获取 stoken + * @author BTMuli + * @since Beta v0.3.0 + */ + +// tauri +import { http } from "@tauri-apps/api"; + +const device = crypto.randomUUID(); + +/** + * @description 获取登录二维码 + * @since Beta v0.3.0 + * @returns {Promise} + */ +export async function getLoginQr(): Promise< + TGApp.Plugins.Mys.GameLogin.GetLoginQrData | TGApp.Plugins.Mys.Base.Response +> { + const url = "https://hk4e-sdk.mihoyo.com/hk4e_cn/combo/panda/qrcode/fetch"; + const data = { + app_id: "4", + device, + }; + return await http + .fetch(url, { + method: "POST", + body: http.Body.json(data), + }) + .then((res) => { + if (res.data.retcode === 0) return res.data.data; + return res.data; + }); +} + +/** + * @description 获取登录状态 + * @since Beta v0.3.0 + * @param {string} ticket 二维码 ticket + * @returns {Promise} + */ +export async function getLoginStatus( + ticket: string, +): Promise { + const url = "https://hk4e-sdk.mihoyo.com/hk4e_cn/combo/panda/qrcode/query"; + const data = { app_id: "4", device, ticket }; + console.log(data); + return await http + .fetch(url, { + method: "POST", + body: http.Body.json(data), + }) + .then((res) => { + if (res.data.retcode === 0) return res.data.data; + return res.data; + }); +} diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 2e9d86ce..2316db94 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -1,14 +1,16 @@ /** * @file store modules user.ts * @description User store module - * @author BTMuli - * @since Alpha v0.2.0 + * @author BTMuli + * @since Beta v0.3.0 */ // vue import { ref } from "vue"; // pinia import { defineStore } from "pinia"; +// sqlite +import TGSqlite from "../../plugins/Sqlite"; export const useUserStore = defineStore( "user", @@ -81,10 +83,9 @@ export const useUserStore = defineStore( }; } - function initCookie(ck: Record): void { - if (cookie.value !== ck) { - cookie.value = ck; - } + async function saveCookie(type: string, val: string): Promise { + cookie.value[type] = val; + await TGSqlite.saveAppData("cookie", JSON.stringify(cookie.value)); } return { @@ -100,7 +101,7 @@ export const useUserStore = defineStore( getCookieGroup2, getCookieGroup3, getCookieGroup4, - initCookie, + saveCookie, }; }, {