mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-05-07 00:15:48 +08:00
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* @file component/func/geetest.ts
|
||||
* @description 封装自定义 geetest 组件,通过函数调用的方式,简化 geetest 的使用
|
||||
* @since Beta v0.6.6
|
||||
* @since Beta v0.7.1
|
||||
*/
|
||||
|
||||
import { h, render } from "vue";
|
||||
import type { ComponentInternalInstance, VNode } from "vue";
|
||||
import { h, render } from "vue";
|
||||
|
||||
import geetest from "./geetest.vue";
|
||||
|
||||
@@ -21,12 +21,12 @@ const geetestId = "tg-func-geetest";
|
||||
interface GeetestInstance extends ComponentInternalInstance {
|
||||
exposeProxy: {
|
||||
displayBox: (
|
||||
props: TGApp.Plugins.Mys.Geetest.reqResp,
|
||||
) => Promise<TGApp.Plugins.Mys.Geetest.validateResp | false>;
|
||||
props: TGApp.BBS.Geetest.CreateRes,
|
||||
) => Promise<TGApp.BBS.Geetest.GeetestVerifyRes | false>;
|
||||
};
|
||||
}
|
||||
|
||||
function renderBox(props: TGApp.Plugins.Mys.Geetest.reqResp): VNode {
|
||||
function renderBox(props: TGApp.BBS.Geetest.CreateRes): VNode {
|
||||
const container = document.createElement("div");
|
||||
container.id = geetestId;
|
||||
const boxVNode: VNode = h(geetest, props);
|
||||
@@ -39,14 +39,14 @@ let geetestInstance: VNode;
|
||||
|
||||
/**
|
||||
* @function showGeetest
|
||||
* @since Beta v0.5.1
|
||||
* @since Beta v0.7.1
|
||||
* @description 弹出 geetest 验证
|
||||
* @param {TGApp.Plugins.Mys.Geetest.reqResp} props geetest 验证的参数
|
||||
* @return {Promise<TGApp.Plugins.Mys.Geetest.validateResp>} 验证成功返回验证数据
|
||||
* @param {TGApp.BBS.Geetest.CreateRes} props geetest 验证的参数
|
||||
* @return {Promise<TGApp.BBS.Geetest.GeetestVerifyRes|false>} 验证成功返回验证数据
|
||||
*/
|
||||
async function showGeetest(
|
||||
props: TGApp.Plugins.Mys.Geetest.reqResp,
|
||||
): Promise<TGApp.Plugins.Mys.Geetest.validateResp | false> {
|
||||
props: TGApp.BBS.Geetest.CreateRes,
|
||||
): Promise<TGApp.BBS.Geetest.GeetestVerifyRes | false> {
|
||||
if (geetestInstance !== undefined) {
|
||||
const boxVue = <GeetestInstance>geetestInstance.component;
|
||||
return boxVue.exposeProxy.displayBox(props);
|
||||
|
||||
@@ -40,14 +40,14 @@ watch(
|
||||
);
|
||||
|
||||
declare function initGeetest(
|
||||
params: TGApp.Plugins.Mys.Geetest.InitGeetestParams,
|
||||
callback: (captchaObj: TGApp.Plugins.Mys.Geetest.GeetestCaptcha) => void,
|
||||
params: TGApp.BBS.Geetest.InitGeetestParams,
|
||||
callback: (captchaObj: TGApp.BBS.Geetest.GeetestCaptcha) => void,
|
||||
): void;
|
||||
|
||||
async function displayBox(
|
||||
props: TGApp.Plugins.Mys.Geetest.reqResp,
|
||||
): Promise<TGApp.Plugins.Mys.Geetest.validateResp | false> {
|
||||
return await new Promise<TGApp.Plugins.Mys.Geetest.validateResp>((resolve) => {
|
||||
props: TGApp.BBS.Geetest.CreateRes,
|
||||
): Promise<TGApp.BBS.Geetest.GeetestVerifyRes | false> {
|
||||
return await new Promise<TGApp.BBS.Geetest.GeetestVerifyRes>((resolve) => {
|
||||
initGeetest(
|
||||
{
|
||||
gt: props.gt,
|
||||
@@ -58,7 +58,7 @@ async function displayBox(
|
||||
area: "#verify",
|
||||
width: "250px",
|
||||
},
|
||||
(captchaObj: TGApp.Plugins.Mys.Geetest.GeetestCaptcha) => {
|
||||
(captchaObj: TGApp.BBS.Geetest.GeetestCaptcha) => {
|
||||
if (geetestEl.value === null) return;
|
||||
geetestEl.value.innerHTML = "";
|
||||
captchaObj.appendTo("#geetest");
|
||||
|
||||
@@ -37,6 +37,7 @@ import { ref, shallowRef } from "vue";
|
||||
import { useUserStore } from "@/store/modules/user.js";
|
||||
import TGLogger from "@/utils/TGLogger.js";
|
||||
import apiHubReq from "@/web/request/apiHubReq.js";
|
||||
import miscReq from "@/web/request/miscReq.js";
|
||||
import painterReq from "@/web/request/painterReq.js";
|
||||
import postReq from "@/web/request/postReq.js";
|
||||
|
||||
@@ -259,7 +260,7 @@ async function refreshState(ck: Record<string, string>): Promise<void> {
|
||||
await TGLogger.Script("[米游币任务]任务数据合并完成");
|
||||
}
|
||||
|
||||
async function autoSign(ck: Record<string, string>): Promise<void> {
|
||||
async function autoSign(ck: Record<string, string>, ch?: string): Promise<void> {
|
||||
const signFind = parseMissions.value.find((i) => i.key === "continuous_sign");
|
||||
if (!signFind) {
|
||||
await TGLogger.Script("[米游币任务]未找到打卡任务");
|
||||
@@ -270,10 +271,20 @@ async function autoSign(ck: Record<string, string>): Promise<void> {
|
||||
return;
|
||||
}
|
||||
await TGLogger.Script("[米游币任务]正在执行打卡");
|
||||
const resp = await apiHubReq.sign(ck);
|
||||
const resp = await apiHubReq.sign(ck, 2, ch);
|
||||
if (resp.retcode !== 0) {
|
||||
await TGLogger.Script(`[米游币任务]打卡失败:${resp.retcode} ${resp.message}`);
|
||||
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
|
||||
if (resp.retcode !== 1034) {
|
||||
await TGLogger.Script(`[米游币任务]打卡失败:${resp.retcode} ${resp.message}`);
|
||||
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
|
||||
return;
|
||||
}
|
||||
await TGLogger.Script(`[米游币任务]社区签到触发验证码,正在尝试验证`);
|
||||
const challenge = await miscReq.challenge(ck);
|
||||
if (challenge === false) {
|
||||
await TGLogger.Script(`[米游币任务]验证失败`);
|
||||
return;
|
||||
}
|
||||
await autoSign(ck, challenge);
|
||||
return;
|
||||
}
|
||||
await TGLogger.Script("[米游币任务]打卡成功");
|
||||
|
||||
@@ -19,19 +19,36 @@
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import showGeetest from "@comp/func/geetest.js";
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import { storeToRefs } from "pinia";
|
||||
|
||||
import takumiReq from "@/web/request/takumiReq.js";
|
||||
import { useUserStore } from "@/store/modules/user.js";
|
||||
import miscReq from "@/web/request/miscReq.js";
|
||||
|
||||
const gameToken = "LCLQ2pYLnEDh7p03ogJVxL9dZqbeLtUE";
|
||||
const uid = "249066520";
|
||||
const { cookie } = storeToRefs(useUserStore());
|
||||
|
||||
async function test(): Promise<void> {
|
||||
const resp = await takumiReq.game.stoken({ uid: uid, token: gameToken });
|
||||
if (resp.retcode !== 0) {
|
||||
if (!cookie.value) return;
|
||||
const ck: Record<string, string> = {
|
||||
stoken: cookie.value.stoken,
|
||||
stuid: cookie.value.stuid,
|
||||
mid: cookie.value.mid,
|
||||
};
|
||||
const resp = await miscReq.create(ck);
|
||||
if ("retcode" in resp) {
|
||||
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
|
||||
return;
|
||||
}
|
||||
const gtRes = await showGeetest(resp);
|
||||
console.log(gtRes);
|
||||
if (gtRes === false) return;
|
||||
const verifyResp = await miscReq.verify(gtRes, ck);
|
||||
if ("retcode" in verifyResp) {
|
||||
showSnackbar.error(`[${verifyResp.retcode}] ${verifyResp.message}`);
|
||||
return;
|
||||
}
|
||||
showSnackbar.success("验证成功");
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
|
||||
2
src/plugins/Mys/types/CaptchaLogin.d.ts
vendored
2
src/plugins/Mys/types/CaptchaLogin.d.ts
vendored
@@ -44,7 +44,7 @@ declare namespace TGApp.Plugins.Mys.CaptchaLogin {
|
||||
* @interface CaptchaAigis
|
||||
* @property {string} session_id 会话 id
|
||||
* @property {number} mmt_type mmt 类型
|
||||
* @see TGApp.Plugins.Mys.Geetest.validateResp
|
||||
* @see TGApp.BBS.Geetest.GeetestVerifyRes
|
||||
* @property {string} data 数据,为上面的序列化数据
|
||||
* @return CaptchaBody
|
||||
*/
|
||||
|
||||
@@ -1,49 +1,55 @@
|
||||
/**
|
||||
* @file plugins/Mys/types/Geetest.d.ts
|
||||
* @description Mys 插件 Geetest 类型定义文件
|
||||
* @since Beta v0.5.2
|
||||
* @file types/BBS/Geetest.d.ts
|
||||
* @description 米游社Geetest 类型定义文件
|
||||
* @since Beta v0.7.1
|
||||
*/
|
||||
|
||||
/**
|
||||
* @description Mys 插件 Geetest 类型
|
||||
* @since Beta v0.5.2
|
||||
* @namespace TGApp.Plugins.Mys.Geetest
|
||||
* @memberof TGApp.Plugins.Mys
|
||||
*/
|
||||
declare namespace TGApp.Plugins.Mys.Geetest {
|
||||
declare namespace TGApp.BBS.Geetest {
|
||||
/**
|
||||
* @description 创建验证的响应
|
||||
* @since Beta v0.7.1
|
||||
* @interface CreateResp
|
||||
* @extends TGApp.BBS.Response.BaseWithData
|
||||
* @property {CreateRes} data - 极验验证数据
|
||||
* @return CreateResp
|
||||
*/
|
||||
type CreateResp = TGApp.BBS.Response.BaseWithData<CreateRes>;
|
||||
|
||||
/**
|
||||
* @description 极验验证的响应数据
|
||||
* @since Beta v0.5.1
|
||||
* @interface reqResp
|
||||
* @since Beta v0.7.1
|
||||
* @interface CreateRes
|
||||
* @property {string} gt - 极验验证 gt
|
||||
* @property {string} challenge - 极验验证 challenge
|
||||
* @property {number} new_captcha - 极验验证 new_captcha
|
||||
* @property {number} success - 极验验证 success
|
||||
* @return reqResp
|
||||
* @return CreateRes
|
||||
*/
|
||||
interface reqResp {
|
||||
gt: string;
|
||||
challenge: string;
|
||||
new_captcha: number;
|
||||
success: number;
|
||||
}
|
||||
type CreateRes = { gt: string; challenge: string; new_captcha: number; success: number };
|
||||
|
||||
/**
|
||||
* @description 验证极验验证的响应
|
||||
* @since Beta v0.7.1
|
||||
* @interface VerifyResp
|
||||
* @extends TGApp.BBS.Response.Base
|
||||
* @property {VerifyRes} data - 极验验证数据
|
||||
* @return VerifyResp
|
||||
*/
|
||||
type VerifyResp = TGApp.BBS.Response.BaseWithData<VerifyRes>;
|
||||
|
||||
/**
|
||||
* @description 极验验证的请求数据
|
||||
* @since Beta v0.5.1
|
||||
* @interface postData
|
||||
* @since Beta v0.7.1
|
||||
* @interface VerifyRes
|
||||
* @property {string} challenge - 极验验证 challenge
|
||||
* @property {string} validate - 极验验证 validate
|
||||
* @return postData
|
||||
* @return VerifyRes
|
||||
*/
|
||||
interface postData {
|
||||
challenge: string;
|
||||
validate: string;
|
||||
}
|
||||
type VerifyRes = { challenge: string };
|
||||
|
||||
/**
|
||||
* @description 极验验证的请求方法-请求参数
|
||||
* @since Beta v0.5.1
|
||||
* @since Beta v0.7.1
|
||||
* @interface InitGeetestParams
|
||||
* @property {string} gt - 极验验证 gt
|
||||
* @property {string} challenge - 极验验证 challenge
|
||||
@@ -54,7 +60,7 @@ declare namespace TGApp.Plugins.Mys.Geetest {
|
||||
* @property {string} area - 极验验证 area
|
||||
* @return InitGeetestParams
|
||||
*/
|
||||
interface InitGeetestParams {
|
||||
type InitGeetestParams = {
|
||||
gt: string;
|
||||
challenge: string;
|
||||
offline: boolean;
|
||||
@@ -62,11 +68,11 @@ declare namespace TGApp.Plugins.Mys.Geetest {
|
||||
product: string;
|
||||
width: string;
|
||||
area: string;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Geetest 插件 captchaObj
|
||||
* @since Beta v0.5.2
|
||||
* @since Beta v0.7.1
|
||||
* @interface GeetestCaptcha
|
||||
* @property {Function} appendTo
|
||||
* @property {Function} getValidate
|
||||
@@ -75,26 +81,26 @@ declare namespace TGApp.Plugins.Mys.Geetest {
|
||||
* @property {Function} onReady
|
||||
* @return GeetestCaptcha
|
||||
*/
|
||||
interface GeetestCaptcha {
|
||||
type GeetestCaptcha = {
|
||||
appendTo: (selector: string) => void;
|
||||
getValidate: () => validateResp;
|
||||
onSuccess: (callback: () => void) => void;
|
||||
onClose: (callback: () => void) => void;
|
||||
onReady: (callback: () => void) => void;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Geetest 插件 validate
|
||||
* @since Beta v0.5.1
|
||||
* @interface validateResp
|
||||
* @since Beta v0.7.1
|
||||
* @interface GeetestVerifyRes
|
||||
* @property {string} geetest_challenge
|
||||
* @property {string} geetest_validate
|
||||
* @property {string} geetest_seccode
|
||||
* @return validateResp
|
||||
* @return GeetestVerifyRes
|
||||
*/
|
||||
interface validateResp {
|
||||
type GeetestVerifyRes = {
|
||||
geetest_challenge: string;
|
||||
geetest_validate: string;
|
||||
geetest_seccode: string;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -146,21 +146,24 @@ async function homeNew(gid: number = 2): Promise<TGApp.BBS.Navigator.Navigator[]
|
||||
|
||||
/**
|
||||
* @description 签到
|
||||
* @since Beta v0.7.0
|
||||
* @since Beta v0.7.1
|
||||
* @description **需要验证码登录获取的 Cookie**
|
||||
* @param {Record<string,string>} cookie 用户 Cookie
|
||||
* @param {string} gid
|
||||
* @param {string} challenge
|
||||
* @return {Promise<TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
async function signIn(
|
||||
cookie: Record<string, string>,
|
||||
gid: number = 2,
|
||||
challenge?: string,
|
||||
): Promise<TGApp.BBS.Response.Base> {
|
||||
const data = { gids: gid };
|
||||
const header = {
|
||||
let header: Record<string, string> = {
|
||||
...getRequestHeader(cookie, "POST", JSON.stringify(data), "X6"),
|
||||
"x-rpc-client_type": "2",
|
||||
};
|
||||
if (challenge) header = { ...header, "x-rpc-challenge": challenge };
|
||||
return await TGHttp<TGApp.BBS.Response.Base>(`${Mahbu}app/api/signIn`, {
|
||||
method: "POST",
|
||||
headers: header,
|
||||
|
||||
104
src/web/request/miscReq.ts
Normal file
104
src/web/request/miscReq.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* @file web/request/miscReq.ts
|
||||
* @description 杂项请求
|
||||
* @since Beta v0.7.1
|
||||
*/
|
||||
import showGeetest from "@comp/func/geetest.js";
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
|
||||
import TGHttp from "@/utils/TGHttp.js";
|
||||
import { getRequestHeader } from "@/web/utils/getRequestHeader.js";
|
||||
|
||||
// BBSApiMiscBaseUrl => bamBu
|
||||
const bamBu: Readonly<string> = "https://bbs-api.miyoushe.com/misc/api/";
|
||||
|
||||
/**
|
||||
* @description 创建极验验证
|
||||
* @since Beta v0.7.1
|
||||
* @param {Record<string,string>} cookie Cookie
|
||||
* @param {boolean} useK2 是否使用 K2
|
||||
* @returns {Promise<TGApp.BBS.Response.Base | TGApp.BBS.Geetest.CreateRes>}
|
||||
*/
|
||||
async function createVerification(
|
||||
cookie: Record<string, string>,
|
||||
useK2: boolean = true,
|
||||
): Promise<TGApp.BBS.Response.Base | TGApp.BBS.Geetest.CreateRes> {
|
||||
const param = { is_high: true };
|
||||
let header;
|
||||
if (useK2) {
|
||||
header = {
|
||||
...getRequestHeader(cookie, "GET", param, "K2", true),
|
||||
"x-rpc-client_type": "2",
|
||||
};
|
||||
} else header = getRequestHeader(cookie, "GET", param, "X4", true);
|
||||
const resp = await TGHttp<TGApp.BBS.Geetest.CreateResp>(`${bamBu}createVerification`, {
|
||||
method: "GET",
|
||||
headers: header,
|
||||
query: param,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 验证极验验证
|
||||
* @since Beta v0.7.1
|
||||
* @param {TGApp.BBS.Geetest.GeetestVerifyRes} data 极验验证数据
|
||||
* @param {Record<string,string>} cookie Cookie
|
||||
* @param {boolean} useK2 是否使用 K2
|
||||
* @returns {Promise<TGApp.BBS.Response.Base|string>}
|
||||
*/
|
||||
async function verifyVerification(
|
||||
data: TGApp.BBS.Geetest.GeetestVerifyRes,
|
||||
cookie: Record<string, string>,
|
||||
useK2: boolean = true,
|
||||
): Promise<TGApp.BBS.Response.Base | string> {
|
||||
let header;
|
||||
if (useK2) {
|
||||
header = {
|
||||
...getRequestHeader(cookie, "POST", JSON.stringify(data), "K2"),
|
||||
"x-rpc-client_type": "2",
|
||||
};
|
||||
} else header = getRequestHeader(cookie, "POST", JSON.stringify(data), "X4");
|
||||
const resp = await TGHttp<TGApp.BBS.Geetest.VerifyResp>(`${bamBu}verifyVerification`, {
|
||||
method: "POST",
|
||||
headers: header,
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data.challenge;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取极验验证 challenge
|
||||
* @since Beta v0.7.1
|
||||
* @param {Record<string,string>} cookie Cookie
|
||||
* @param {boolean} useK2 是否使用 K2
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async function getGeetestChallenge(
|
||||
cookie: Record<string, string>,
|
||||
useK2: boolean = false,
|
||||
): Promise<string | false> {
|
||||
const createResp = await createVerification(cookie, useK2);
|
||||
if ("retcode" in createResp) {
|
||||
showSnackbar.error(`[${createResp.retcode}] ${createResp.message}`);
|
||||
return false;
|
||||
}
|
||||
const gtRes = await showGeetest(createResp);
|
||||
if (!gtRes) return false;
|
||||
const verifyRes = await verifyVerification(gtRes, cookie, useK2);
|
||||
if (typeof verifyRes !== "string") {
|
||||
showSnackbar.error(`[${verifyRes.retcode}] ${verifyRes.message}`);
|
||||
return false;
|
||||
}
|
||||
return verifyRes;
|
||||
}
|
||||
|
||||
const miscReq = {
|
||||
create: createVerification,
|
||||
verify: verifyVerification,
|
||||
challenge: getGeetestChallenge,
|
||||
};
|
||||
|
||||
export default miscReq;
|
||||
Reference in New Issue
Block a user