♻️ 迁移takumiReq

This commit is contained in:
BTMuli
2026-04-14 22:51:58 +08:00
parent 329a594d7c
commit a59085eaa8
11 changed files with 325 additions and 140 deletions

View File

@@ -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<void> {
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<void> {
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();

View File

@@ -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<void> {
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<string> {

View File

@@ -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<void> {
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<void> {
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();

View File

@@ -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<void> {
}
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<void> {
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);

View File

@@ -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<Array<TGApp.BBS.Obc.GachaItem>>([]);
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");
});
</script>

View File

@@ -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<void> {
async function refreshState(ck: TGApp.App.Account.Cookie, uid: string): Promise<void> {
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();