实装 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

@@ -51,13 +51,6 @@ export const useUserStore = defineStore(
return cookie.value[key] || "";
}
function getCookieGroup1(): TGApp.BBS.Constant.CookieGroup1 {
return {
login_ticket: getCookieItem("login_ticket"),
login_uid: getCookieItem("login_uid"),
};
}
function getCookieGroup2(): TGApp.BBS.Constant.CookieGroup2 {
return {
account_id: getCookieItem("account_id"),
@@ -89,7 +82,6 @@ export const useUserStore = defineStore(
setBriefInfo,
setCurAccount,
getCurAccount,
getCookieGroup1,
getCookieGroup2,
getCookieGroup3,
getCookieGroup4,

26
src/types/Game/Gacha.d.ts vendored Normal file
View File

@@ -0,0 +1,26 @@
/**
* @file types Game Gacha.d.ts
* @description 游戏抽卡相关类型定义文件
* @author BTMuli<bt-muli@outlook.com>
* @since Beta v0.3.0
*/
declare namespace TGApp.Game.Gacha {
/**
* @description 获取 authkey 返回类型
* @interface AuthkeyResponse
* @since Beta v0.3.0
* @extends TGApp.BBS.Response.Base
* @property {number} data.sign_type - 签名类型
* @property {number} data.authkey_ver - authkey 版本
* @property {string} data.authkey - authkey
* @return AuthkeyResponse
*/
export interface AuthkeyResponse extends TGApp.BBS.Response.Base {
data: {
sign_type: number;
authkey_ver: number;
authkey: string;
};
}
}

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;
});
}