From a59085eaa8efb9cf8fe7b026fc2a695f0bb03fcb Mon Sep 17 00:00:00 2001 From: BTMuli Date: Tue, 14 Apr 2026 22:51:58 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E8=BF=81=E7=A7=BBtakumiRe?= =?UTF-8?q?q?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/app/t-sidebar.vue | 42 +++++++--- src/components/pageAnno/tao-iframe.vue | 24 ++++-- src/components/pageConfig/tc-userBadge.vue | 71 +++++++++++----- src/components/pageConfig/tco-gameLogin.vue | 24 ++++-- src/components/pageHome/ph-comp-pool.vue | 27 +++++-- src/components/userScripts/tus-sign.vue | 34 +++++--- src/pages/User/Gacha.vue | 31 ++++--- src/pages/User/GachaB.vue | 32 +++++--- src/request/takumiReq.ts | 89 +++++++++------------ src/types/BBS/Auth.d.ts | 40 +++++++++ src/utils/TGClient.ts | 51 +++++++++--- 11 files changed, 325 insertions(+), 140 deletions(-) create mode 100644 src/types/BBS/Auth.d.ts diff --git a/src/components/app/t-sidebar.vue b/src/components/app/t-sidebar.vue index 1a75a440..1936a611 100644 --- a/src/components/app/t-sidebar.vue +++ b/src/components/app/t-sidebar.vue @@ -332,6 +332,7 @@ import { invoke } from "@tauri-apps/api/core"; import type { Event, UnlistenFn } from "@tauri-apps/api/event"; import { readDir } from "@tauri-apps/plugin-fs"; import mhyClient from "@utils/TGClient.js"; +import TGHttps from "@utils/TGHttps.js"; import TGLogger from "@utils/TGLogger.js"; import { storeToRefs } from "pinia"; import { computed, onMounted, onUnmounted, ref, shallowRef } from "vue"; @@ -466,16 +467,27 @@ async function tryGetTokens(ck: TGApp.App.Account.Cookie): Promise { cookie.value = ck; isLogin.value = true; await showLoading.update("正在获取游戏账号"); - const gameRes = await takumiReq.bind.gameRoles(cookie.value); - if (!Array.isArray(gameRes)) { + let gameRes: TGApp.BBS.Game.AccountResp | undefined; + try { + gameRes = await takumiReq.bind.gameRoles(cookie.value); + if (gameRes.retcode !== 0) { + await showLoading.end(); + showSnackbar.error(`[${gameRes.retcode}] ${gameRes.message}`); + await TGLogger.Warn(`获取游戏账号失败:${gameRes.retcode}-${gameRes.message}`); + isTryLogin.value = false; + return; + } + } catch (e) { + const errMsg = TGHttps.getErrMsg(e); await showLoading.end(); - showSnackbar.error(`[${gameRes.retcode}]${gameRes.message}`); - await TGLogger.Error(`获取游戏账号失败:${gameRes.retcode}-${gameRes.message}`); + showSnackbar.error(`获取游戏账号失败:${errMsg}`); + await TGLogger.Error(`[TSidebar] 获取游戏账号异常`); + await TGLogger.Error(`[TSidebar] ${e}`); isTryLogin.value = false; return; } showSnackbar.success("获取游戏账号成功"); - await TSUserAccount.game.saveAccounts(briefInfoGet.uid, gameRes); + await TSUserAccount.game.saveAccounts(briefInfoGet.uid, gameRes.data.list); const curAccount = await TSUserAccount.game.getCurAccount(briefInfoGet.uid); if (!curAccount) { showSnackbar.warn("未检测到游戏账号,请重新刷新"); @@ -699,15 +711,27 @@ async function addByCookie(): Promise { updated: "", }); await showLoading.update("正在获取游戏账号"); - const gameRes = await takumiReq.bind.gameRoles(ck); - if (!Array.isArray(gameRes)) { + let gameRes: TGApp.BBS.Game.AccountResp | undefined; + try { + gameRes = await takumiReq.bind.gameRoles(ck); + if (gameRes.retcode !== 0) { + await showLoading.end(); + showSnackbar.error(`[${gameRes.retcode}] ${gameRes.message}`); + await TGLogger.Warn(`获取游戏账号失败:${gameRes.retcode}-${gameRes.message}`); + isTryLogin.value = false; + return; + } + } catch (e) { + const errMsg = TGHttps.getErrMsg(e); await showLoading.end(); - showSnackbar.error(`[${gameRes.retcode}]${gameRes.message}`); + showSnackbar.error(`获取游戏账号失败:${errMsg}`); + await TGLogger.Error(`[TSidebar] 获取游戏账号异常`); + await TGLogger.Error(`[TSidebar] ${e}`); isTryLogin.value = false; return; } await showLoading.update("正在保存游戏账号"); - await TSUserAccount.game.saveAccounts(briefInfoGet.uid, gameRes); + await TSUserAccount.game.saveAccounts(briefInfoGet.uid, gameRes.data.list); const curAccount = await TSUserAccount.game.getCurAccount(briefInfoGet.uid); if (!curAccount) { await showLoading.end(); diff --git a/src/components/pageAnno/tao-iframe.vue b/src/components/pageAnno/tao-iframe.vue index 300c0a0a..f1b464b5 100644 --- a/src/components/pageAnno/tao-iframe.vue +++ b/src/components/pageAnno/tao-iframe.vue @@ -13,6 +13,8 @@ import showSnackbar from "@comp/func/snackbar.js"; import takumiReq from "@req/takumiReq.js"; import useAppStore from "@store/app.js"; import useUserStore from "@store/user.js"; +import TGHttps from "@utils/TGHttps.js"; +import TGLogger from "@utils/TGLogger.js"; import { storeToRefs } from "pinia"; import { onMounted, ref, watch } from "vue"; @@ -45,14 +47,26 @@ async function refreshAuthkey(): Promise { showSnackbar.warn("请先登录账号"); return; } - const authkeyRes = await takumiReq.bind.authKey(cookie.value, account.value); - if (typeof authkeyRes === "string") { - authkey.value = authkeyRes; - } else { - showSnackbar.error("获取authkey失败"); + let authkeyRes: TGApp.Game.Gacha.AuthKeyResp | undefined; + try { + authkeyRes = await takumiReq.bind.authKey(cookie.value, account.value); + if (authkeyRes.retcode !== 0) { + showSnackbar.error(`获取authkey失败:[${authkeyRes.retcode}] ${authkeyRes.message}`); + await TGLogger.Warn( + `[TaoIframe] 获取authkey失败:[${authkeyRes.retcode}] ${authkeyRes.message}`, + ); + visible.value = false; + return; + } + } catch (e) { + const errMsg = TGHttps.getErrMsg(e); + showSnackbar.error(`获取authkey失败:${errMsg}`); + await TGLogger.Error(`[TaoIframe] 获取authkey异常`); + await TGLogger.Error(`[TaoIframe] ${e}`); visible.value = false; return; } + authkey.value = authkeyRes.data.authkey; } async function getUrl(): Promise { diff --git a/src/components/pageConfig/tc-userBadge.vue b/src/components/pageConfig/tc-userBadge.vue index 19daa59d..f1df30e7 100644 --- a/src/components/pageConfig/tc-userBadge.vue +++ b/src/components/pageConfig/tc-userBadge.vue @@ -130,6 +130,7 @@ import TSUserAccount from "@Sqlm/userAccount.js"; import useAppStore from "@store/app.js"; import useUserStore from "@store/user.js"; import TGLogger from "@utils/TGLogger.js"; +import TGHttps from "@utils/TGHttps.js"; import { storeToRefs } from "pinia"; import { computed, ref, shallowRef } from "vue"; @@ -199,15 +200,25 @@ async function tryGetTokens(ck: TGApp.App.Account.Cookie): Promise { cookie.value = ck; isLogin.value = true; await showLoading.update("正在获取游戏账号"); - const gameRes = await takumiReq.bind.gameRoles(cookie.value); - if (!Array.isArray(gameRes)) { + let gameRes: TGApp.BBS.Game.AccountResp | undefined; + try { + gameRes = await takumiReq.bind.gameRoles(cookie.value); + if (gameRes.retcode !== 0) { + await showLoading.end(); + showSnackbar.error(`[${gameRes.retcode}] ${gameRes.message}`); + await TGLogger.Warn(`获取游戏账号失败:${gameRes.retcode}-${gameRes.message}`); + return; + } + } catch (e) { + const errMsg = TGHttps.getErrMsg(e); await showLoading.end(); - showSnackbar.error(`[${gameRes.retcode}]${gameRes.message}`); - await TGLogger.Error(`获取游戏账号失败:${gameRes.retcode}-${gameRes.message}`); + showSnackbar.error(`获取游戏账号失败:${errMsg}`); + await TGLogger.Error(`[TcUserBadge] 获取游戏账号异常`); + await TGLogger.Error(`[TcUserBadge] ${e}`); return; } showSnackbar.success("获取游戏账号成功"); - await TSUserAccount.game.saveAccounts(briefInfoGet.uid, gameRes); + await TSUserAccount.game.saveAccounts(briefInfoGet.uid, gameRes.data.list); const curAccount = await TSUserAccount.game.getCurAccount(briefInfoGet.uid); if (!curAccount) { showSnackbar.warn("未检测到游戏账号,请重新刷新"); @@ -329,18 +340,27 @@ async function refreshUser(uid: string, full: boolean) { } await TSUserAccount.account.saveAccount(account); await showLoading.update("正在获取游戏账号信息"); - const accountRes = await takumiReq.bind.gameRoles(ck); - if (Array.isArray(accountRes)) { - await showLoading.update("获取游戏账号信息成功"); - await TGLogger.Info("[tc-userBadge][refreshUserInfo] 获取账号信息成功"); - await TSUserAccount.game.saveAccounts(account.uid, accountRes); - } else { + let accountRes: TGApp.BBS.Game.AccountResp | undefined; + try { + accountRes = await takumiReq.bind.gameRoles(ck); + if (accountRes.retcode !== 0) { + await showLoading.update("获取游戏账号信息失败"); + showSnackbar.error(`[${accountRes.retcode}] ${accountRes.message}`); + await TGLogger.Warn("[tc-userBadge][refreshUserInfo] 获取账号信息失败"); + await TGLogger.Warn( + `[tc-userBadge][refreshUserInfo] ${accountRes.retcode}: ${accountRes.message}`, + ); + } else { + await showLoading.update("获取游戏账号信息成功"); + await TGLogger.Info("[tc-userBadge][refreshUserInfo] 获取账号信息成功"); + await TSUserAccount.game.saveAccounts(account.uid, accountRes.data.list); + } + } catch (e) { + const errMsg = TGHttps.getErrMsg(e); await showLoading.update("获取游戏账号信息失败"); - showSnackbar.error(`[${accountRes.retcode}]${accountRes.message}`); - await TGLogger.Error("[tc-userBadge][refreshUserInfo] 获取账号信息失败"); - await TGLogger.Error( - `[tc-userBadge][refreshUserInfo] ${accountRes.retcode}: ${accountRes.message}`, - ); + showSnackbar.error(`获取游戏账号信息失败:${errMsg}`); + await TGLogger.Error("[tc-userBadge][refreshUserInfo] 获取账号信息异常"); + await TGLogger.Error(`[tc-userBadge][refreshUserInfo] ${e}`); } await showLoading.end(); } @@ -533,14 +553,25 @@ async function addByCookie(): Promise { updated: "", }); await showLoading.update("正在获取游戏账号"); - const gameRes = await takumiReq.bind.gameRoles(ck); - if (!Array.isArray(gameRes)) { + let gameRes: TGApp.BBS.Game.AccountResp | undefined; + try { + gameRes = await takumiReq.bind.gameRoles(ck); + if (gameRes.retcode !== 0) { + await showLoading.end(); + showSnackbar.error(`[${gameRes.retcode}] ${gameRes.message}`); + await TGLogger.Warn(`获取游戏账号失败:${gameRes.retcode}-${gameRes.message}`); + return; + } + } catch (e) { + const errMsg = TGHttps.getErrMsg(e); await showLoading.end(); - showSnackbar.error(`[${gameRes.retcode}]${gameRes.message}`); + showSnackbar.error(`获取游戏账号失败:${errMsg}`); + await TGLogger.Error(`[TcUserBadge] 获取游戏账号异常`); + await TGLogger.Error(`[TcUserBadge] ${e}`); return; } await showLoading.update("正在保存游戏账号"); - await TSUserAccount.game.saveAccounts(briefGet.uid, gameRes); + await TSUserAccount.game.saveAccounts(briefGet.uid, gameRes.data.list); const curAccount = await TSUserAccount.game.getCurAccount(briefGet.uid); if (!curAccount) { await showLoading.end(); diff --git a/src/components/pageConfig/tco-gameLogin.vue b/src/components/pageConfig/tco-gameLogin.vue index 8e7b47bc..b77d4b9c 100644 --- a/src/components/pageConfig/tco-gameLogin.vue +++ b/src/components/pageConfig/tco-gameLogin.vue @@ -41,6 +41,8 @@ import showLoading from "@comp/func/loading.js"; import showSnackbar from "@comp/func/snackbar.js"; import hk4eReq from "@req/hk4eReq.js"; import takumiReq from "@req/takumiReq.js"; +import TGHttps from "@utils/TGHttps.js"; +import TGLogger from "@utils/TGLogger.js"; import { generateShareImg } from "@utils/TGShare.js"; import QrcodeVue from "qrcode.vue"; import { onUnmounted, ref, watch } from "vue"; @@ -150,9 +152,21 @@ async function cycleGetDataGame(): Promise { } const statusRaw: TGApp.Game.Login.StatPayloadRaw = JSON.parse(res.payload.raw); await showLoading.start("正在获取SToken"); - const stResp = await takumiReq.game.stoken(statusRaw); - if ("retcode" in stResp) { - showSnackbar.error(`[${stResp.retcode}] ${stResp.message}`); + let stResp: TGApp.Game.Login.StResp | undefined; + try { + stResp = await takumiReq.game.stoken(statusRaw); + if (stResp.retcode !== 0) { + showSnackbar.error(`[${stResp.retcode}] ${stResp.message}`); + await TGLogger.Warn(`[TcoGameLogin] 获取SToken失败:[${stResp.retcode}] ${stResp.message}`); + model.value = false; + await showLoading.end(); + return; + } + } catch (e) { + const errMsg = TGHttps.getErrMsg(e); + showSnackbar.error(`获取SToken失败:${errMsg}`); + await TGLogger.Error(`[TcoGameLogin] 获取SToken异常`); + await TGLogger.Error(`[TcoGameLogin] ${e}`); model.value = false; await showLoading.end(); return; @@ -161,9 +175,9 @@ async function cycleGetDataGame(): Promise { account_id: statusRaw.uid, ltuid: statusRaw.uid, stuid: statusRaw.uid, - mid: stResp.user_info.mid, + mid: stResp.data.user_info.mid, cookie_token: "", - stoken: stResp.token.token, + stoken: stResp.data.token.token, ltoken: "", }; emits("success", ck); diff --git a/src/components/pageHome/ph-comp-pool.vue b/src/components/pageHome/ph-comp-pool.vue index 701371e9..359440f5 100644 --- a/src/components/pageHome/ph-comp-pool.vue +++ b/src/components/pageHome/ph-comp-pool.vue @@ -31,6 +31,7 @@ import "swiper/css/navigation"; import showSnackbar from "@comp/func/snackbar.js"; import PhPoolCard from "@comp/pageHome/ph-pool-card.vue"; import takumiReq from "@req/takumiReq.js"; +import TGHttps from "@utils/TGHttps.js"; import TGLogger from "@utils/TGLogger.js"; import { A11y, Autoplay } from "swiper/modules"; import { Swiper, SwiperSlide } from "swiper/vue"; @@ -45,14 +46,26 @@ const pools = shallowRef>([]); const swiperModules = [Autoplay, A11y]; onMounted(async () => { - const resp = await takumiReq.obc.gacha(); - if (Array.isArray(resp)) { - if (resp.length < 3) pools.value = resp; - else pools.value = [...resp, ...resp]; - } else { - showSnackbar.error(`获取限时祈愿失败:[${resp.retcode}]${resp.message}`); - await TGLogger.Error(`获取限时祈愿失败:[${resp.retcode}]${resp.message}`); + let resp: TGApp.BBS.Obc.GachaResp | undefined; + try { + resp = await takumiReq.obc.gacha(); + if (resp.retcode !== 0) { + showSnackbar.error(`获取限时祈愿失败:[${resp.retcode}] ${resp.message}`); + await TGLogger.Warn(`[PhCompPool] 获取限时祈愿失败:[${resp.retcode}] ${resp.message}`); + emits("success"); + return; + } + } catch (e) { + const errMsg = TGHttps.getErrMsg(e); + showSnackbar.error(`获取限时祈愿失败:${errMsg}`); + await TGLogger.Error(`[PhCompPool] 获取限时祈愿异常`); + await TGLogger.Error(`[PhCompPool] ${e}`); + emits("success"); + return; } + const list = resp.data.list; + if (list.length < 3) pools.value = list; + else pools.value = [...list, ...list]; emits("success"); }); diff --git a/src/components/userScripts/tus-sign.vue b/src/components/userScripts/tus-sign.vue index 9374b520..3d654311 100644 --- a/src/components/userScripts/tus-sign.vue +++ b/src/components/userScripts/tus-sign.vue @@ -63,6 +63,7 @@ import takumiReq from "@req/takumiReq.js"; import TSUserAccount from "@Sqlm/userAccount.js"; import useBBSStore from "@store/bbs.js"; import TGLogger from "@utils/TGLogger.js"; +import TGHttps from "@utils/TGHttps.js"; import TGNotify from "@utils/TGNotify.js"; import { storeToRefs } from "pinia"; import { onMounted, ref, shallowRef, watch } from "vue"; @@ -208,22 +209,29 @@ async function tryAuto(skip: boolean = false): Promise { async function refreshState(ck: TGApp.App.Account.Cookie, uid: string): Promise { if (signAccounts.value.length === 0) { await TGLogger.Script("[签到任务]未检测到游戏账户,正在获取"); - const gameResp = await takumiReq.bind.gameRoles(ck); - if (Array.isArray(gameResp)) { - await TGLogger.Script("[签到任务]获取游戏账户成功"); - await TSUserAccount.game.saveAccounts(uid, gameResp); - gameAccounts.value = await TSUserAccount.game.getAccount(uid); - for (const ac of gameAccounts.value) { - const info = getGameInfo(ac.gameBiz); - const find = signAccounts.value.find((i) => i.account === ac); - if (find) continue; - signAccounts.value.push({ selected: true, account: ac, info }); + let gameResp: TGApp.BBS.Game.AccountResp | undefined; + try { + gameResp = await takumiReq.bind.gameRoles(ck); + if (gameResp.retcode !== 0) { + await TGLogger.Script(`[签到任务]获取游戏账户失败:${gameResp.retcode} ${gameResp.message}`); + showSnackbar.error(`[${gameResp.retcode}] ${gameResp.message}`); + return; } - } else { - await TGLogger.Script(`[签到任务]获取游戏账户失败:${gameResp.retcode} ${gameResp.message}`); - showSnackbar.error(`[${gameResp.retcode}] ${gameResp.message}`); + } catch (e) { + const errMsg = TGHttps.getErrMsg(e); + await TGLogger.Script(`[签到任务]获取游戏账户异常:${errMsg}`); + showSnackbar.error(`获取游戏账户失败:${errMsg}`); return; } + await TGLogger.Script("[签到任务]获取游戏账户成功"); + await TSUserAccount.game.saveAccounts(uid, gameResp.data.list); + gameAccounts.value = await TSUserAccount.game.getAccount(uid); + for (const ac of gameAccounts.value) { + const info = getGameInfo(ac.gameBiz); + const find = signAccounts.value.find((i) => i.account === ac); + if (find) continue; + signAccounts.value.push({ selected: true, account: ac, info }); + } } const cookie = { cookie_token: ck.cookie_token, account_id: ck.account_id }; const dayNow = new Date().getDate(); diff --git a/src/pages/User/Gacha.vue b/src/pages/User/Gacha.vue index 0a41b28d..cf74df5c 100644 --- a/src/pages/User/Gacha.vue +++ b/src/pages/User/Gacha.vue @@ -488,21 +488,32 @@ async function confirmRefresh(force: boolean): Promise { } await TGLogger.Info(`[Gacha][${rfAccount.gameUid}][confirmRefresh] 刷新祈愿数据`); await showLoading.start(`正在刷新祈愿数据`, `UID:${rfAccount.gameUid},正在获取 authkey`); - const authkeyRes = await takumiReq.bind.authKey(rfCk!, rfAccount); - if (typeof authkeyRes === "string") { - authkey.value = authkeyRes; - await TGLogger.Info(`[Gacha][${rfAccount.gameUid}][confirmRefresh] 成功获取 authkey`); - } else { + let authkeyRes: TGApp.Game.Gacha.AuthKeyResp | undefined; + try { + authkeyRes = await takumiReq.bind.authKey(rfCk!, rfAccount); + if (authkeyRes.retcode !== 0) { + await showLoading.update("获取authkey失败"); + showSnackbar.error(`[${authkeyRes.retcode}] ${authkeyRes.message}`); + await TGLogger.Warn(`[Gacha][${rfAccount.gameUid}][confirmRefresh] 获取 authkey 失败`); + await TGLogger.Warn( + `[Gacha][${rfAccount.gameUid}][confirmRefresh] ${authkeyRes.retcode} ${authkeyRes.message}`, + ); + await new Promise((resolve) => setTimeout(resolve, 1000)); + await showLoading.end(); + return; + } + } catch (e) { + const errMsg = TGHttps.getErrMsg(e); await showLoading.update("获取authkey失败"); - showSnackbar.error(`[${authkeyRes.retcode}] ${authkeyRes.message}`); - await TGLogger.Error(`[Gacha][${rfAccount.gameUid}][confirmRefresh] 获取 authkey 失败`); - await TGLogger.Error( - `[Gacha][${rfAccount.gameUid}][confirmRefresh] ${authkeyRes.retcode} ${authkeyRes.message}`, - ); + showSnackbar.error(`获取authkey失败:${errMsg}`); + await TGLogger.Error(`[Gacha][${rfAccount.gameUid}][confirmRefresh] 获取 authkey 异常`); + await TGLogger.Error(`[Gacha][${rfAccount.gameUid}][confirmRefresh] ${e}`); await new Promise((resolve) => setTimeout(resolve, 1000)); await showLoading.end(); return; } + authkey.value = authkeyRes.data.authkey; + await TGLogger.Info(`[Gacha][${rfAccount.gameUid}][confirmRefresh] 成功获取 authkey`); await refreshGachaPool(rfAccount, "100", "新手祈愿", force); await refreshGachaPool(rfAccount, "200", "常驻祈愿", force); await refreshGachaPool(rfAccount, "301", "角色祈愿", force); diff --git a/src/pages/User/GachaB.vue b/src/pages/User/GachaB.vue index 43ddf91f..e841791d 100644 --- a/src/pages/User/GachaB.vue +++ b/src/pages/User/GachaB.vue @@ -101,6 +101,7 @@ import useUserStore from "@store/user.js"; import { path } from "@tauri-apps/api"; import { open, save } from "@tauri-apps/plugin-dialog"; import TGLogger from "@utils/TGLogger.js"; +import TGHttps from "@utils/TGHttps.js"; import { storeToRefs } from "pinia"; import { onMounted, ref, shallowRef, watch } from "vue"; import { useRouter } from "vue-router"; @@ -203,21 +204,32 @@ async function confirmRefresh(force: boolean): Promise { } await TGLogger.Info(`[GachaB][${rfAccount.gameUid}] 开始刷新千星奇域祈愿数据`); await showLoading.start(`正在刷新祈愿数据`, `UID:${rfAccount.gameUid},正在获取 authkey`); - const authkeyRes = await takumiReq.bind.authKey(rfCk!, rfAccount); - if (typeof authkeyRes === "string") { - authkey.value = authkeyRes; - await TGLogger.Info(`[GachaB][${rfAccount.gameUid}] 成功获取 authkey`); - } else { + let authkeyRes: TGApp.Game.Gacha.AuthKeyResp | undefined; + try { + authkeyRes = await takumiReq.bind.authKey(rfCk!, rfAccount); + if (authkeyRes.retcode !== 0) { + await showLoading.update("获取authkey失败"); + showSnackbar.error(`[${authkeyRes.retcode}] ${authkeyRes.message}`); + await TGLogger.Warn(`[GachaB][${rfAccount.gameUid}] 获取 authkey 失败`); + await TGLogger.Warn( + `[GachaB][${rfAccount.gameUid}] ${authkeyRes.retcode} ${authkeyRes.message}`, + ); + await new Promise((resolve) => setTimeout(resolve, 1000)); + await showLoading.end(); + return; + } + } catch (e) { + const errMsg = TGHttps.getErrMsg(e); await showLoading.update("获取authkey失败"); - showSnackbar.error(`[${authkeyRes.retcode}]${authkeyRes.message}`); - await TGLogger.Error(`[GachaB][${rfAccount.gameUid}] 获取 authkey 失败`); - await TGLogger.Error( - `[GachaB][${rfAccount.gameUid}] ${authkeyRes.retcode} ${authkeyRes.message}`, - ); + showSnackbar.error(`获取authkey失败:${errMsg}`); + await TGLogger.Error(`[GachaB][${rfAccount.gameUid}] 获取 authkey 异常`); + await TGLogger.Error(`[GachaB][${rfAccount.gameUid}] ${e}`); await new Promise((resolve) => setTimeout(resolve, 1000)); await showLoading.end(); return; } + authkey.value = authkeyRes.data.authkey; + await TGLogger.Info(`[GachaB][${rfAccount.gameUid}] 成功获取 authkey`); await refreshGachaPool(rfAccount, "1000", "常驻颂愿", force); await refreshGachaPool(rfAccount, "2000", "活动颂愿", force); // await refreshGachaPool(rfAccount, "20011", "活动颂愿·男", force); diff --git a/src/request/takumiReq.ts b/src/request/takumiReq.ts index 13aedb53..9210495a 100644 --- a/src/request/takumiReq.ts +++ b/src/request/takumiReq.ts @@ -3,7 +3,6 @@ * @since Beta v0.10.1 */ import { getRequestHeader } from "@utils/getRequestHeader.js"; -import TGHttp from "@utils/TGHttp.js"; import TGHttps from "@utils/TGHttps.js"; // TakumiApiBaseUrl => taBu @@ -11,13 +10,13 @@ const taBu: Readonly = "https://api-takumi.mihoyo.com/"; /** * 根据gameToken获取stoken - * @since Beta v0.7.2 + * @since Beta v0.10.1 * @param raw - 状态数据 - * @returns stoken + * @returns stoken响应数据 */ async function getSTokenByGameToken( raw: TGApp.Game.Login.StatPayloadRaw, -): Promise { +): Promise { const data = { account_id: Number(raw.uid), game_token: raw.token }; const header = { ...getRequestHeader({}, "POST", JSON.stringify(data), "X6"), @@ -26,51 +25,52 @@ async function getSTokenByGameToken( "x-rpc-game_biz": "bbs_cn", "x-rpc-sys_version": "12", }; - const resp = await TGHttp( + const resp = await TGHttps.post( `${taBu}account/ma-cn-session/app/getTokenByGameToken`, { - method: "POST", headers: header, body: JSON.stringify(data), }, ); - if (resp.retcode !== 0) return resp; return resp.data; } /** * 根据stoken获取action_ticket - * @since Beta v0.7.2 + * @since Beta v0.10.1 * @param cookie - Cookie * @param user - 用户 * @param actionType - 动作类型 - * @returns action_ticket + * @returns action_ticket响应数据 */ async function getActionTicketBySToken( cookie: TGApp.App.Account.Cookie, user: TGApp.Sqlite.Account.Game, actionType: string, -): Promise { +): Promise { const ck = { stoken: cookie.stoken, mid: cookie.mid }; const params = { action_type: actionType, stoken: cookie.stoken, uid: user.gameUid }; - return await TGHttp(`${taBu}auth/api/getActionTicketBySToken`, { - method: "GET", - headers: getRequestHeader(ck, "GET", params, "K2"), - query: params, - }); + const resp = await TGHttps.get( + `${taBu}auth/api/getActionTicketBySToken`, + { + headers: getRequestHeader(ck, "GET", params, "K2"), + query: params, + }, + ); + return resp.data; } /** * 生成authkey - * @since Beta v0.6.3 + * @since Beta v0.10.1 * @param cookie - cookie * @param account - 账户 - * @returns authkey + * @returns authkey响应数据 */ async function genAuthKey( cookie: TGApp.App.Account.Cookie, account: TGApp.Sqlite.Account.Game, -): Promise { +): Promise { const ck = { stoken: cookie.stoken, mid: cookie.mid }; const data = { auth_appid: "webview_gacha", @@ -78,75 +78,64 @@ async function genAuthKey( game_uid: account.gameUid, region: account.region, }; - const resp = await TGHttp( - `${taBu}binding/api/genAuthKey`, - { - method: "POST", - headers: getRequestHeader(ck, "POST", JSON.stringify(data), "LK2", true), - body: JSON.stringify(data), - }, - ); - if (resp.retcode !== 0) return resp; - return resp.data.authkey; + const resp = await TGHttps.post(`${taBu}binding/api/genAuthKey`, { + headers: getRequestHeader(ck, "POST", JSON.stringify(data), "LK2", true), + body: JSON.stringify(data), + }); + return resp.data; } /** * 生成authkey-v2,专门用于JSBridge - * @since Beta v0.6.3 + * @since Beta v0.10.1 * @param cookie - cookie * @param payload - payload - * @returns authkey2 + * @returns authkey2响应数据 */ async function genAuthKey2( cookie: Record, payload: Record, -): Promise { - return await TGHttp(`${taBu}binding/api/genAuthKey`, { - method: "POST", +): Promise { + const resp = await TGHttps.post(`${taBu}binding/api/genAuthKey`, { headers: getRequestHeader(cookie, "POST", JSON.stringify(payload), "LK2", true), body: JSON.stringify(payload), }); + return resp.data; } /** * 通过cookie获取游戏账号 - * @since Beta v0.7.2 + * @since Beta v0.10.1 * @param cookie - cookie - * @returns 游戏账号 + * @returns 游戏账号响应数据 */ async function getUserGameRolesByCookie( cookie: TGApp.App.Account.Cookie, -): Promise | TGApp.BBS.Response.Base> { +): Promise { const ck = { account_id: cookie.account_id, cookie_token: cookie.cookie_token }; - const resp = await TGHttp( + const resp = await TGHttps.get( `${taBu}binding/api/getUserGameRolesByCookie`, { - method: "GET", headers: getRequestHeader(ck, "GET", {}), }, ); - if (resp.retcode !== 0) return resp; - return resp.data.list; + return resp.data; } /** * 获取卡池信息 - * @since Beta v0.7.2 - * @returns 卡池信息 + * @since Beta v0.10.1 + * @returns 卡池信息响应数据 */ -async function getObcGachaPool(): Promise< - Array | TGApp.BBS.Response.Base -> { - const resp = await TGHttp( +async function getObcGachaPool(): Promise { + const resp = await TGHttps.get( `${taBu}common/blackboard/ys_obc/v1/gacha_pool`, { - method: "GET", - query: { app_sn: "ys_obc" }, headers: { "Content-Type": "application/json" }, + query: { app_sn: "ys_obc" }, }, ); - if (resp.retcode !== 0) return resp; - return resp.data.list; + return resp.data; } /** diff --git a/src/types/BBS/Auth.d.ts b/src/types/BBS/Auth.d.ts new file mode 100644 index 00000000..3570abef --- /dev/null +++ b/src/types/BBS/Auth.d.ts @@ -0,0 +1,40 @@ +/** + * BBS 认证相关类型定义 + * @since Beta v0.10.1 + */ + +declare namespace TGApp.BBS.Auth { + /** + * ActionTicket 数据 + * @since Beta v0.10.1 + */ + type ActionTicketData = { + /** action_ticket */ + ticket: string; + }; + + /** + * ActionTicket 响应 + * @since Beta v0.10.1 + */ + type ActionTicketResp = TGApp.BBS.Response.BaseWithData; + + /** + * AuthKey 数据 + * @since Beta v0.10.1 + */ + type AuthKeyData = { + /** 签名类型 */ + sign_type: number; + /** authKey 版本 */ + authkey_ver: number; + /** authKey */ + authkey: string; + }; + + /** + * AuthKey 响应 + * @since Beta v0.10.1 + */ + type AuthKeyResp = TGApp.BBS.Response.BaseWithData; +} diff --git a/src/utils/TGClient.ts b/src/utils/TGClient.ts index c7a4eda7..fc4eafff 100644 --- a/src/utils/TGClient.ts +++ b/src/utils/TGClient.ts @@ -1,6 +1,6 @@ /** * 负责米游社客户端的 callback 处理 - * @since Beta v0.9.4 + * @since Beta v0.10.1 */ import showSnackbar from "@comp/func/snackbar.js"; @@ -19,6 +19,7 @@ import { getDS4JS } from "@utils/getRequestHeader.js"; import { parseLink } from "./linkParser.js"; import TGBbs from "./TGBbs.js"; import TGLogger from "./TGLogger.js"; +import TGHttps from "./TGHttps.js"; import { createPost } from "./TGWindow.js"; import { getDeviceInfo } from "./toolFunc.js"; @@ -482,7 +483,7 @@ class Client { /** * 获取米游社客户端的 authkey - * @since Beta v0.3.9 + * @since Beta v0.10.1 * @param arg - 请求参数 * @returns 无返回值 */ @@ -492,13 +493,26 @@ class Client { const userStore = useUserStore(); if (!userStore.cookie) return; const cookie = { mid: userStore.cookie.mid, stoken: userStore.cookie.stoken }; - const res = await takumiReq.bind.authKey2(cookie, arg.payload); - await this.callback(arg.callback, res.data); + let res: TGApp.BBS.Auth.AuthKeyResp | undefined; + try { + res = await takumiReq.bind.authKey2(cookie, arg.payload); + if (res.retcode !== 0) { + await TGLogger.Warn(`[TGClient][genAuthKey] 业务错误:[${res.retcode}] ${res.message}`); + await this.callback(arg.callback, res); + return; + } + } catch (e) { + const errMsg = TGHttps.getErrMsg(e); + await TGLogger.Error(`[TGClient][genAuthKey] 网络错误:${errMsg}`); + await TGLogger.Error(`[TGClient][genAuthKey] ${e}`); + return; + } + await this.callback(arg.callback, res); } /** * 获取米游社客户端的 action_ticket - * @since Beta v0.3.9 + * @since Beta v0.10.1 * @param arg - 请求参数 * @returns 无返回值 */ @@ -507,12 +521,27 @@ class Client { ): Promise { const userStore = useUserStore(); if (!userStore.cookie) return; - const ActionTicket = await takumiReq.auth.actionTicket( - userStore.cookie, - userStore.account, - arg.payload.action_type, - ); - await this.callback(arg.callback, ActionTicket.data); + let actionTicket: TGApp.BBS.Auth.ActionTicketResp | undefined; + try { + actionTicket = await takumiReq.auth.actionTicket( + userStore.cookie, + userStore.account, + arg.payload.action_type, + ); + if (actionTicket.retcode !== 0) { + await TGLogger.Warn( + `[TGClient][getActionTicket] 业务错误:[${actionTicket.retcode}] ${actionTicket.message}`, + ); + await this.callback(arg.callback, actionTicket); + return; + } + } catch (e) { + const errMsg = TGHttps.getErrMsg(e); + await TGLogger.Error(`[TGClient][getActionTicket] 网络错误:${errMsg}`); + await TGLogger.Error(`[TGClient][getActionTicket] ${e}`); + return; + } + await this.callback(arg.callback, actionTicket); } /**