实装 authKey 获取

This commit is contained in:
BTMuli
2023-09-04 14:54:05 +08:00
parent 4b80de3f24
commit 4fef4d94e1
4 changed files with 71 additions and 8 deletions

View File

@@ -5,6 +5,7 @@
* @since Beta v0.3.0
*/
import { genAuthkey } from "./genAuthkey";
import { getAbyss } from "./getAbyss";
import { getAnnoList, getAnnoContent } from "./getAnno";
import { getCookieTokenByGameToken, getCookieTokenBySToken } from "./getCookieToken";
@@ -26,6 +27,7 @@ const TGRequest = {
getContent: getAnnoContent,
},
User: {
getAuthkey: genAuthkey,
getRecord: getGameRecord,
byLoginTicket: {
getTokens: getTokensByLoginTicket,

View File

@@ -0,0 +1,43 @@
/**
* @file web request genAuthkey.ts
* @description 生成 authkey
* @author BTMuli <bt-muli@outlook.com>
* @since Beta v0.3.0
*/
// tauri
import { http } from "@tauri-apps/api";
// utils
import TGUtils from "../utils/TGUtils";
import TGConstant from "../constant/TGConstant";
/**
* @description 生成 authkey
* @since Beta v0.3.0
* @param {Record<string, string>} cookie cookie // stoken_v2 & mid
* @param {string} gameUid 游戏 uid
* @returns {Promise<string|TGApp.BBS.Response.Base>} authkey
*/
export async function genAuthkey(
cookie: Record<string, string>,
gameUid: string,
): Promise<string | TGApp.BBS.Response.Base> {
const url = "https://api-takumi.mihoyo.com/binding/api/genAuthKey";
const data = {
auth_appid: "webview_gacha",
game_biz: TGConstant.Utils.GAME_BIZ,
game_uid: Number(gameUid),
region: TGUtils.Tools.getServerByUid(gameUid),
};
const header = TGUtils.User.getHeader(cookie, "POST", JSON.stringify(data), "lk2", true);
return await http
.fetch<TGApp.Game.Gacha.AuthkeyResponse>(url, {
method: "POST",
headers: header,
body: http.Body.json(data),
})
.then((res) => {
if (res.data.retcode === 0) return res.data.data.authkey;
return res.data;
});
}