mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-04-22 21:59:49 +08:00
♻️ 迁移takumiReq
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -488,21 +488,32 @@ async function confirmRefresh(force: boolean): Promise<void> {
|
||||
}
|
||||
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<void>((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<void>((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);
|
||||
|
||||
@@ -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<void> {
|
||||
}
|
||||
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<void>((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<void>((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);
|
||||
|
||||
@@ -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<string> = "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<TGApp.BBS.Response.Base | TGApp.Game.Login.StRes> {
|
||||
): Promise<TGApp.Game.Login.StResp> {
|
||||
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<TGApp.Game.Login.StResp>(
|
||||
const resp = await TGHttps.post<TGApp.Game.Login.StResp>(
|
||||
`${taBu}account/ma-cn-session/app/getTokenByGameToken`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: header,
|
||||
body: JSON.stringify(data),
|
||||
},
|
||||
);
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>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<TGApp.BBS.Response.Base> {
|
||||
): Promise<TGApp.BBS.Auth.ActionTicketResp> {
|
||||
const ck = { stoken: cookie.stoken, mid: cookie.mid };
|
||||
const params = { action_type: actionType, stoken: cookie.stoken, uid: user.gameUid };
|
||||
return await TGHttp<TGApp.BBS.Response.Base>(`${taBu}auth/api/getActionTicketBySToken`, {
|
||||
method: "GET",
|
||||
headers: getRequestHeader(ck, "GET", params, "K2"),
|
||||
query: params,
|
||||
});
|
||||
const resp = await TGHttps.get<TGApp.BBS.Auth.ActionTicketResp>(
|
||||
`${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<string | TGApp.BBS.Response.Base> {
|
||||
): Promise<TGApp.Game.Gacha.AuthKeyResp> {
|
||||
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<TGApp.Game.Gacha.AuthKeyResp | TGApp.BBS.Response.Base>(
|
||||
`${taBu}binding/api/genAuthKey`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: getRequestHeader(ck, "POST", JSON.stringify(data), "LK2", true),
|
||||
body: JSON.stringify(data),
|
||||
},
|
||||
);
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.authkey;
|
||||
const resp = await TGHttps.post<TGApp.Game.Gacha.AuthKeyResp>(`${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<string, string>,
|
||||
payload: Record<string, string>,
|
||||
): Promise<TGApp.BBS.Response.Base> {
|
||||
return await TGHttp<TGApp.BBS.Response.Base>(`${taBu}binding/api/genAuthKey`, {
|
||||
method: "POST",
|
||||
): Promise<TGApp.BBS.Auth.AuthKeyResp> {
|
||||
const resp = await TGHttps.post<TGApp.BBS.Auth.AuthKeyResp>(`${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<Array<TGApp.BBS.Game.Account> | TGApp.BBS.Response.Base> {
|
||||
): Promise<TGApp.BBS.Game.AccountResp> {
|
||||
const ck = { account_id: cookie.account_id, cookie_token: cookie.cookie_token };
|
||||
const resp = await TGHttp<TGApp.BBS.Game.AccountResp>(
|
||||
const resp = await TGHttps.get<TGApp.BBS.Game.AccountResp>(
|
||||
`${taBu}binding/api/getUserGameRolesByCookie`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: getRequestHeader(ck, "GET", {}),
|
||||
},
|
||||
);
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>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.Obc.GachaItem> | TGApp.BBS.Response.Base
|
||||
> {
|
||||
const resp = await TGHttp<TGApp.BBS.Obc.GachaResp>(
|
||||
async function getObcGachaPool(): Promise<TGApp.BBS.Obc.GachaResp> {
|
||||
const resp = await TGHttps.get<TGApp.BBS.Obc.GachaResp>(
|
||||
`${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 <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.list;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
40
src/types/BBS/Auth.d.ts
vendored
Normal file
40
src/types/BBS/Auth.d.ts
vendored
Normal file
@@ -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<ActionTicketData>;
|
||||
|
||||
/**
|
||||
* 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<AuthKeyData>;
|
||||
}
|
||||
@@ -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<void> {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user