完成扫码获取 gameToken

This commit is contained in:
BTMuli
2023-09-03 16:07:30 +08:00
parent 3cac2057f8
commit 3a7ca20b14
5 changed files with 323 additions and 7 deletions

90
src/plugins/Mys/types/GameLogin.d.ts vendored Normal file
View File

@@ -0,0 +1,90 @@
/**
* @file plugins Mys types GameLogin.d.ts
* @description Mys 插件 Game 登录类型定义文件
* @author BTMuli <bt-muli@outlook.com>
* @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;
}
}

View File

@@ -0,0 +1,58 @@
/**
* @file plugins Mys utils doGameLogin
* @description 获取 gameToken曲线获取 stoken
* @author BTMuli <bt-muli@outlook.com>
* @since Beta v0.3.0
*/
// tauri
import { http } from "@tauri-apps/api";
const device = crypto.randomUUID();
/**
* @description 获取登录二维码
* @since Beta v0.3.0
* @returns {Promise<TGApp.Plugins.Mys.GameLogin.GetLoginQrData|TGApp.Plugins.Mys.Base.Response>}
*/
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<TGApp.Plugins.Mys.GameLogin.GetLoginQrResponse>(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<TGApp.Plugins.Mys.GameLogin.GetLoginStatusData | TGApp.Plugins.Mys.Base.Response>}
*/
export async function getLoginStatus(
ticket: string,
): Promise<TGApp.Plugins.Mys.GameLogin.GetLoginStatusData | TGApp.Plugins.Mys.Base.Response> {
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<TGApp.Plugins.Mys.GameLogin.GetLoginStatusResponse>(url, {
method: "POST",
body: http.Body.json(data),
})
.then((res) => {
if (res.data.retcode === 0) return res.data.data;
return res.data;
});
}