初步打通相关流程

This commit is contained in:
BTMuli
2023-09-04 01:12:19 +08:00
parent 4f6f065645
commit bda4966ae5
11 changed files with 257 additions and 185 deletions

View File

@@ -2,12 +2,12 @@
* @file web request TGRequest.ts
* @description 应用用到的请求函数
* @author BTMuli <bt-muli@outlook.com>
* @since Alpha v0.2.3
* @since Beta v0.3.0
*/
import { getAbyss } from "./getAbyss";
import { getAnnoList, getAnnoContent } from "./getAnno";
import { getCookieTokenBySToken } from "./getCookieToken";
import { getCookieTokenByGameToken, getCookieTokenBySToken } from "./getCookieToken";
// import * from "./getEnkaData.ts";
import { getGameAccountsBySToken, getGameAccountsByCookie } from "./getGameAccounts";
import { getGameRecord } from "./getGameRecord";
@@ -15,12 +15,10 @@ import { getLTokenBySToken } from "./getLToken";
import { getGameRoleListByLToken } from "./getRoleList";
import getSyncAvatarDetail from "./getSyncAvatarDetail";
import getSyncAvatarListAll from "./getSyncAvatarListAll";
// import * from "./getTickets.ts";
import { getTokensByLoginTicket } from "./getTokens";
import { getUserInfoByCookie } from "./getUserInfo";
// import * from "./getUserCard";
import initCookie from "./initCookie";
import { verifyLToken } from "./verifyLToken";
import { getStokenByGameToken } from "./getStoken";
const TGRequest = {
Anno: {
@@ -28,7 +26,6 @@ const TGRequest = {
getContent: getAnnoContent,
},
User: {
init: initCookie,
getRecord: getGameRecord,
byLoginTicket: {
getTokens: getTokensByLoginTicket,
@@ -47,6 +44,10 @@ const TGRequest = {
getCookieToken: getCookieTokenBySToken,
getLToken: getLTokenBySToken,
},
bgGameToken: {
getCookieToken: getCookieTokenByGameToken,
getStoken: getStokenByGameToken,
},
calculate: {
getSyncAvatarListAll,
getSyncAvatarDetail,

View File

@@ -54,10 +54,10 @@ export async function getCookieTokenByGameToken(
gameToken: string,
): Promise<string | TGApp.BBS.Response.Base> {
const url = "https://api-takumi.mihoyo.com/auth/api/getCookieAccountInfoByGameToken";
const data = { account_id: accountId, game_token: gameToken };
const data = { account_id: Number(accountId), game_token: gameToken };
return await http
.fetch<TGApp.BBS.Response.getCookieTokenByGameToken>(url, {
method: "GET",
method: "POST",
body: http.Body.json(data),
})
.then((res) => {

View File

@@ -15,19 +15,20 @@ import TGUtils from "../utils/TGUtils";
/**
* @description 根据 stoken 获取 ltoken
* @since Alpha v0.1.5
* @param {string} stuid 登录用户 uid
* @param {string} stoken stoken
* @param {string} mid 登录用户 mid
* @param {string} stoken stoken_v2
* @returns {Promise<string|TGApp.BBS.Response.Base>}
*/
export async function getLTokenBySToken(
stuid: string,
mid: string,
stoken: string,
): Promise<string | TGApp.BBS.Response.Base> {
const url = TGApi.GameTokens.getLToken;
const cookie = {
stuid,
mid,
stoken,
};
console.log(cookie);
const params = { stoken };
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
return await http

View File

@@ -22,7 +22,7 @@ export async function getStokenByGameToken(
gameToken: string,
): Promise<TGApp.BBS.Response.getStokenByGameTokenData | TGApp.BBS.Response.Base> {
const url = "https://api-takumi.mihoyo.com/account/ma-cn-session/app/getTokenByGameToken";
const data = { account_id: accountId, game_token: gameToken };
const data = { account_id: Number(accountId), game_token: gameToken };
const header = {
"x-rpc-app_id": TGConstant.BBS.APP_ID,
};

View File

@@ -1,50 +0,0 @@
/**
* @file web request initCookie.ts
* @description 首次输入 cookie 后的一系列请求
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.5
*/
// utils
import TGSqlite from "../../plugins/Sqlite";
// request
import { getCookieTokenBySToken } from "./getCookieToken";
import { getTokensByLoginTicket } from "./getTokens";
import { verifyLToken } from "./verifyLToken";
/**
* @description 根据输入 cookie 获取一堆 token
* @since Alpha v0.1.5
* @param {string} ticket login_ticket
* @param {string} uid login_uid
* @returns {Promise<void>}
*/
async function initCookie(ticket: string, uid: string): Promise<void> {
const tokenRes = await getTokensByLoginTicket(ticket, uid);
const cookie: TGApp.BBS.Constant.Cookie = {
account_id: uid,
cookie_token: "",
login_ticket: ticket,
mid: "",
login_uid: uid,
ltoken: "",
ltuid: uid,
stoken: "",
stuid: uid,
};
if (Array.isArray(tokenRes)) {
const lToken = tokenRes.find((item) => item.name === "ltoken");
const sToken = tokenRes.find((item) => item.name === "stoken");
if (lToken != null) cookie.ltoken = lToken.token;
if (sToken != null) cookie.stoken = sToken.token;
const cookieToken = await getCookieTokenBySToken(uid, cookie.stoken);
if (typeof cookieToken === "string") cookie.cookie_token = cookieToken;
const mid = await verifyLToken(cookie.ltoken, cookie.ltuid);
if (typeof mid === "string") cookie.mid = mid;
await TGSqlite.saveAppData("cookie", JSON.stringify(cookie));
} else {
throw new Error("获取 token 失败");
}
}
export default initCookie;