diff --git a/src/types/BBS/Account.d.ts b/src/types/BBS/Account.d.ts index 290a8cac..fb58d227 100644 --- a/src/types/BBS/Account.d.ts +++ b/src/types/BBS/Account.d.ts @@ -2,7 +2,7 @@ * @file types BBS Account.d.ts * @description BBS 账户相关类型定义文件 * @author BTMuli - * @since Alpha v0.1.5 + * @since Beta v0.3.0 */ declare namespace TGApp.BBS.Account { @@ -41,4 +41,45 @@ declare namespace TGApp.BBS.Account { rebind_mobile_time: string; links: unknown[]; } + + /** + * @description 通过 gameToken 获取 stoken 返回的用户信息 + * @interface getStokenByGameTokenInfo + * @since Beta v0.3.0 + * @property {string} aid 账号 id + * @property {string} mid mid + * @property {string} account_name 账号名称 + * @property {string} email 邮箱 + * @property {number} is_email_verify 是否验证邮箱 // 0 未验证 1 已验证 + * @property {string} area_code 手机区号 // '+86' + * @property {string} mobile 手机号 // 部分明文,中间隐藏 + * @property {string} safe_area_code 安全手机区号 + * @property {string} safe_mobile 安全手机号 + * @property {string} realname 真实姓名 // 最后一位明文,其他隐藏 + * @property {string} identity_code 身份证号 // 头尾三位明文,其他隐藏 + * @property {string} rebind_area_code 重新绑定手机区号 + * @property {string} rebind_mobile 重新绑定手机号 + * @property {string} rebind_mobile_time 重新绑定手机时间 + * @property {unknown[]} links 账号绑定信息 + * @property {string} country 国家 + * @return getStokenByGameTokenInfo + */ + export interface getStokenByGameTokenInfo { + aid: string; + mid: string; + account_name: string; + email: string; + is_email_verify: number; + area_code: string; + mobile: string; + safe_area_code: string; + safe_mobile: string; + realname: string; + identity_code: string; + rebind_area_code: string; + rebind_mobile: string; + rebind_mobile_time: string; + links: unknown[]; + country: string; + } } diff --git a/src/types/BBS/Response.d.ts b/src/types/BBS/Response.d.ts index 542892b7..0c7c8d15 100644 --- a/src/types/BBS/Response.d.ts +++ b/src/types/BBS/Response.d.ts @@ -2,8 +2,8 @@ * @file types BBS Tokens.d.ts * @description BBS 返回数据类型定义文件 * @todo 视情况看看要不要拆分 - * @author BTMuli - * @since Alpha v0.1.5 + * @author BTMuli< bt-muli@outlook.com> + * @since Beta v0.3.0 */ declare namespace TGApp.BBS.Response { @@ -100,4 +100,53 @@ declare namespace TGApp.BBS.Response { need_realperson: boolean; }; } + + /** + * @description 通过 gameToken 获取 stoken 的返回类型 + * @interface getStokenByGameToken + * @since Beta v0.3.0 + * @extends Base + * @property {getStokenByGameTokenData} data - 返回数据 + * @return getStokenByGameToken + */ + export interface getStokenByGameToken extends Base { + data: getStokenByGameTokenData; + } + + /** + * @description 通过 gameToken 获取 stoken 的返回类型数据 + * @interface getStokenByGameTokenData + * @since Beta v0.3.0 + * @property {number} token.token_type - token 类型 + * @property {string} token.token - token 值 + * @property {TGApp.BBS.Account.getStokenByGameTokenInfo} user_info - 用户信息 + * @property {unknown} realname_info - 实名信息 // todo: 未知类型 + * @property {boolean} need_realperson - 是否需要实名认证 + * @return getStokenByGameToken + */ + export interface getStokenByGameTokenData { + token: { + token_type: number; + token: string; + }; + user_info: TGApp.BBS.Account.getStokenByGameTokenInfo; + realname_info: unknown; + need_realperson: boolean; + } + + /** + * @description 通过 gameToken 获取 cookie_token 的返回类型 + * @interface getCookieTokenByGameToken + * @since Beta v0.3.0 + * @extends Base + * @property {string} data.uid - 用户 uid + * @property {string} data.cookie_token - cookie_token 值 + * @return getCookieTokenByGameToken + */ + export interface getCookieTokenByGameToken extends Base { + data: { + uid: string; + cookie_token: string; + }; + } } diff --git a/src/web/constant/TGConstant.ts b/src/web/constant/TGConstant.ts index 1602074a..1f7a8d85 100644 --- a/src/web/constant/TGConstant.ts +++ b/src/web/constant/TGConstant.ts @@ -1,11 +1,11 @@ /** * @file web constant TGConstant.ts * @description 常量 - * @author BTMuli - * @since Alpha v0.2.0 + * @author BTMuli + * @since Beta v0.3.0 */ -import { BBS_VERSION, BBS_HEADER_AGENT } from "./bbs"; +import { BBS_VERSION, BBS_HEADER_AGENT, BBS_APP_ID } from "./bbs"; import SALT from "./salt"; import SERVER from "./server"; import { GAME_BIZ } from "./utils"; @@ -14,6 +14,7 @@ const TGConstant = { BBS: { VERSION: BBS_VERSION, USER_AGENT: BBS_HEADER_AGENT, + APP_ID: BBS_APP_ID, }, Salt: SALT, Server: SERVER, diff --git a/src/web/constant/bbs.ts b/src/web/constant/bbs.ts index a80217ee..05792fbe 100644 --- a/src/web/constant/bbs.ts +++ b/src/web/constant/bbs.ts @@ -1,9 +1,10 @@ /** * @file web constant bbs.ts * @description 常量-应用数据 - * @author BTMuli - * @since Alpha v0.2.0 + * @author BTMuli + * @since Beta v0.3.0 */ export const BBS_VERSION = "2.50.1"; export const BBS_HEADER_AGENT = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) miHoYoBBS/${BBS_VERSION}`; +export const BBS_APP_ID = "bll8iq97cem8"; diff --git a/src/web/request/getCookieToken.ts b/src/web/request/getCookieToken.ts index 405c44f8..e8d49d36 100644 --- a/src/web/request/getCookieToken.ts +++ b/src/web/request/getCookieToken.ts @@ -2,7 +2,7 @@ * @file web request getCookieToken.ts * @description 获取 Cookie Token 的请求函数 * @author BTMuli - * @since Alpha v0.1.5 + * @since Beta v0.3.0 */ // tauri @@ -41,3 +41,27 @@ export async function getCookieTokenBySToken( return res.data.data.cookie_token; }); } + +/** + * @description 根据 gameToken 获取 cookie_token + * @since Beta v0.3.0 + * @param {string} accountId 账号 id + * @param {string} gameToken gameToken + * @returns {Promise} + */ +export async function getCookieTokenByGameToken( + accountId: string, + gameToken: string, +): Promise { + const url = "https://api-takumi.mihoyo.com/auth/api/getCookieAccountInfoByGameToken"; + const data = { account_id: accountId, game_token: gameToken }; + return await http + .fetch(url, { + method: "GET", + body: http.Body.json(data), + }) + .then((res) => { + if (res.data.retcode !== 0) return res.data; + return res.data.data.cookie_token; + }); +} diff --git a/src/web/request/getStoken.ts b/src/web/request/getStoken.ts new file mode 100644 index 00000000..20f79515 --- /dev/null +++ b/src/web/request/getStoken.ts @@ -0,0 +1,39 @@ +/** + * @file web request getStoken.ts + * @description 获取 stoken + * @author BTMuli + * @since Beta v0.3.0 + */ + +// tauri +import { http } from "@tauri-apps/api"; +// constant +import TGConstant from "../constant/TGConstant"; + +/** + * @description 获取 stoken + * @since Beta v0.3.0 + * @param {string} accountId 账户 ID + * @param {string} gameToken 游戏 Token + * @returns {Promise} + */ +export async function getStokenByGameToken( + accountId: string, + gameToken: string, +): Promise { + const url = "https://api-takumi.mihoyo.com/account/ma-cn-session/app/getTokenByGameToken"; + const data = { account_id: accountId, game_token: gameToken }; + const header = { + "x-rpc-app_id": TGConstant.BBS.APP_ID, + }; + return await http + .fetch(url, { + method: "POST", + headers: header, + body: http.Body.json(data), + }) + .then((res) => { + if (res.data.retcode !== 0) return res.data; + return res.data.data; + }); +}