✏️ 完善极验类型

This commit is contained in:
BTMuli
2023-10-09 19:06:24 +08:00
parent 5272108e82
commit 93fe738c97
7 changed files with 99 additions and 70 deletions

View File

@@ -60,6 +60,7 @@
"pinia-plugin-persistedstate": "^3.2.0",
"qrcode.vue": "^3.4.1",
"tauri-plugin-sql-api": "github:tauri-apps/tauri-plugin-sql#v1",
"uuid": "^9.0.1",
"vue": "^3.3.4",
"vue-echarts": "^6.6.1",
"vue-json-viewer": "^3.0.4",
@@ -72,6 +73,7 @@
"@types/color-convert": "^2.0.1",
"@types/js-md5": "^0.7.0",
"@types/node": "^20.7.1",
"@types/uuid": "^9.0.5",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"@vitejs/plugin-vue": "^4.3.4",

15
pnpm-lock.yaml generated
View File

@@ -38,6 +38,9 @@ dependencies:
tauri-plugin-sql-api:
specifier: github:tauri-apps/tauri-plugin-sql#v1
version: github.com/tauri-apps/tauri-plugin-sql/1c79471feb06366fe1c11cb1cb6c67bcdb80c215
uuid:
specifier: ^9.0.1
version: 9.0.1
vue:
specifier: ^3.3.4
version: 3.3.4
@@ -70,6 +73,9 @@ devDependencies:
'@types/node':
specifier: ^20.7.1
version: 20.7.1
'@types/uuid':
specifier: ^9.0.5
version: 9.0.5
'@typescript-eslint/eslint-plugin':
specifier: ^6.7.3
version: 6.7.3(@typescript-eslint/parser@6.7.3)(eslint@8.50.0)(typescript@5.2.2)
@@ -724,6 +730,10 @@ packages:
resolution: {integrity: sha512-7aqorHYgdNO4DM36stTiGO3DvKoex9TQRwsJU6vMaFGyqpBA1MNZkz+PG3gaNUPpTAOYhT1WR7M1JyA3fbS9Cw==}
dev: true
/@types/uuid@9.0.5:
resolution: {integrity: sha512-xfHdwa1FMJ082prjSJpoEI57GZITiQz10r3vEJCHa2khEFQjKy91aWKz6+zybzssCvXUwE1LQWgWVwZ4nYUvHQ==}
dev: true
/@types/yauzl@2.10.0:
resolution: {integrity: sha512-Cn6WYCm0tXv8p6k+A8PvbDG763EDpBoTzHdA+Q/MF6H3sapGjCm9NzoaJncJS9tUKSuCoDs9XHxYYsQDgxR6kw==}
requiresBuild: true
@@ -4751,6 +4761,11 @@ packages:
base64-arraybuffer: 1.0.2
dev: false
/uuid@9.0.1:
resolution: {integrity: sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==}
hasBin: true
dev: false
/validate-npm-package-license@3.0.4:
resolution: {integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==}
dependencies:

View File

