mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
✨ 获取用户头像&昵称
This commit is contained in:
@@ -33,8 +33,10 @@ import TBackTop from "./components/t-backTop.vue";
|
|||||||
import { fs, window, app, event } from "@tauri-apps/api";
|
import { fs, window, app, event } from "@tauri-apps/api";
|
||||||
// store
|
// store
|
||||||
import { useAppStore } from "./store/modules/app";
|
import { useAppStore } from "./store/modules/app";
|
||||||
|
import { useUserStore } from "./store/modules/user";
|
||||||
|
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
|
const userStore = useUserStore();
|
||||||
const isMain = ref(true as boolean);
|
const isMain = ref(true as boolean);
|
||||||
const theme = ref(appStore.theme as string);
|
const theme = ref(appStore.theme as string);
|
||||||
|
|
||||||
@@ -50,6 +52,8 @@ onMounted(async () => {
|
|||||||
await win.setTitle(title);
|
await win.setTitle(title);
|
||||||
await checkLoad();
|
await checkLoad();
|
||||||
}
|
}
|
||||||
|
// 保存 cookie
|
||||||
|
await userStore.initCookie();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听主题变化
|
// 监听主题变化
|
||||||
|
|||||||
@@ -106,11 +106,16 @@
|
|||||||
</v-list-group>
|
</v-list-group>
|
||||||
<v-divider />
|
<v-divider />
|
||||||
<div class="bottom-menu">
|
<div class="bottom-menu">
|
||||||
<!-- <v-list-item v-show="isDev" :title="userInfo.nickname" value="user" link href="/user">
|
<v-list-item :title="userInfo.nickname" value="user" link href="/user">
|
||||||
<template #prepend>
|
<template #prepend>
|
||||||
<img :src="userInfo.avatar" alt="userIcon" class="side-icon">
|
<img :src="userInfo.avatar" alt="userIcon" class="side-icon">
|
||||||
</template>
|
</template>
|
||||||
</v-list-item> -->
|
<template #append>
|
||||||
|
<v-icon style="color:var(--sidebar-icon)" @click="refreshUser()">
|
||||||
|
mdi-refresh
|
||||||
|
</v-icon>
|
||||||
|
</template>
|
||||||
|
</v-list-item>
|
||||||
<v-list-item :title="themeTitle" value="theme" @click="switchTheme()">
|
<v-list-item :title="themeTitle" value="theme" @click="switchTheme()">
|
||||||
<template #prepend>
|
<template #prepend>
|
||||||
<v-icon style="color:var(--sidebar-icon)">
|
<v-icon style="color:var(--sidebar-icon)">
|
||||||
@@ -135,17 +140,17 @@ import { computed, ref, onMounted } from "vue";
|
|||||||
import { event } from "@tauri-apps/api";
|
import { event } from "@tauri-apps/api";
|
||||||
// store
|
// store
|
||||||
import { useAppStore } from "../store/modules/app";
|
import { useAppStore } from "../store/modules/app";
|
||||||
|
import { useUserStore } from "../store/modules/user";
|
||||||
|
// utils
|
||||||
|
import TGRequest from "../web/request/TGRequest";
|
||||||
|
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
|
const userStore = useUserStore();
|
||||||
|
|
||||||
// 测试数据
|
const userInfo = computed(() => {
|
||||||
// const userInfo = {
|
return userStore.getBriefInfo();
|
||||||
// nickname: "测试用户",
|
});
|
||||||
// avatar: "/source/UI/defaultUser.webp",
|
|
||||||
// };
|
|
||||||
|
|
||||||
const rail = ref(appStore.sidebar.collapse);
|
const rail = ref(appStore.sidebar.collapse);
|
||||||
// const isDev = ref(appStore.devMode);
|
|
||||||
// theme
|
// theme
|
||||||
const themeGet = computed({
|
const themeGet = computed({
|
||||||
get () {
|
get () {
|
||||||
@@ -178,6 +183,16 @@ onMounted(async () => {
|
|||||||
await listenOnTheme();
|
await listenOnTheme();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function refreshUser () {
|
||||||
|
const cookie_token = userStore.getCookieItem("cookie_token");
|
||||||
|
const account_id = userStore.getCookieItem("account_id");
|
||||||
|
const res = await TGRequest.User.byCookie.getUserInfo(cookie_token, account_id);
|
||||||
|
if (res.hasOwnProperty("nickname")) {
|
||||||
|
const info = res as BTMuli.User.Base.BriefInfo;
|
||||||
|
userStore.setBriefInfo(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function listenOnTheme () {
|
async function listenOnTheme () {
|
||||||
await event.listen("readTheme", (e) => {
|
await event.listen("readTheme", (e) => {
|
||||||
const theme = e.payload as string;
|
const theme = e.payload as string;
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ import { fs, app, os } from "@tauri-apps/api";
|
|||||||
import { useAppStore } from "../store/modules/app";
|
import { useAppStore } from "../store/modules/app";
|
||||||
import { useHomeStore } from "../store/modules/home";
|
import { useHomeStore } from "../store/modules/home";
|
||||||
import { useAchievementsStore } from "../store/modules/achievements";
|
import { useAchievementsStore } from "../store/modules/achievements";
|
||||||
|
import { useUserStore } from "../store/modules/user";
|
||||||
// utils
|
// utils
|
||||||
import { backupUiafData, restoreUiafData } from "../utils/UIAF";
|
import { backupUiafData, restoreUiafData } from "../utils/UIAF";
|
||||||
import TGSqlite from "../utils/TGSqlite";
|
import TGSqlite from "../utils/TGSqlite";
|
||||||
@@ -175,6 +176,7 @@ import TGRequest from "../web/request/TGRequest";
|
|||||||
|
|
||||||
// Store
|
// Store
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
|
const userStore = useUserStore();
|
||||||
const homeStore = useHomeStore();
|
const homeStore = useHomeStore();
|
||||||
const achievementsStore = useAchievementsStore();
|
const achievementsStore = useAchievementsStore();
|
||||||
|
|
||||||
@@ -429,7 +431,15 @@ async function inputCookie () {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await TGRequest.User.init(ticket, uid);
|
await TGRequest.User.init(ticket, uid);
|
||||||
|
await userStore.initCookie();
|
||||||
loadingTitle.value = "正在获取用户信息...";
|
loadingTitle.value = "正在获取用户信息...";
|
||||||
|
const cookie_token = userStore.getCookieItem("cookie_token");
|
||||||
|
const res = await TGRequest.User.byCookie.getUserInfo(cookie_token, uid);
|
||||||
|
// . 判断返回是否为 BTMuli.User.Base.BriefInfo
|
||||||
|
if (res.hasOwnProperty("nickname")) {
|
||||||
|
const info = res as BTMuli.User.Base.BriefInfo;
|
||||||
|
userStore.setBriefInfo(info);
|
||||||
|
}
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
snackbarText.value = "Cookie 已保存!";
|
snackbarText.value = "Cookie 已保存!";
|
||||||
snackbarColor.value = "success";
|
snackbarColor.value = "success";
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file store modules hk4e.ts
|
|
||||||
* @description store modules hk4e.ts
|
|
||||||
* @author BTMuli<outlook.com>
|
|
||||||
* @since Alpha v0.1.2
|
|
||||||
*/
|
|
||||||
|
|
||||||
// pinia
|
|
||||||
import { defineStore } from "pinia";
|
|
||||||
|
|
||||||
export const useHk4eStore = defineStore(
|
|
||||||
"hk4e",
|
|
||||||
() => {
|
|
||||||
// getCookie
|
|
||||||
function getCookie (): string {
|
|
||||||
return localStorage.getItem("hk4eCookie") || "{}";
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取具体的 cookie
|
|
||||||
function getCookieItem (key: string): string {
|
|
||||||
const cookie = getCookie();
|
|
||||||
const cookieParsed = JSON.parse(cookie);
|
|
||||||
return cookieParsed.value[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
// setCookie
|
|
||||||
function setCookie (value: string): void {
|
|
||||||
// 解析 cookie
|
|
||||||
const cookieObj: Record<string, string> = {};
|
|
||||||
value.split(";").forEach((item) => {
|
|
||||||
const [key, value] = item.split("=");
|
|
||||||
cookieObj[key.trim()] = value;
|
|
||||||
});
|
|
||||||
// 保存 cookie
|
|
||||||
localStorage.setItem("hk4eCookie", JSON.stringify(cookieObj));
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
getCookie,
|
|
||||||
setCookie,
|
|
||||||
getCookieItem,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
{
|
|
||||||
persist: true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
53
src/store/modules/user.ts
Normal file
53
src/store/modules/user.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/**
|
||||||
|
* @file store modules user.ts
|
||||||
|
* @description User store module
|
||||||
|
* @author BTMuli<bt-muli@outlook.com>
|
||||||
|
* @since Alpha v0.2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
// vue
|
||||||
|
import { ref } from "vue";
|
||||||
|
// pinia
|
||||||
|
import { defineStore } from "pinia";
|
||||||
|
// utils
|
||||||
|
import TGSqlite from "../../utils/TGSqlite";
|
||||||
|
|
||||||
|
export const useUserStore = defineStore(
|
||||||
|
"user", () => {
|
||||||
|
const briefInfo = ref({
|
||||||
|
nickname: "",
|
||||||
|
avatar: "",
|
||||||
|
uid: "",
|
||||||
|
desc: "",
|
||||||
|
} as BTMuli.User.Base.BriefInfo);
|
||||||
|
const cookie = ref({} as Record<string, string>);
|
||||||
|
|
||||||
|
function setBriefInfo (info: BTMuli.User.Base.BriefInfo): void {
|
||||||
|
briefInfo.value = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBriefInfo (): Record<string, string> {
|
||||||
|
return briefInfo.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCookieItem (key: string): string {
|
||||||
|
return cookie.value[key] || "";
|
||||||
|
}
|
||||||
|
|
||||||
|
async function initCookie (): Promise<void> {
|
||||||
|
const ck = await TGSqlite.getCookie();
|
||||||
|
if (cookie.value !== ck) {
|
||||||
|
cookie.value = ck;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
getBriefInfo,
|
||||||
|
setBriefInfo,
|
||||||
|
getCookieItem,
|
||||||
|
initCookie,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
{
|
||||||
|
persist: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
17
src/types/UserRequest.d.ts
vendored
17
src/types/UserRequest.d.ts
vendored
@@ -45,4 +45,21 @@ declare namespace BTMuli.User.Base {
|
|||||||
stoken_v2?: string
|
stoken_v2?: string
|
||||||
stuid: string
|
stuid: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 用户简略信息
|
||||||
|
* @since Alpha v0.2.0
|
||||||
|
* @interface BriefInfo
|
||||||
|
* @property {string} nickname 用户昵称
|
||||||
|
* @property {string} uid 用户 uid
|
||||||
|
* @property {string} avatar 用户头像
|
||||||
|
* @property {string} desc 用户简介
|
||||||
|
* @returns BriefInfo
|
||||||
|
*/
|
||||||
|
export interface BriefInfo {
|
||||||
|
nickname: string
|
||||||
|
uid: string
|
||||||
|
avatar: string
|
||||||
|
desc: string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/web/api/BBS.ts
Normal file
10
src/web/api/BBS.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* @file web api BBS.ts
|
||||||
|
* @description BBS API
|
||||||
|
* @author BTMuli<bt-muli@outlook.com>
|
||||||
|
* @since Alpha v0.2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
const BBS_API = "https://bbs-api.miyoushe.com/"; // 基础 API
|
||||||
|
|
||||||
|
export const BBSUserInfoAPI = `${BBS_API}user/wapi/getUserFullInfo`; // 用户信息 API
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
* @since Alpha v0.2.0
|
* @since Alpha v0.2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { BBSUserInfoApi } from "./BBS";
|
||||||
import { ENKA_API } from "./ENKA";
|
import { ENKA_API } from "./ENKA";
|
||||||
import { Hk4eAnnoListApi, Hk4eAnnoContentApi, Hk4eAnnoQuery } from "./Hk4e";
|
import { Hk4eAnnoListApi, Hk4eAnnoContentApi, Hk4eAnnoQuery } from "./Hk4e";
|
||||||
import { PassportTokenApi, PassportCookieTokenApi, PassportVerifyApi } from "./Passport";
|
import { PassportTokenApi, PassportCookieTokenApi, PassportVerifyApi } from "./Passport";
|
||||||
@@ -29,6 +30,7 @@ const TGApi = {
|
|||||||
},
|
},
|
||||||
GameData: {
|
GameData: {
|
||||||
byCookie: {
|
byCookie: {
|
||||||
|
getUserInfo: BBSUserInfoApi, // 获取用户信息
|
||||||
getAccounts: TakumiCookieBindingRolesApi, // 获取绑定角色
|
getAccounts: TakumiCookieBindingRolesApi, // 获取绑定角色
|
||||||
getCharacter: TakumiRecordGenshinCharacterApi, // 获取角色信息
|
getCharacter: TakumiRecordGenshinCharacterApi, // 获取角色信息
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { getLTokenBySToken } from "./getLToken";
|
|||||||
// import * from "./getRoleList.ts";
|
// import * from "./getRoleList.ts";
|
||||||
// import * from "./getTickets.ts";
|
// import * from "./getTickets.ts";
|
||||||
import { getTokensByLoginTicket } from "./getTokens";
|
import { getTokensByLoginTicket } from "./getTokens";
|
||||||
|
import { getUserInfoByCookie } from "./getUserInfo";
|
||||||
// import * from "./getUserCard";
|
// import * from "./getUserCard";
|
||||||
import initCookie from "./initCookie";
|
import initCookie from "./initCookie";
|
||||||
import { verifyLToken } from "./verifyLToken";
|
import { verifyLToken } from "./verifyLToken";
|
||||||
@@ -29,6 +30,7 @@ const TGRequest = {
|
|||||||
},
|
},
|
||||||
byCookie: {
|
byCookie: {
|
||||||
getAccounts: getGameAccountsByCookie,
|
getAccounts: getGameAccountsByCookie,
|
||||||
|
getUserInfo: getUserInfoByCookie,
|
||||||
},
|
},
|
||||||
byLToken: {
|
byLToken: {
|
||||||
verify: verifyLToken,
|
verify: verifyLToken,
|
||||||
|
|||||||
47
src/web/request/getUserInfo.ts
Normal file
47
src/web/request/getUserInfo.ts
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* @file web request getUserInfo.ts
|
||||||
|
* @description 获取用户信息请求
|
||||||
|
* @author BTMuli<bt-muli@outlook.com>
|
||||||
|
* @since Alpha v0.2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
// tauri
|
||||||
|
import { http } from "@tauri-apps/api";
|
||||||
|
// api
|
||||||
|
import TGApi from "../api/TGApi";
|
||||||
|
// utils
|
||||||
|
import TGUtils from "../utils/TGUtils";
|
||||||
|
// types
|
||||||
|
import { type UserResponse } from "../../plugins/Mys/interface/user";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 根据 cookie 获取用户信息
|
||||||
|
* @since Alpha v0.2.0
|
||||||
|
* @param {string} cookie_token cookie token
|
||||||
|
* @param {string} account_id 用户 account_id
|
||||||
|
* @returns {Promise<BTMuli.User.Base.BriefInfo | BTMuli.Genshin.Base.Response>}
|
||||||
|
*/
|
||||||
|
export async function getUserInfoByCookie (cookie_token: string, account_id: string): Promise<BTMuli.User.Base.BriefInfo | BTMuli.Genshin.Base.Response> {
|
||||||
|
const cookie = {
|
||||||
|
cookie_token,
|
||||||
|
account_id,
|
||||||
|
};
|
||||||
|
const url = TGApi.GameData.byCookie.getUserInfo;
|
||||||
|
const params = { gids: 2 };
|
||||||
|
const header = TGUtils.User.getSignHeader(cookie, "GET", {}, "common");
|
||||||
|
return await http.fetch<UserResponse>(url, {
|
||||||
|
method: "GET",
|
||||||
|
headers: header,
|
||||||
|
body: http.Body.json(params),
|
||||||
|
}).then((res) => {
|
||||||
|
console.log(res);
|
||||||
|
if (res.data.retcode !== 0) return res.data;
|
||||||
|
const info = res.data.data.user_info;
|
||||||
|
return {
|
||||||
|
nickname: info.nickname,
|
||||||
|
uid: info.uid,
|
||||||
|
avatar: info.avatar,
|
||||||
|
desc: info.introduce,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -35,17 +35,11 @@ async function initCookie (ticket: string, uid: string): Promise<void> {
|
|||||||
if (Array.isArray(tokenRes)) {
|
if (Array.isArray(tokenRes)) {
|
||||||
const lToken = tokenRes.find((item) => item.name === "ltoken");
|
const lToken = tokenRes.find((item) => item.name === "ltoken");
|
||||||
const sToken = tokenRes.find((item) => item.name === "stoken");
|
const sToken = tokenRes.find((item) => item.name === "stoken");
|
||||||
if (lToken) {
|
if (lToken) cookie.ltoken = lToken.token;
|
||||||
await TGSqlite.saveAppData("ltoken", lToken.token);
|
if (sToken) cookie.stoken = sToken.token;
|
||||||
cookie.ltoken = lToken.token;
|
|
||||||
}
|
|
||||||
if (sToken) {
|
|
||||||
await TGSqlite.saveAppData("stoken", sToken.token);
|
|
||||||
cookie.stoken = sToken.token;
|
|
||||||
}
|
|
||||||
const cookieToken = await getCookieTokenBySToken(uid, cookie.stoken);
|
const cookieToken = await getCookieTokenBySToken(uid, cookie.stoken);
|
||||||
if (typeof cookieToken === "string") cookie.cookie_token = cookieToken;
|
if (typeof cookieToken === "string") cookie.cookie_token = cookieToken;
|
||||||
const mid = await verifyLToken(cookie.ltoken, cookie.ltuid, cookie.stoken);
|
const mid = await verifyLToken(cookie.ltoken, cookie.ltuid);
|
||||||
if (typeof mid === "string") cookie.mid = mid;
|
if (typeof mid === "string") cookie.mid = mid;
|
||||||
await TGSqlite.saveAppData("cookie", JSON.stringify(cookie));
|
await TGSqlite.saveAppData("cookie", JSON.stringify(cookie));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { getAnnoCard } from "./getAnnoCard";
|
import { getAnnoCard } from "./getAnnoCard";
|
||||||
import { getRequestHeader } from "./getRequestHeader";
|
import { getRequestHeader, getRequestSignHeader } from "./getRequestHeader";
|
||||||
import { parseAnnoContent } from "./parseAnno";
|
import { parseAnnoContent } from "./parseAnno";
|
||||||
import { transCookie, getServerByUid } from "./tools";
|
import { transCookie, getServerByUid } from "./tools";
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@ const TGUtils = {
|
|||||||
},
|
},
|
||||||
User: {
|
User: {
|
||||||
getHeader: getRequestHeader,
|
getHeader: getRequestHeader,
|
||||||
|
getSignHeader: getRequestSignHeader,
|
||||||
},
|
},
|
||||||
Tools: {
|
Tools: {
|
||||||
transCookie,
|
transCookie,
|
||||||
|
|||||||
@@ -40,19 +40,36 @@ function getRandomNumber (min: number, max: number): number {
|
|||||||
return Math.floor(Math.random() * (max - min + 1) + min);
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 获取随机字符串
|
||||||
|
* @since Alpha v0.2.0
|
||||||
|
* @param {number} length 字符串长度
|
||||||
|
* @returns {string} 随机字符串
|
||||||
|
*/
|
||||||
|
export function getRandomString (length: number): string {
|
||||||
|
const str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
|
let res = "";
|
||||||
|
for (let i = 0; i < length; i++) {
|
||||||
|
res += str.charAt(Math.floor(Math.random() * str.length));
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 获取 ds
|
* @description 获取 ds
|
||||||
* @since Alpha v0.2.0
|
* @since Alpha v0.2.0
|
||||||
* @version 2.49.1
|
* @version 2.49.1
|
||||||
* @param {string} saltType salt 类型
|
|
||||||
* @param {string} method 请求方法
|
* @param {string} method 请求方法
|
||||||
* @param {string} data 请求数据
|
* @param {string} data 请求数据
|
||||||
|
* @param {string} saltType salt 类型
|
||||||
|
* @param {boolean} isSign 是否为签名
|
||||||
* @returns {string} ds
|
* @returns {string} ds
|
||||||
*/
|
*/
|
||||||
function getDS (method: string, data: string, saltType: string): string {
|
function getDS (method: string, data: string, saltType: string, isSign: boolean = false): string {
|
||||||
const salt = getSalt(saltType);
|
const salt = getSalt(saltType);
|
||||||
const time = Math.floor(Date.now() / 1000).toString();
|
const time = Math.floor(Date.now() / 1000).toString();
|
||||||
const random = getRandomNumber(100000, 200000).toString();
|
let random = getRandomNumber(100000, 200000).toString();
|
||||||
|
if (isSign) random = getRandomString(6);
|
||||||
const body = method === "GET" ? "" : data;
|
const body = method === "GET" ? "" : data;
|
||||||
const query = method === "GET" ? data : "";
|
const query = method === "GET" ? data : "";
|
||||||
const hashStr = `salt=${salt}&t=${time}&r=${random}&b=${body}&q=${query}`;
|
const hashStr = `salt=${salt}&t=${time}&r=${random}&b=${body}&q=${query}`;
|
||||||
@@ -80,8 +97,28 @@ export function getRequestHeader (cookie: Record<string, string>, method: string
|
|||||||
"User-Agent": TGConstant.BBS.USER_AGENT,
|
"User-Agent": TGConstant.BBS.USER_AGENT,
|
||||||
"x-rpc-app_version": TGConstant.BBS.VERSION,
|
"x-rpc-app_version": TGConstant.BBS.VERSION,
|
||||||
"x-rpc-client_type": "5",
|
"x-rpc-client_type": "5",
|
||||||
Referer: "https://webstatic.mihoyo.com/",
|
Referer: TGConstant.BBS.REFERER,
|
||||||
DS: ds,
|
DS: ds,
|
||||||
Cookie: transCookie(cookie),
|
Cookie: transCookie(cookie),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 获取签名请求头
|
||||||
|
* @since Alpha v0.2.0
|
||||||
|
* @param {Record<string, string>} cookie cookie
|
||||||
|
* @param {string} method 请求方法
|
||||||
|
* @param {Record<string, string|number>} data 请求数据
|
||||||
|
* @param {string} saltType salt 类型
|
||||||
|
* @returns {Record<string, string>} 请求头
|
||||||
|
*/
|
||||||
|
export function getRequestSignHeader (cookie: Record<string, string>, method: string, data: Record<string, string | number>, saltType: string): Record<string, string> {
|
||||||
|
return {
|
||||||
|
"User-Agent": TGConstant.BBS.USER_AGENT,
|
||||||
|
"x-rpc-app_version": TGConstant.BBS.VERSION,
|
||||||
|
"x-rpc-client_type": "5",
|
||||||
|
Referer: TGConstant.BBS.REFERER,
|
||||||
|
DS: getDS(method, transParams(data), saltType, true),
|
||||||
|
Cookie: transCookie(cookie),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,21 +27,6 @@ export function decodeRegExp (data: string): string {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description 获取随机字符串
|
|
||||||
* @since Alpha v0.2.0
|
|
||||||
* @param {number} length 字符串长度
|
|
||||||
* @returns {string} 随机字符串
|
|
||||||
*/
|
|
||||||
export function getRandomString (length: number): string {
|
|
||||||
const str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
||||||
let res = "";
|
|
||||||
for (let i = 0; i < length; i++) {
|
|
||||||
res += str[Math.floor(Math.random() * str.length)];
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 将 cookie 对象转换为字符串
|
* @description 将 cookie 对象转换为字符串
|
||||||
* @since Alpha v0.2.0
|
* @since Alpha v0.2.0
|
||||||
|
|||||||
Reference in New Issue
Block a user