🌱 comboToken登录

This commit is contained in:
目棃
2025-02-26 11:31:15 +08:00
parent c25bde1b7a
commit 70216734a3
7 changed files with 263 additions and 16 deletions

View File

@@ -1,10 +1,11 @@
/**
* @file web/request/hk4eReq.ts
* @description Hk4eApi 请求模块
* @since Beta v0.6.3
* @since Beta v0.7.0
*/
import TGHttp from "@/utils/TGHttp.js";
import { getDeviceInfo } from "@/utils/toolFunc.js";
export enum AnnoServer {
CN_ISLAND = "cn_gf01",
@@ -20,6 +21,7 @@ export type AnnoLang = "zh-cn" | "zh-tw" | "en" | "ja";
const AnnoApi: Readonly<string> = "https://hk4e-ann-api.mihoyo.com/common/hk4e_cn/announcement/api";
const AnnoApiGlobal: Readonly<string> =
"https://sg-hk4e-api.hoyoverse.com/common/hk4e_global/announcement/api";
const SdkApi: Readonly<string> = "https://hk4e-sdk.mihoyo.com/hk4e_cn/";
/**
* @description 判断是否为国内服务器
@@ -137,9 +139,48 @@ async function getGachaLog(
return resp.data.list;
}
/**
* @description 获取登录二维码
* @since Beta v0.7.0
* @param {string} appId 应用 ID // 目前只有2/7能用
* @returns {Promise<TGApp.Game.Login.QrRes|TGApp.BBS.Response.Base>}
*/
async function fetchPandaQr(
appId: string = "2",
): Promise<TGApp.Game.Login.QrRes | TGApp.BBS.Response.Base> {
const data = { app_id: appId, device: getDeviceInfo("device_id") };
const resp = await TGHttp<TGApp.Game.Login.QrResp>(`${SdkApi}combo/panda/qrcode/fetch`, {
method: "POST",
body: JSON.stringify(data),
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data;
}
/**
* @description 获取登录状态
* @since Beta v0.7.0
* @param {string} ticket 二维码 ticket
* @param {string} appId 应用 ID
* @returns {Promise<TGApp.BBS.Response.Base|TGApp.Game.Login.StatusRes>}
*/
async function queryPandaQr(
ticket: string,
appId: string = "2",
): Promise<TGApp.BBS.Response.Base | TGApp.Game.Login.StatusRes> {
const data = { app_id: appId, ticket, device: getDeviceInfo("device_id") };
const resp = await TGHttp<TGApp.Game.Login.StatusResp>(`${SdkApi}combo/panda/qrcode/query`, {
method: "POST",
body: JSON.stringify(data),
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data;
}
const Hk4eApi = {
anno: { list: getAnnoList, content: getAnnoContent },
gacha: getGachaLog,
loginQr: { create: fetchPandaQr, state: queryPandaQr },
};
export default Hk4eApi;

View File

@@ -3,12 +3,58 @@
* @description Takumi 相关请求函数
* @since Beta v0.7.0
*/
import TGBbs from "@/utils/TGBbs.js";
import TGHttp from "@/utils/TGHttp.js";
import { getRequestHeader } from "@/web/utils/getRequestHeader.js";
import { getDeviceInfo } from "@/utils/toolFunc.js";
import { getDS, getRequestHeader } from "@/web/utils/getRequestHeader.js";
// TakumiApiBaseUrl => taBu
const taBu: Readonly<string> = "https://api-takumi.mihoyo.com/";
/**
* @description 根据gameToken获取stoken
* @todo -100
* @param {TGApp.Game.Login.StatusPayloadRaw} raw 状态数据
* @returns {Promise<TGApp.BBS.Response.Base|string>}
*/
async function getSTokenByGameToken(
raw: TGApp.Game.Login.StatusPayloadRaw,
): Promise<TGApp.BBS.Response.Base> {
const data = { account_id: raw.uid, game_token: raw.token };
// const header = {
// ...getRequestHeader(ck, "POST", JSON.stringify(data), "X6"),
// "x-rpc-client_type": "4",
// "x-rpc-app_id": "bll8iq97cem8",
// "x-rpc-game_biz": "bbs_cn",
// };
const header = {
"x-rpc-app_version": TGBbs.version,
"x-rpc-aigis": "",
"Content-Type": "application/json",
"x-rpc-game_biz": "bbs_cn",
"x-rpc-sys_version": "12",
"x-rpc-device_id": getDeviceInfo("device_id"),
"x-rpc-device_name": getDeviceInfo("device_name"),
"x-rpc-device_model": getDeviceInfo("product"),
"x-rpc-app_id": "bll8iq97cem8",
"x-rpc-client_type": "4",
"User-Agent": "okhttp/4.9.3",
ds: getDS("POST", JSON.stringify(data), "X6", false),
cookie: `account_id=${raw.uid};ltuid=${raw.uid};stuid=${raw.uid};game_token=${raw.token};`,
};
const resp = await TGHttp<TGApp.BBS.Response.Base>(
`${taBu}account/ma-cn-session/app/getTokenByGameToken`,
{
method: "POST",
headers: header,
body: JSON.stringify(data),
},
);
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
console.log(resp);
return resp;
}
/**
* @description 根据stoken获取action_ticket
* @since Beta v0.6.3
@@ -102,6 +148,7 @@ async function getUserGameRolesByCookie(
const TakumiApi = {
auth: { actionTicket: getActionTicketBySToken },
bind: { authKey: genAuthKey, authKey2: genAuthKey2, gameRoles: getUserGameRolesByCookie },
game: { stoken: getSTokenByGameToken },
};
export default TakumiApi;

View File

@@ -57,7 +57,7 @@ function getRandomNumber(min: number, max: number): number {
* @param {boolean} isSign 是否为签名
* @returns {string} ds
*/
function getDS(
export function getDS(
method: string,
data: string,
saltType: keyof typeof SaltType,