@@ -44,43 +44,52 @@ watch(show, () => {
}
});
async function displayBox(): Promise<boolean> {
const cookie = userStore.getCookieGroup3();
const res = await TGRequest.User.verification.get(cookie.ltoken, cookie.ltuid);
if ("retcode" in res) {
async function displayBox(): Promise<void> {
const cookieGet = userStore.getCookieGroup3();
const resGet = await TGRequest.User.verification.get(cookieGet.ltoken, cookieGet.ltuid);
if ("retcode" in resGet) {
showSnackbar({
text: `[${res.retcode}]${res.message}`,
text: `[${resGet.retcode}]${resGet.message}`,
color: "error",
});
return false;
return;
}
show.value = true;
return await new Promise((resolve) => {
// @ts-expect-error Cannot find name 'initGeetest'.
initGeetest(
{
gt: res.gt,
challenge: res.challenge,
offline: false,
new_captcha: true,
product: "custom",
area: "#verify",
width: "250px",
},
(captchaObj: TGApp.BBS.Geetest.GeetestCaptcha) => {
geetestRef.value.innerHTML = "";
captchaObj.appendTo("#geetest");
captchaObj.onSuccess(async () => {
const validate = captchaObj.getValidate();
const res = TGRequest.User.verification.verify(userStore.cookie, validate);
resolve(res);
});
captchaObj.onClose(() => {
show.value = false;
});
},
);
});
initGeetest(
{
gt: resGet.gt,
challenge: resGet.challenge,
offline: false,
new_captcha: true,
product: "custom",
area: "#verify",
width: "250px",
},
(captchaObj: TGApp.BBS.Geetest.GeetestCaptcha) => {
geetestRef.value.innerHTML = "";
captchaObj.appendTo("#geetest");
// @eslint-ignore-next-line @typescript-eslint/no-misused-promises
captchaObj.onSuccess(async () => {
const validate = captchaObj.getValidate();
const cookie = {
account_id: userStore.cookie.account_id,
cookie_token: userStore.cookie.cookie_token,
ltoken: userStore.cookie.ltoken,
ltuid: userStore.cookie.ltuid,
};
const resVerify = await TGRequest.User.verification.verify(cookie, validate);
if (resVerify.retcode !== 0) {
showSnackbar({
text: `[${resVerify.retcode}]${resVerify.message}`,
color: "error",
});
}
});
captchaObj.onClose(() => {
show.value = false;
});
},
);
}
defineExpose({

View File

@@ -30,8 +30,7 @@ onMounted(async () => {
});
async function getGC(): Promise<void> {
const res = await showGeetest();
console.log(res);
await showGeetest();
}
</script>
<style lang="css" scoped>

View File

@@ -1,7 +1,6 @@
/**
* @file types BBS Geetest.d.ts
* @description BBS 极验相关类型定义文件
* @author BTMuli<bt-muli@outlook.com>
* @since Beta v0.3.3
*/
@@ -58,7 +57,7 @@ declare namespace TGApp.BBS.Geetest {
* @property {boolean} new_captcha - 极验验证 new_captcha
* @property {string} product - 极验验证 product
* @property {string} width - 极验验证 width
* @property {boolean} https - 极验验证 https
* @property {string} area - 极验验证 area
* @return InitGeetestParams
*/
export interface InitGeetestParams {
@@ -68,17 +67,15 @@ declare namespace TGApp.BBS.Geetest {
new_captcha: boolean;
product: string;
width: string;
https: boolean;
area: string;
}
/**
* @description Geetest 插件 captchaObj
* @since Beta v0.3.3
* @todo 完善
* @interface GeetestCaptcha
* @property {Function} appendTo
* @property {Function} getValidate
* @property {Function} onRefresh
* @property {Function} onSuccess
* @property {Function} onClose
* @return GeetestCaptcha
@@ -86,7 +83,6 @@ declare namespace TGApp.BBS.Geetest {
export interface GeetestCaptcha {
appendTo: (selector: string) => void;
getValidate: () => GeetestValidate;
onRefresh: (callback: () => void) => GeetestCaptcha;
onSuccess: (callback: () => void) => void;
onClose: (callback: () => void) => void;
}
@@ -106,3 +102,14 @@ declare namespace TGApp.BBS.Geetest {
geetest_seccode: string;
}
}
/**
* @description 设置全局 initGeetest 方法
* @param {TGApp.BBS.Geetest.InitGeetestParams} params 极验验证的请求方法-请求参数
* @param callback 极验验证的请求方法-回调函数
* @return {void}
*/
declare function initGeetest(
params: TGApp.BBS.Geetest.InitGeetestParams,
callback: (captchaObj: TGApp.BBS.Geetest.GeetestCaptcha) => void,
): void;

View File

@@ -6,11 +6,24 @@
import TGUtils from "../utils/TGUtils";
import { http } from "@tauri-apps/api";
import showSnackbar from "../../components/func/snackbar";
import TGConstant from "../constant/TGConstant";
import { v4 } from "uuid";
/**
* @description 获取 deviceId
* @since Beta v0.3.3
* @return {string} deviceId
*/
function getDeviceId(): string {
const local = localStorage.getItem("deviceId");
if (local) return local;
const id = v4();
localStorage.setItem("deviceId", id);
return id;
}
/**
* @description 发起验证请求
* @since Beta v0.3.3
* @param {string} Ltoken ltoken
* @param {string} Ltuid ltuid
* @return {Promise<TGApp.Plugins.Geetest.getData|TGApp.BBS.Response.Base>} 验证码参数
@@ -44,48 +57,32 @@ export async function getVerification(
* @todo 待测试
* @param {Record<string, string>} cookie cookie
* @param {TGApp.BBS.Geetest.GeetestValidate} validate 验证码参数
* @return {Promise<boolean>} 提交结果
* @return {Promise<TGApp.BBS.Response.Base>} 提交结果
*/
export async function submitVerification(
cookie: Record<string, string>,
validate: TGApp.BBS.Geetest.GeetestValidate,
): Promise<boolean> {
): Promise<TGApp.BBS.Response.Base> {
const url = "https://api-takumi-record.mihoyo.com/game_record/app/card/wapi/verifyVerification";
const dataRaw = {
const data = {
geetest_challenge: validate.geetest_challenge,
geetest_validate: validate.geetest_validate,
geetest_seccode: validate.geetest_seccode,
};
const data = JSON.stringify(dataRaw);
const header = TGUtils.User.getHeader(cookie, "POST", data, "common", false);
header["x-rpc-client_type"] = "2";
const header = TGUtils.User.getHeader(cookie, "POST", data, "common");
const reqHeader = {
...header,
"x-rpc-app_id": TGConstant.BBS.APP_ID,
"x-rpc-challenge": validate.geetest_challenge,
"x-rpc-validate": validate.geetest_validate,
"x-rpc-seccode": validate.geetest_seccode,
"x-rpc-game_biz": "hk4e_cn",
"x-rpc-sdk_version": "1.3.1.2",
"x-rpc-device_id": "FA47BE878C143D2FE18785B660EF114A",
"x-rpc-device_id": getDeviceId(),
"x-rpc-page": "3.1.3_#/ys",
};
console.log(reqHeader);
return await http
.fetch<TGApp.BBS.Response.Base>(url, {
method: "POST",
headers: reqHeader,
body: http.Body.json(dataRaw),
body: http.Body.json(data),
})
.then((res) => {
console.log(res.rawHeaders);
if (res.data.retcode !== 0) {
showSnackbar({
text: `[${res.data.retcode}] ${res.data.message}`,
color: "error",
});
console.log(res.data);
return false;
}
return true;
return res.data;
});
}

View File

@@ -101,12 +101,12 @@ export function getRequestHeader(
ds = getDS(method, transParams(data), saltType, isSign);
}
return {
"User-Agent": TGConstant.BBS.USER_AGENT,
"user-agent": TGConstant.BBS.USER_AGENT,
"x-rpc-app_version": TGConstant.BBS.VERSION,
"x-rpc-client_type": "5",
"x-requested-with": "com.mihoyo.hyperion",
Referer: "https://webstatic.mihoyo.com",
DS: ds,
Cookie: transCookie(cookie),
referer: "https://webstatic.mihoyo.com",
ds,
cookie: transCookie(cookie),
};
}