Skip to content

Commit

Permalink
✏️ 完善极验类型
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Oct 9, 2023
1 parent 5272108 commit 93fe738
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 70 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 41 additions & 32 deletions src/components/func/geetest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
3 changes: 1 addition & 2 deletions src/pages/common/Test.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
19 changes: 13 additions & 6 deletions src/types/BBS/Geetest.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* @file types BBS Geetest.d.ts
* @description BBS 极验相关类型定义文件
* @author BTMuli<bt-muli@outlook.com>
* @since Beta v0.3.3
*/

Expand Down Expand Up @@ -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 {
Expand All @@ -68,25 +67,22 @@ 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
*/
export interface GeetestCaptcha {
appendTo: (selector: string) => void;
getValidate: () => GeetestValidate;
onRefresh: (callback: () => void) => GeetestCaptcha;
onSuccess: (callback: () => void) => void;
onClose: (callback: () => void) => void;
}
Expand All @@ -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;
49 changes: 23 additions & 26 deletions src/web/request/operVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>} 验证码参数
Expand Down Expand Up @@ -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;
});
}
8 changes: 4 additions & 4 deletions src/web/utils/getRequestHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}

0 comments on commit 93fe738

Please sign in to comment.