扫码登录

This commit is contained in:
目棃
2025-01-08 14:58:00 +08:00
parent f801363440
commit d5f40a5775
18 changed files with 1293 additions and 970 deletions

View File

@@ -1,12 +1,11 @@
/**
* @file plugins/Mys/index.ts
* @description Mys plugin index
* @since Beta v0.6.3
* @since Beta v0.6.8
*/
import * as ApiHub from "./request/apiHubReq.js";
import { doCaptchaLogin, getCaptcha } from "./request/doCaptchaLogin.js";
import { getLoginQr, getLoginStatus } from "./request/doGameLogin.js";
import { getGachaData, getPositionData } from "./request/obcReq.js";
import * as Painter from "./request/painterReq.js";
import * as Post from "./request/postReq.js";
@@ -21,7 +20,7 @@ const Mys = {
Gacha: { get: getGachaData, card: getGachaCard },
Position: { get: getPositionData, card: getPositionCard },
Lottery: { get: Painter.lotteryUserShow, card: getLotteryCard },
User: { getQr: getLoginQr, getData: getLoginStatus, getCaptcha, login: doCaptchaLogin },
User: { getCaptcha, login: doCaptchaLogin },
};
export default Mys;

View File

@@ -1,59 +0,0 @@
/**
* @file plugins/Mys/request/doGameLogin
* @description 获取 gameToken曲线获取 stoken
* @since Beta v0.5.0
*/
import TGHttp from "@/utils/TGHttp.js";
import { getDeviceInfo } from "@/utils/toolFunc.js";
import { getRequestHeader } from "@/web/utils/getRequestHeader.js";
const APP_ID = 8;
/**
* @description 获取登录二维码
* @since Beta v0.5.0
* @returns {Promise<TGApp.Plugins.Mys.GameLogin.GetLoginQrData|TGApp.BBS.Response.Base>}
*/
export async function getLoginQr(): Promise<
TGApp.Plugins.Mys.GameLogin.GetLoginQrData | TGApp.BBS.Response.Base
> {
const data: Record<string, string | number> = {
app_id: APP_ID,
device: getDeviceInfo("device_id"),
};
const resp = await TGHttp<
TGApp.Plugins.Mys.GameLogin.GetLoginQrResponse | TGApp.BBS.Response.Base
>("https://hk4e-sdk.mihoyo.com/hk4e_cn/combo/panda/qrcode/fetch", {
method: "POST",
headers: getRequestHeader({}, "POST", data),
body: JSON.stringify(data),
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data;
}
/**
* @description 获取登录状态
* @since Beta v0.5.0
* @param {string} ticket 二维码 ticket
* @returns {Promise<TGApp.Plugins.Mys.GameLogin.GetLoginStatusData | TGApp.BBS.Response.Base>}
*/
export async function getLoginStatus(
ticket: string,
): Promise<TGApp.Plugins.Mys.GameLogin.GetLoginStatusData | TGApp.BBS.Response.Base> {
const data: Record<string, string | number> = {
app_id: APP_ID,
device: getDeviceInfo("device_id"),
ticket,
};
const resp = await TGHttp<
TGApp.Plugins.Mys.GameLogin.GetLoginStatusResponse | TGApp.BBS.Response.Base
>("https://hk4e-sdk.mihoyo.com/hk4e_cn/combo/panda/qrcode/query", {
method: "POST",
headers: getRequestHeader({}, "POST", data),
body: JSON.stringify(data),
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data;
}

View File

@@ -1,102 +0,0 @@
/**
* @file plugins/Mys/types/GameLogin.d.ts
* @description Mys 插件 Game 登录类型定义文件
* @since Beta v0.4.4
*/
/**
* @description Mys 插件 Game 登录类型
* @since Beta v0.4.4
* @namespace TGApp.Plugins.Mys.GameLogin
* @memberof TGApp.Plugins.Mys
*/
declare namespace TGApp.Plugins.Mys.GameLogin {
/**
* @description 获取登录二维码返回数据
* @since Beta v0.3.0
* @interface GetLoginQrResponse
* @extends TGApp.BBS.Response.BaseWithData
* @property {GetLoginQrData} data 数据
* @return GetLoginQrResponse
*/
interface GetLoginQrResponse extends TGApp.BBS.Response.BaseWithData {
data: GetLoginQrData;
}
/**
* @description 获取登录二维码返回数据
* @since Beta v0.3.0
* @interface GetLoginQrData
* @property {string} url 二维码链接
* @return GetLoginQrData
*/
interface GetLoginQrData {
url: string;
}
/**
* @description 获取登录状态返回数据
* @since Beta v0.3.0
* @interface GetLoginStatusResponse
* @extends TGApp.BBS.Response.BaseWithData
* @property {GetLoginStatusData} data 数据
* @return GetLoginStatusResponse
*/
interface GetLoginStatusResponse extends TGApp.BBS.Response.BaseWithData {
data: GetLoginStatusData;
}
/**
* @description 获取登录状态返回数据
* @since Beta v0.3.0
* @interface GetLoginStatusData
* @property {string} stat 状态 // Init: 未扫码Scanned: 已扫码Confirmed: 已确认
* @property {StatusPayload} payload 状态数据
* @return GetLoginStatusData
*/
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
*/
interface StatusPayload {
ext: string;
proto: string;
raw: string;
}
/**
* @description 反序列化后的登录状态数据
* @since Beta v0.4.4
* @interface StatusPayloadRawOpen
* @property {string} uid 用户 UID
* @property {string} token 用户 token
* @return StatusPayloadRawOpen
*/
interface StatusPayloadRawOpen {
open_id: string;
open_token: string;
}
/**
* @description 反序列化后的登录状态数据
* @since Beta v0.4.4
* @interface StatusPayloadRawAccount
* @property {string} uid 用户 UID
* @property {string} token 用户 token
* @return StatusPayloadRawOpen
*/
interface StatusPayloadRawAccount {
uid: string;
token: string;
}
}