成功完成签到&战绩页面渲染

This commit is contained in:
BTMuli
2023-10-24 21:51:37 +08:00
parent 1914261e80
commit 16999f2e58
4 changed files with 73 additions and 55 deletions

View File

@@ -13,7 +13,8 @@ fn get_mhy_client_url(func: String) -> WindowUrl {
.parse() .parse()
.unwrap(); .unwrap();
} else if func == "game_record" { } else if func == "game_record" {
url_res = "https://webstatic.mihoyo.com/app/community-game-records/index.html".parse().unwrap(); url_res =
"https://webstatic.mihoyo.com/app/community-game-records/index.html?bbs_presentation_style=fullscreen".parse().unwrap();
} }
return WindowUrl::External(url_res); return WindowUrl::External(url_res);
} }

View File

@@ -93,6 +93,11 @@
"domain": "webstatic.mihoyo.com", "domain": "webstatic.mihoyo.com",
"windows": ["mhy_client"], "windows": ["mhy_client"],
"enableTauriAPI": true "enableTauriAPI": true
},
{
"domain": "api-takumi-record.mihoyo.com",
"windows": ["mhy_client"],
"enableTauriAPI": true
} }
], ],
"csp": null "csp": null

View File

@@ -9,6 +9,7 @@ import type { Event } from "@tauri-apps/api/event";
import { WebviewWindow } from "@tauri-apps/api/window"; import { WebviewWindow } from "@tauri-apps/api/window";
import Md5 from "js-md5"; import Md5 from "js-md5";
import { getDeviceID } from "./toolFunc";
import { useUserStore } from "../store/modules/user"; import { useUserStore } from "../store/modules/user";
import TGConstant from "../web/constant/TGConstant"; import TGConstant from "../web/constant/TGConstant";
import TGRequest from "../web/request/TGRequest"; import TGRequest from "../web/request/TGRequest";
@@ -84,7 +85,11 @@ class TGClient {
*/ */
async hideSideBar(): Promise<void> { async hideSideBar(): Promise<void> {
const executeJS = const executeJS =
"javascript:(function() {let st = document.createElement('style');st.innerHTML = '::-webkit-scrollbar{display:none}';document.querySelector('body').appendChild(st);})();"; "javascript:(function(){" +
"let st = document.createElement('style');" +
"st.innerHTML = '::-webkit-scrollbar{display:none}';" +
"document.querySelector('body').appendChild(st);" +
"})();";
await invoke("execute_js", { label: "mhy_client", js: executeJS }); await invoke("execute_js", { label: "mhy_client", js: executeJS });
} }
@@ -102,7 +107,6 @@ class TGClient {
await invoke<InvokeArg>("create_mhy_client", { func }); await invoke<InvokeArg>("create_mhy_client", { func });
this.window = WebviewWindow.getByLabel("mhy_client"); this.window = WebviewWindow.getByLabel("mhy_client");
await this.window?.show(); await this.window?.show();
await this.hideSideBar();
} }
/** /**
@@ -120,10 +124,11 @@ class TGClient {
await this.getStatusBarHeight(callback); await this.getStatusBarHeight(callback);
break; break;
case "getCookieInfo": case "getCookieInfo":
await this.getCookieInfo(callback); await this.getCookieInfo(payload, callback);
break; break;
case "getActionTicket": case "getActionTicket":
await this.getActionTicket(payload, callback); await this.getActionTicket(payload, callback);
await this.hideSideBar();
break; break;
case "getHTTPRequestHeaders": case "getHTTPRequestHeaders":
await this.getHTTPRequestHeaders(callback); await this.getHTTPRequestHeaders(callback);
@@ -138,10 +143,11 @@ class TGClient {
await this.getUserInfo(callback); await this.getUserInfo(callback);
break; break;
case "configure_share": case "configure_share":
await this.callback(callback ?? "");
break; break;
// getNotificationSettings
default: default:
console.warn(`[${arg.windowLabel}] ${arg.payload}`); console.warn(`[${arg.windowLabel}] ${arg.payload}`);
await this.hideSideBar();
} }
} }
@@ -150,12 +156,17 @@ class TGClient {
* @since Beta v0.3.4 * @since Beta v0.3.4
* @desc 回调函数 * @desc 回调函数
* @param {string} callback - 回调函数名 * @param {string} callback - 回调函数名
* @param {string} payload - 回调函数参 * @param {object} data - 回调数
* @returns {void} - 无返回值 * @returns {void} - 无返回值
*/ */
async callback(callback: string, payload?: string): Promise<void> { async callback(callback: string, data: object): Promise<void> {
const js = `javascript:mhyWebBridge("${callback}", ${payload ?? ""});`; const response: TGApp.BBS.Response.Base = {
console.log(js); retcode: 0,
message: "success",
data: data ?? {},
};
const js = `javascript:mhyWebBridge("${callback}", ${JSON.stringify(response)});`;
console.info(`[callback] ${js}`);
await invoke("create_mhy_client", { func: "execute_js" }); await invoke("create_mhy_client", { func: "execute_js" });
await invoke("execute_js", { label: "mhy_client", js }); await invoke("execute_js", { label: "mhy_client", js });
} }
@@ -171,29 +182,25 @@ class TGClient {
const data = { const data = {
statusBarHeight: 0, statusBarHeight: 0,
}; };
await this.callback(callback, JSON.stringify(data)); await this.callback(callback, data);
} }
/** /**
* @func getCookieInfo * @func getCookieInfo
* @since Beta v0.3.3 * @since Beta v0.3.4
* @desc 获取米游社客户端的 cookie * @desc 获取米游社客户端的 cookie
* @param {unknown} payload - 请求参数
* @param {string} callback - 回调函数名 * @param {string} callback - 回调函数名
* @returns {void} - 无返回值 * @returns {void} - 无返回值
*/ */
async getCookieInfo(callback: string): Promise<void> { async getCookieInfo(payload: unknown, callback: string): Promise<void> {
const user = useUserStore(); const user = useUserStore();
// todo这边还不清楚返回结构 const data = {
const cookie = { ltoken: user.cookie.ltoken,
data: { ltuid: user.cookie.ltuid,
ltuid: user.cookie.ltuid, login_ticket: "",
ltoken: user.cookie.ltoken,
stuid: user.cookie.stuid,
stoken: user.cookie.stoken,
mid: user.cookie.mid,
},
}; };
await this.callback(callback, JSON.stringify(cookie)); await this.callback(callback, data);
} }
/** /**
@@ -210,13 +217,13 @@ class TGClient {
const uid = user.getCurAccount().gameUid; const uid = user.getCurAccount().gameUid;
const mid = user.cookie.mid; const mid = user.cookie.mid;
const stoken = user.cookie.stoken; const stoken = user.cookie.stoken;
const actionTicket = await TGRequest.User.bySToken.getActionTicket( const ActionTicket = await TGRequest.User.bySToken.getActionTicket(
actionType, actionType,
stoken, stoken,
mid, mid,
uid, uid,
); );
await this.callback(callback, JSON.stringify(actionTicket)); await this.callback(callback, ActionTicket.data);
} }
/** /**
@@ -227,16 +234,12 @@ class TGClient {
* @returns {void} - 无返回值 * @returns {void} - 无返回值
*/ */
async getHTTPRequestHeaders(callback: string): Promise<void> { async getHTTPRequestHeaders(callback: string): Promise<void> {
console.log("getHTTPRequestHeaders"); const data = {
const header = {
"x-rpc-client_type": "5", "x-rpc-client_type": "5",
"x-rpc-device_id": localStorage.getItem("device_id") ?? "", "x-rpc-device_id": getDeviceID(),
"x-rpc-app_version": TGConstant.BBS.VERSION, "x-rpc-app_version": TGConstant.BBS.VERSION,
}; };
const data = { await this.callback(callback, data);
headers: header,
};
await this.callback(callback, JSON.stringify(data));
} }
/** /**
@@ -247,17 +250,14 @@ class TGClient {
* @returns {void} - 无返回值 * @returns {void} - 无返回值
*/ */
async getDS(callback: string): Promise<void> { async getDS(callback: string): Promise<void> {
console.log("getDS");
const salt = TGConstant.Salt.LK2; const salt = TGConstant.Salt.LK2;
const time = Math.floor(Date.now() / 1000).toString(); const time = Math.floor(Date.now() / 1000).toString();
const random = TGUtils.Tools.getRandomString(6); const random = TGUtils.Tools.getRandomString(6);
const ds = Md5.md5.update(`salt=${salt}&t=${time}&r=${random}`).hex(); const check = Md5.md5.update(`salt=${salt}&t=${time}&r=${random}`).hex();
const data = { const data = {
data: { DS: `${time},${random},${check}`,
DS: `${time},${random},${ds}`,
},
}; };
await this.callback(callback, JSON.stringify(data)); await this.callback(callback, data);
} }
/** /**
@@ -270,19 +270,16 @@ class TGClient {
*/ */
async getDS2(payload: any, callback: string): Promise<void> { async getDS2(payload: any, callback: string): Promise<void> {
const { query, body } = payload; const { query, body } = payload;
const salt = TGConstant.Salt.LK2; const salt = TGConstant.Salt.X4;
const time = Math.floor(Date.now() / 1000).toString(); const time = Math.floor(Date.now() / 1000).toString();
const random = TGUtils.Tools.getRandomNumber(100000, 200000).toString(); const random = TGUtils.Tools.getRandomNumber(100001, 200000).toString();
const dataB = TGUtils.Tools.transParams(body); const dataB = TGUtils.Tools.transParams(body);
const dataQ = TGUtils.Tools.transParams(query); const dataQ = TGUtils.Tools.transParams(query);
const ds = Md5.md5.update(`salt=${salt}&t=${time}&r=${random}&b=${dataB}&q=${dataQ}`).hex(); const check = Md5.md5.update(`salt=${salt}&t=${time}&r=${random}&b=${dataB}&q=${dataQ}`).hex();
const data = { const data = {
data: { DS: `${time},${random},${check}`,
DS: `${time},${random},${ds}`,
},
}; };
console.log(data); await this.callback(callback, data);
await this.callback(callback, JSON.stringify(data));
} }
/** /**
@@ -301,14 +298,14 @@ class TGClient {
console.error(`[${callback}] ${userInfo.message}`); console.error(`[${callback}] ${userInfo.message}`);
return; return;
} }
const data = { // const data = {
id: userInfo.uid, // id: userInfo.uid,
gender: userInfo.gender, // gender: userInfo.gender,
nickname: userInfo.nickname, // nickname: userInfo.nickname,
introduce: userInfo.introduce, // introduce: userInfo.introduce,
avatar_url: userInfo.avatar_url, // avatar_url: userInfo.avatar_url,
}; // };
await this.callback(callback, JSON.stringify(data)); await this.callback(callback, userInfo);
} }
} }

View File

@@ -1,10 +1,11 @@
/** /**
* @file utils toolFunc.ts * @file utils toolFunc.ts
* @description 一些工具函数 * @description 一些工具函数
* @author BTMuli <bt-muli@outlook.com> * @since Beta v0.3.4
* @since Beta v0.3.0
*/ */
import { v4 } from "uuid";
/** /**
* @description 时间戳转换为时间字符串 * @description 时间戳转换为时间字符串
* @returns {string} 时间字符串 d天 hh:mm:ss * @returns {string} 时间字符串 d天 hh:mm:ss
@@ -19,3 +20,17 @@ export function stamp2LastTime(time: number): string {
.toFixed(0) .toFixed(0)
.padStart(2, "0")}:${second.toFixed(0).padStart(2, "0")}`; .padStart(2, "0")}:${second.toFixed(0).padStart(2, "0")}`;
} }
/**
* @description 获取 deviceID
* @since Beta v0.3.4
* @returns {string} deviceID
*/
export function getDeviceID(): string {
let deviceID = localStorage.getItem("deviceID");
if (deviceID === null) {
deviceID = v4();
localStorage.setItem("deviceID", deviceID);
}
return deviceID;
}