/** * @file web/request/genAuthkey.ts * @description 生成 authkey * @since Beta v0.6.2 */ import TGHttp from "../../utils/TGHttp.js"; import TGConstant from "../constant/TGConstant.js"; import TGUtils from "../utils/TGUtils.js"; /** * @description 生成 authkey * @since Beta v0.6.2 * @param {TGApp.App.Account.Cookie} cookie cookie * @param {TGApp.Sqlite.Account.Game} account 账户 * @returns {Promise} authkey */ export async function genAuthkey( cookie: TGApp.App.Account.Cookie, account: TGApp.Sqlite.Account.Game, ): Promise { const url = "https://api-takumi.mihoyo.com/binding/api/genAuthKey"; const ck = { stoken: cookie.stoken, mid: cookie.mid }; const data = { auth_appid: "webview_gacha", game_biz: TGConstant.Utils.GAME_BIZ, game_uid: account.gameUid, region: account.region, }; const header = TGUtils.User.getHeader(ck, "POST", JSON.stringify(data), "lk2", true); const resp = await TGHttp(url, { method: "POST", headers: header, body: JSON.stringify(data), }); if (resp.retcode !== 0) return resp; return resp.data.authkey; } /** * @description 生成 authkey * @since Beta v0.5.0 * @param {Record} cookie cookie // stoken_v2 & mid * @param {object} payload payload * @returns {Promise} authkey */ export async function genAuthkey2( cookie: Record, payload: Record, ): Promise { const url = "https://api-takumi.mihoyo.com/binding/api/genAuthKey"; const header = TGUtils.User.getHeader(cookie, "POST", JSON.stringify(payload), "lk2", true); return await TGHttp(url, { method: "POST", headers: header, body: JSON.stringify(payload), }); }