mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-14 09:38:13 +08:00
✨ 初步打通相关流程
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
// vue
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { computed, ref, watch } from "vue";
|
||||
import showSnackbar from "../func/snackbar";
|
||||
import TOverlay from "../main/t-overlay.vue";
|
||||
import QrcodeVue from "qrcode.vue";
|
||||
@@ -50,8 +50,10 @@ const ticket = ref<string>("");
|
||||
|
||||
const userStore = useUserStore();
|
||||
|
||||
onMounted(async () => {
|
||||
await freshQr();
|
||||
watch(visible, async (value) => {
|
||||
if (value) {
|
||||
await freshQr();
|
||||
}
|
||||
});
|
||||
|
||||
async function freshQr(): Promise<void> {
|
||||
@@ -96,6 +98,8 @@ async function getData(): Promise<void> {
|
||||
} else {
|
||||
const data: TGApp.Plugins.Mys.GameLogin.StatusPayloadRaw = JSON.parse(res.payload.raw);
|
||||
await userStore.saveCookie("account_id", data.uid);
|
||||
await userStore.saveCookie("ltuid", data.uid);
|
||||
await userStore.saveCookie("stuid", data.uid);
|
||||
await userStore.saveCookie("game_token", data.token);
|
||||
showSnackbar({
|
||||
text: "登录成功",
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="ur-top">
|
||||
<div class="ur-top-title">
|
||||
<span v-if="!isEmpty">{{ getTitle() }} 更新于 {{ recordData.updated }}</span>
|
||||
<span v-else>原神战绩【暂无数据】【{{ user.gameUid }}】</span>
|
||||
<span v-else>原神战绩【暂无数据】</span>
|
||||
</div>
|
||||
<div class="ur-top-btns">
|
||||
<v-btn class="ur-top-btn" @click="refresh()">
|
||||
@@ -46,6 +46,7 @@ import { useUserStore } from "../../store/modules/user";
|
||||
import TGRequest from "../../web/request/TGRequest";
|
||||
import TGSqlite from "../../plugins/Sqlite";
|
||||
import { generateShareImg } from "../../utils/TGShare";
|
||||
import showSnackbar from "../../components/func/snackbar";
|
||||
|
||||
// store
|
||||
const userStore = useUserStore();
|
||||
@@ -91,7 +92,10 @@ async function refresh(): Promise<void> {
|
||||
await TGSqlite.saveUserRecord(res, user.value.gameUid);
|
||||
await initUserRecordData();
|
||||
} else {
|
||||
console.error(res);
|
||||
showSnackbar({
|
||||
text: `[${res.retcode}] ${res.message}`,
|
||||
color: "error",
|
||||
});
|
||||
}
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<ToLoading v-model="loading" :title="loadingTitle" :subtitle="loadingSub" />
|
||||
<ToGameLogin v-model="scan" />
|
||||
<v-list class="config-list">
|
||||
<v-list-subheader :inset="true" class="config-header"> 应用信息</v-list-subheader>
|
||||
<v-divider :inset="true" class="border-opacity-75" />
|
||||
@@ -48,7 +49,19 @@
|
||||
<img class="config-icon" :src="userInfo.avatar" alt="Login" />
|
||||
</template>
|
||||
<template #append>
|
||||
<v-btn class="config-btn" @click="confirmRefreshUser"> 刷新数据 </v-btn>
|
||||
<v-btn v-show="userInfo.nickname === '未登录'" class="config-btn" @click="confirmScanLogin">
|
||||
扫码登录</v-btn
|
||||
>
|
||||
<v-btn v-show="userInfo.nickname === '未登录'" class="config-btn" @click="confirmInitUser">
|
||||
刷新数据</v-btn
|
||||
>
|
||||
<v-btn
|
||||
v-show="userInfo.nickname !== '未登录'"
|
||||
class="config-btn"
|
||||
@click="confirmRefreshUser"
|
||||
>
|
||||
刷新数据</v-btn
|
||||
>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-subheader :inset="true" class="config-header">系统信息</v-list-subheader>
|
||||
@@ -105,7 +118,7 @@
|
||||
:chips="true"
|
||||
/>
|
||||
<template #append>
|
||||
<v-btn class="config-btn" @click="submitHome"> 确定 </v-btn>
|
||||
<v-btn class="config-btn" @click="submitHome"> 确定</v-btn>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item prepend-icon="mdi-content-save" title="数据备份" @click="confirmBackup" />
|
||||
@@ -130,12 +143,12 @@
|
||||
/>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item @click="confirmInputCK">
|
||||
<v-list-item @click="confirmScan">
|
||||
<template #prepend>
|
||||
<v-icon>mdi-cookie</v-icon>
|
||||
</template>
|
||||
<template #title>
|
||||
<span style="cursor: pointer">手动输入 Cookie</span>
|
||||
<span style="cursor: pointer">重新扫码</span>
|
||||
</template>
|
||||
<template #append>
|
||||
<v-icon
|
||||
@@ -177,6 +190,7 @@ import { computed, onMounted, ref } from "vue";
|
||||
import showSnackbar from "../../components/func/snackbar";
|
||||
import showConfirm from "../../components/func/confirm";
|
||||
import ToLoading from "../../components/overlay/to-loading.vue";
|
||||
import ToGameLogin from "../../components/overlay/to-gameLogin.vue";
|
||||
// tauri
|
||||
import { app, fs, os } from "@tauri-apps/api";
|
||||
// store
|
||||
@@ -211,6 +225,7 @@ const dbInfo = ref<Array<{ key: string; value: string; updated: string }>>([]);
|
||||
const loading = ref<boolean>(true);
|
||||
const loadingTitle = ref<string>("正在加载...");
|
||||
const loadingSub = ref<string>("");
|
||||
const scan = ref<boolean>(false);
|
||||
|
||||
// data
|
||||
const showHome = ref<string[]>(homeStore.getShowValue());
|
||||
@@ -256,6 +271,121 @@ function toOuter(url: string): void {
|
||||
window.open(url);
|
||||
}
|
||||
|
||||
// 扫码登录
|
||||
async function confirmScanLogin(): Promise<void> {
|
||||
const confirmRes = await showConfirm({
|
||||
title: "请使用米游社 APP 执行操作",
|
||||
text: "请在成功后刷新数据",
|
||||
});
|
||||
if (confirmRes) {
|
||||
scan.value = true;
|
||||
} else {
|
||||
showSnackbar({
|
||||
color: "grey",
|
||||
text: "已取消扫码登录",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 初次获取用户信息
|
||||
async function confirmInitUser(): Promise<void> {
|
||||
const cookieTemp = {
|
||||
account_id: userStore.getCookieItem("account_id"),
|
||||
game_token: userStore.getCookieItem("game_token"),
|
||||
ltuid: userStore.getCookieItem("ltuid"),
|
||||
ltoken: "",
|
||||
stoken: "",
|
||||
cookie_token: "",
|
||||
stuid: "",
|
||||
mid: "",
|
||||
};
|
||||
loadingTitle.value = "正在获取 tokens";
|
||||
loading.value = true;
|
||||
loadingSub.value = "正在获取 stoken_v2";
|
||||
const stokenRes = await TGRequest.User.bgGameToken.getStoken(
|
||||
cookieTemp.account_id,
|
||||
cookieTemp.game_token,
|
||||
);
|
||||
if ("retcode" in stokenRes) {
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
text: `[${stokenRes.retcode}] ${stokenRes.message}`,
|
||||
});
|
||||
console.error("获取 stoken_v2 失败", stokenRes);
|
||||
} else {
|
||||
const stoken = stokenRes.token.token;
|
||||
const mid = stokenRes.user_info.mid;
|
||||
await userStore.saveCookie("stoken", stoken);
|
||||
await userStore.saveCookie("mid", mid);
|
||||
cookieTemp.stoken = stoken;
|
||||
cookieTemp.mid = mid;
|
||||
}
|
||||
loadingSub.value = "正在获取 cookie_token";
|
||||
const cookieTokenRes = await TGRequest.User.bgGameToken.getCookieToken(
|
||||
cookieTemp.account_id,
|
||||
cookieTemp.game_token,
|
||||
);
|
||||
if (typeof cookieTokenRes !== "string") {
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
text: `[${cookieTokenRes.retcode}] ${cookieTokenRes.message}`,
|
||||
});
|
||||
loadingSub.value = "获取 cookie_token 失败";
|
||||
console.error("获取 cookie_token 失败", cookieTokenRes);
|
||||
} else {
|
||||
await userStore.saveCookie("cookie_token", cookieTokenRes);
|
||||
cookieTemp.cookie_token = cookieTokenRes;
|
||||
}
|
||||
loadingSub.value = "正在获取 ltoken";
|
||||
const lTokenRes = await TGRequest.User.bySToken.getLToken(cookieTemp.mid, cookieTemp.stoken);
|
||||
if (typeof lTokenRes === "string") {
|
||||
await userStore.saveCookie("ltoken", lTokenRes);
|
||||
cookieTemp.ltoken = lTokenRes;
|
||||
} else {
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
text: `[${lTokenRes.retcode}] ${lTokenRes.message}`,
|
||||
});
|
||||
loadingSub.value = "获取 ltoken 失败";
|
||||
console.error("获取 ltoken 失败", lTokenRes);
|
||||
}
|
||||
loadingTitle.value = "正在获取用户信息";
|
||||
loadingSub.value = "正在获取 用户信息";
|
||||
const infoRes = await TGRequest.User.byCookie.getUserInfo(
|
||||
cookieTemp.cookie_token,
|
||||
cookieTemp.account_id,
|
||||
);
|
||||
console.log(infoRes);
|
||||
if ("nickname" in infoRes) {
|
||||
userStore.setBriefInfo(infoRes);
|
||||
} else {
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
text: `[${infoRes.retcode}] ${infoRes.message}`,
|
||||
});
|
||||
loadingSub.value = "获取用户信息失败";
|
||||
console.error("获取用户信息失败", infoRes);
|
||||
}
|
||||
const accountRes = await TGRequest.User.byCookie.getAccounts(
|
||||
cookieTemp.cookie_token,
|
||||
cookieTemp.account_id,
|
||||
);
|
||||
console.log(accountRes);
|
||||
if (Array.isArray(accountRes)) {
|
||||
loadingTitle.value = "获取成功!正在保存到数据库!";
|
||||
await TGSqlite.saveAccount(accountRes);
|
||||
} else {
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
text: `[${accountRes.retcode}] ${accountRes.message}`,
|
||||
});
|
||||
loadingSub.value = "获取用户信息失败";
|
||||
console.error("获取用户信息失败", accountRes);
|
||||
}
|
||||
loadingSub.value = "";
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
// 刷新用户信息
|
||||
async function confirmRefreshUser(): Promise<void> {
|
||||
const res = await showConfirm({
|
||||
@@ -273,7 +403,7 @@ async function confirmRefreshUser(): Promise<void> {
|
||||
if (Object.keys(ck).length < 1) {
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
text: "请先输入 Cookie!",
|
||||
text: "扫码登录后才能刷新用户信息!",
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -286,11 +416,10 @@ async function confirmRefreshUser(): Promise<void> {
|
||||
} else {
|
||||
console.error(verifyLTokenRes);
|
||||
loadingTitle.value = "验证失败!正在重新获取 ltoken";
|
||||
const ltokenRes = await TGRequest.User.bySToken.getLToken(ck.stuid, ck.stoken);
|
||||
const ltokenRes = await TGRequest.User.bySToken.getLToken(ck.mid, ck.stoken);
|
||||
if (typeof ltokenRes === "string") {
|
||||
ck.ltoken = ltokenRes;
|
||||
await TGSqlite.saveAppData("cookie", JSON.stringify(ck));
|
||||
userStore.initCookie(ck);
|
||||
loadingTitle.value = "刷新成功!正在获取用户头像、昵称信息";
|
||||
} else {
|
||||
console.error(ltokenRes);
|
||||
@@ -298,11 +427,10 @@ async function confirmRefreshUser(): Promise<void> {
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
const cookieTokenRes = await TGRequest.User.bySToken.getCookieToken(ck.stuid, ck.stoken);
|
||||
const cookieTokenRes = await TGRequest.User.bySToken.getCookieToken(ck.mid, ck.stoken);
|
||||
if (typeof cookieTokenRes === "string") {
|
||||
ck.cookie_token = cookieTokenRes;
|
||||
await TGSqlite.saveAppData("cookie", JSON.stringify(ck));
|
||||
userStore.initCookie(ck);
|
||||
console.log(JSON.stringify(ck));
|
||||
loadingTitle.value = "刷新成功!正在获取用户头像、昵称信息";
|
||||
} else {
|
||||
@@ -406,8 +534,6 @@ async function confirmRestore(): Promise<void> {
|
||||
fail.length > 0
|
||||
? showSnackbar({ text: `${fail.join("、")} 恢复失败!`, color: "error" })
|
||||
: showSnackbar({ text: "数据已恢复!" });
|
||||
const cookie = await TGSqlite.getCookie();
|
||||
userStore.initCookie(cookie);
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
@@ -500,73 +626,17 @@ async function confirmResetApp(): Promise<void> {
|
||||
}
|
||||
|
||||
// 输入 cookie
|
||||
async function confirmInputCK(): Promise<void> {
|
||||
const res = await showConfirm({
|
||||
title: "请输入 Cookie",
|
||||
text: "Cookie:",
|
||||
mode: "input",
|
||||
async function confirmScan(): Promise<void> {
|
||||
await confirmScanLogin();
|
||||
const confirmRes = await showConfirm({
|
||||
title: "是否刷新数据?",
|
||||
});
|
||||
if (res === false) {
|
||||
if (confirmRes) {
|
||||
await confirmInitUser();
|
||||
} else {
|
||||
showSnackbar({
|
||||
color: "grey",
|
||||
text: "已取消输入Cookie",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (typeof res !== "string") {
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
text: "Confirm组件类型错误!",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const cookie = res;
|
||||
if (cookie === "") {
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
text: "Cookie 为空!",
|
||||
});
|
||||
return;
|
||||
}
|
||||
loadingTitle.value = "正在获取 tokens...";
|
||||
const cookieObj = cookie
|
||||
.trim()
|
||||
.split(";")
|
||||
.map((item) => item.trim().split("="));
|
||||
const ticket = cookieObj.find((item) => item[0] === "login_ticket")?.[1];
|
||||
const uid = cookieObj.find((item) => item[0] === "login_uid")?.[1];
|
||||
// 如果两者不存在
|
||||
if (!ticket || !uid) {
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
text: "Cookie 无效!",
|
||||
});
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await TGRequest.User.init(ticket, uid);
|
||||
const ck = await TGSqlite.getCookie();
|
||||
userStore.initCookie(ck);
|
||||
loadingTitle.value = "正在获取用户信息...";
|
||||
const cookie_token = userStore.getCookieItem("cookie_token");
|
||||
const resUser = await TGRequest.User.byCookie.getUserInfo(cookie_token, uid);
|
||||
if ("nickname" in resUser) {
|
||||
userStore.setBriefInfo(resUser);
|
||||
appStore.isLogin = true;
|
||||
}
|
||||
const resAccounts = await TGRequest.User.byCookie.getAccounts(cookie_token, uid);
|
||||
if (Array.isArray(resAccounts)) {
|
||||
await TGSqlite.saveAccount(resAccounts);
|
||||
}
|
||||
loading.value = false;
|
||||
showSnackbar({
|
||||
text: "Cookie 已保存!",
|
||||
});
|
||||
} catch (err) {
|
||||
loading.value = false;
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
text: "Cookie 无效!",
|
||||
text: "已取消刷新数据",
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -687,7 +757,7 @@ function submitHome(): void {
|
||||
|
||||
.config-btn {
|
||||
width: 100px;
|
||||
margin-left: 100px;
|
||||
margin-left: 20px;
|
||||
background: var(--tgc-btn-1);
|
||||
color: var(--btn-text);
|
||||
}
|
||||
|
||||
@@ -1,50 +1,34 @@
|
||||
<template>
|
||||
<div>
|
||||
<h1>Test</h1>
|
||||
<h1>测试米游社扫码登录</h1>
|
||||
<div class="btn-list">
|
||||
<v-btn @click="renderQr">渲染二维码</v-btn>
|
||||
<v-btn @click="getData">获取数据</v-btn>
|
||||
<v-btn class="test-btn" @click="showScan">弹窗</v-btn>
|
||||
</div>
|
||||
<div class="qr-container">
|
||||
<qrcode-vue :value="content" :size="size" level="H" render-as="svg" />
|
||||
<ToGameLogin v-model="visible" />
|
||||
<h1>颜色测试</h1>
|
||||
<div class="test-box">
|
||||
<div class="test-1">
|
||||
Box 1
|
||||
<div class="test-2">
|
||||
Box 2
|
||||
<div class="test-3">
|
||||
Box 3
|
||||
<div class="test-4">Box 4</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
// vue
|
||||
import { ref } from "vue";
|
||||
import QrcodeVue from "qrcode.vue";
|
||||
import showSnackbar from "../../components/func/snackbar";
|
||||
// utils
|
||||
import { getLoginQr, getLoginStatus } from "../../plugins/Mys/utils/doWebLogin";
|
||||
import ToGameLogin from "../../components/overlay/to-gameLogin.vue";
|
||||
|
||||
const content = ref<string>("qrcode");
|
||||
const size = ref<number>(300);
|
||||
const ticket = ref<string>("");
|
||||
const visible = ref<boolean>(false);
|
||||
|
||||
async function renderQr(): Promise<void> {
|
||||
const res = await getLoginQr();
|
||||
if ("retcode" in res) {
|
||||
showSnackbar({
|
||||
text: `[${res.retcode}] ${res.message}`,
|
||||
color: "error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
ticket.value = res.ticket;
|
||||
content.value = res.url;
|
||||
}
|
||||
|
||||
async function getData(): Promise<void> {
|
||||
const res = await getLoginStatus(ticket.value);
|
||||
if ("retcode" in res) {
|
||||
showSnackbar({
|
||||
text: `[${res.retcode}] ${res.message}`,
|
||||
color: "error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
console.log(res);
|
||||
function showScan(): void {
|
||||
visible.value = true;
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
@@ -54,4 +38,42 @@ async function getData(): Promise<void> {
|
||||
margin-bottom: 20px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.test-btn {
|
||||
background: var(--tgc-btn-1);
|
||||
color: var(--btn-text);
|
||||
}
|
||||
|
||||
.test-box {
|
||||
display: flex;
|
||||
border-radius: 5px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.test-1,
|
||||
.test-2,
|
||||
.test-3,
|
||||
.test-4 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.test-1 {
|
||||
background: var(--box-bg-1);
|
||||
}
|
||||
|
||||
.test-2 {
|
||||
background: var(--box-bg-2);
|
||||
}
|
||||
|
||||
.test-3 {
|
||||
background: var(--box-bg-3);
|
||||
}
|
||||
|
||||
.test-4 {
|
||||
background: var(--box-bg-4);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* @file store modules app.ts
|
||||
* @description App store module
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.5
|
||||
* @author BTMuli <bt-muli@outlook.com>
|
||||
* @since Beta v0.3.0
|
||||
*/
|
||||
|
||||
// vue
|
||||
@@ -42,8 +42,6 @@ export const useAppStore = defineStore(
|
||||
const devEnv = ref(false);
|
||||
// 应用主题
|
||||
const theme = ref("default");
|
||||
// 是否登录
|
||||
const isLogin = ref(false);
|
||||
|
||||
const dataPath = reactive({
|
||||
userDataDir,
|
||||
@@ -78,7 +76,6 @@ export const useAppStore = defineStore(
|
||||
}
|
||||
|
||||
return {
|
||||
isLogin,
|
||||
theme,
|
||||
loading,
|
||||
buildTime,
|
||||
@@ -102,7 +99,7 @@ export const useAppStore = defineStore(
|
||||
{
|
||||
key: "app",
|
||||
storage: window.localStorage,
|
||||
paths: ["devMode", "loading", "buildTime", "isLogin", "devEnv"],
|
||||
paths: ["devMode", "loading", "buildTime", "devEnv"],
|
||||
},
|
||||
{
|
||||
key: "sidebar",
|
||||
|
||||
@@ -33,6 +33,27 @@ export const useUserStore = defineStore(
|
||||
});
|
||||
const cookie = ref<Record<string, string>>({});
|
||||
|
||||
// 判断当前用户是否已经登录
|
||||
function isLogin(): boolean {
|
||||
return cookie.value?.account_id !== "";
|
||||
}
|
||||
|
||||
// 加载用户数据,用于应用启动时
|
||||
async function loadUserData(): Promise<void> {
|
||||
if (isLogin()) {
|
||||
const accountDB = await TGSqlite.getCurAccount();
|
||||
if (accountDB) {
|
||||
setCurAccount(accountDB);
|
||||
}
|
||||
} else {
|
||||
const cookieDB = await TGSqlite.getCookie();
|
||||
if (Object.keys(cookieDB).length > 0) {
|
||||
cookie.value = cookieDB;
|
||||
await loadUserData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setBriefInfo(info: TGApp.App.Account.BriefInfo): void {
|
||||
briefInfo.value = info;
|
||||
}
|
||||
@@ -102,6 +123,8 @@ export const useUserStore = defineStore(
|
||||
getCookieGroup3,
|
||||
getCookieGroup4,
|
||||
saveCookie,
|
||||
isLogin,
|
||||
loadUserData,
|
||||
};
|
||||
},
|
||||
{
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
* @file web request TGRequest.ts
|
||||
* @description 应用用到的请求函数
|
||||
* @author BTMuli <bt-muli@outlook.com>
|
||||
* @since Alpha v0.2.3
|
||||
* @since Beta v0.3.0
|
||||
*/
|
||||
|
||||
import { getAbyss } from "./getAbyss";
|
||||
import { getAnnoList, getAnnoContent } from "./getAnno";
|
||||
import { getCookieTokenBySToken } from "./getCookieToken";
|
||||
import { getCookieTokenByGameToken, getCookieTokenBySToken } from "./getCookieToken";
|
||||
// import * from "./getEnkaData.ts";
|
||||
import { getGameAccountsBySToken, getGameAccountsByCookie } from "./getGameAccounts";
|
||||
import { getGameRecord } from "./getGameRecord";
|
||||
@@ -15,12 +15,10 @@ import { getLTokenBySToken } from "./getLToken";
|
||||
import { getGameRoleListByLToken } from "./getRoleList";
|
||||
import getSyncAvatarDetail from "./getSyncAvatarDetail";
|
||||
import getSyncAvatarListAll from "./getSyncAvatarListAll";
|
||||
// import * from "./getTickets.ts";
|
||||
import { getTokensByLoginTicket } from "./getTokens";
|
||||
import { getUserInfoByCookie } from "./getUserInfo";
|
||||
// import * from "./getUserCard";
|
||||
import initCookie from "./initCookie";
|
||||
import { verifyLToken } from "./verifyLToken";
|
||||
import { getStokenByGameToken } from "./getStoken";
|
||||
|
||||
const TGRequest = {
|
||||
Anno: {
|
||||
@@ -28,7 +26,6 @@ const TGRequest = {
|
||||
getContent: getAnnoContent,
|
||||
},
|
||||
User: {
|
||||
init: initCookie,
|
||||
getRecord: getGameRecord,
|
||||
byLoginTicket: {
|
||||
getTokens: getTokensByLoginTicket,
|
||||
@@ -47,6 +44,10 @@ const TGRequest = {
|
||||
getCookieToken: getCookieTokenBySToken,
|
||||
getLToken: getLTokenBySToken,
|
||||
},
|
||||
bgGameToken: {
|
||||
getCookieToken: getCookieTokenByGameToken,
|
||||
getStoken: getStokenByGameToken,
|
||||
},
|
||||
calculate: {
|
||||
getSyncAvatarListAll,
|
||||
getSyncAvatarDetail,
|
||||
|
||||
@@ -54,10 +54,10 @@ export async function getCookieTokenByGameToken(
|
||||
gameToken: string,
|
||||
): Promise<string | TGApp.BBS.Response.Base> {
|
||||
const url = "https://api-takumi.mihoyo.com/auth/api/getCookieAccountInfoByGameToken";
|
||||
const data = { account_id: accountId, game_token: gameToken };
|
||||
const data = { account_id: Number(accountId), game_token: gameToken };
|
||||
return await http
|
||||
.fetch<TGApp.BBS.Response.getCookieTokenByGameToken>(url, {
|
||||
method: "GET",
|
||||
method: "POST",
|
||||
body: http.Body.json(data),
|
||||
})
|
||||
.then((res) => {
|
||||
|
||||
@@ -15,19 +15,20 @@ import TGUtils from "../utils/TGUtils";
|
||||
/**
|
||||
* @description 根据 stoken 获取 ltoken
|
||||
* @since Alpha v0.1.5
|
||||
* @param {string} stuid 登录用户 uid
|
||||
* @param {string} stoken stoken
|
||||
* @param {string} mid 登录用户 mid
|
||||
* @param {string} stoken stoken_v2
|
||||
* @returns {Promise<string|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
export async function getLTokenBySToken(
|
||||
stuid: string,
|
||||
mid: string,
|
||||
stoken: string,
|
||||
): Promise<string | TGApp.BBS.Response.Base> {
|
||||
const url = TGApi.GameTokens.getLToken;
|
||||
const cookie = {
|
||||
stuid,
|
||||
mid,
|
||||
stoken,
|
||||
};
|
||||
console.log(cookie);
|
||||
const params = { stoken };
|
||||
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
|
||||
return await http
|
||||
|
||||
@@ -22,7 +22,7 @@ export async function getStokenByGameToken(
|
||||
gameToken: string,
|
||||
): Promise<TGApp.BBS.Response.getStokenByGameTokenData | TGApp.BBS.Response.Base> {
|
||||
const url = "https://api-takumi.mihoyo.com/account/ma-cn-session/app/getTokenByGameToken";
|
||||
const data = { account_id: accountId, game_token: gameToken };
|
||||
const data = { account_id: Number(accountId), game_token: gameToken };
|
||||
const header = {
|
||||
"x-rpc-app_id": TGConstant.BBS.APP_ID,
|
||||
};
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/**
|
||||
* @file web request initCookie.ts
|
||||
* @description 首次输入 cookie 后的一系列请求
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.5
|
||||
*/
|
||||
|
||||
// utils
|
||||
import TGSqlite from "../../plugins/Sqlite";
|
||||
// request
|
||||
import { getCookieTokenBySToken } from "./getCookieToken";
|
||||
import { getTokensByLoginTicket } from "./getTokens";
|
||||
import { verifyLToken } from "./verifyLToken";
|
||||
|
||||
/**
|
||||
* @description 根据输入 cookie 获取一堆 token
|
||||
* @since Alpha v0.1.5
|
||||
* @param {string} ticket login_ticket
|
||||
* @param {string} uid login_uid
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function initCookie(ticket: string, uid: string): Promise<void> {
|
||||
const tokenRes = await getTokensByLoginTicket(ticket, uid);
|
||||
const cookie: TGApp.BBS.Constant.Cookie = {
|
||||
account_id: uid,
|
||||
cookie_token: "",
|
||||
login_ticket: ticket,
|
||||
mid: "",
|
||||
login_uid: uid,
|
||||
ltoken: "",
|
||||
ltuid: uid,
|
||||
stoken: "",
|
||||
stuid: uid,
|
||||
};
|
||||
if (Array.isArray(tokenRes)) {
|
||||
const lToken = tokenRes.find((item) => item.name === "ltoken");
|
||||
const sToken = tokenRes.find((item) => item.name === "stoken");
|
||||
if (lToken != null) cookie.ltoken = lToken.token;
|
||||
if (sToken != null) cookie.stoken = sToken.token;
|
||||
const cookieToken = await getCookieTokenBySToken(uid, cookie.stoken);
|
||||
if (typeof cookieToken === "string") cookie.cookie_token = cookieToken;
|
||||
const mid = await verifyLToken(cookie.ltoken, cookie.ltuid);
|
||||
if (typeof mid === "string") cookie.mid = mid;
|
||||
await TGSqlite.saveAppData("cookie", JSON.stringify(cookie));
|
||||
} else {
|
||||
throw new Error("获取 token 失败");
|
||||
}
|
||||
}
|
||||
|
||||
export default initCookie;
|
||||
Reference in New Issue
Block a user