🌱 继续优化验证码登录,尝试引入geetest

This commit is contained in:
目棃
2024-07-27 12:51:28 +08:00
parent a8b1ff4588
commit 8f116c954f
11 changed files with 385 additions and 313 deletions

View File

@@ -40,12 +40,13 @@ function rsaEncrypt(data: string): string {
/**
* @description 获取短信验证码
* @since Beta v0.5.1
* @todo retcode 为-3101时表示需要进行验证需要从resp.headers["x-rpc-aigis"]中获取相关数据
* @param {string} phone - 手机号
* @param {string} [aigis] - 验证数据
* @returns {Promise<TGApp.Plugins.Mys.CaptchaLogin.CaptchaData | TGApp.BBS.Response.Base>}
*/
export async function getCaptcha(
phone: string,
aigis?: string,
): Promise<TGApp.Plugins.Mys.CaptchaLogin.CaptchaData | TGApp.BBS.Response.BaseWithData> {
const url = "https://passport-api.mihoyo.com/account/ma-cn-verifier/verifier/createLoginCaptcha";
const device_fp = getDeviceInfo("device_fp");
@@ -54,7 +55,7 @@ export async function getCaptcha(
const device_model = getDeviceInfo("product");
const body = { area_code: rsaEncrypt("+86"), mobile: rsaEncrypt(phone) };
const header: Record<string, string> = {
"x-rpc-aigis": "",
"x-rpc-aigis": aigis || "",
"x-rpc-app_version": TGConstant.BBS.VERSION,
"x-rpc-client_type": "2",
"x-rpc-app_id": TGConstant.BBS.APP_ID,

View File

@@ -38,6 +38,21 @@ declare namespace TGApp.Plugins.Mys.CaptchaLogin {
action_type: string;
}
/**
* @description 触发验证的序列化数据
* @since Beta v0.5.1
* @interface CaptchaAigis
* @property {string} session_id 会话 id
* @property {number} mmt_type mmt 类型
* @property {TGApp.Plugins.Mys.Geetest.getData} data 数据
* @return CaptchaBody
*/
interface CaptchaAigis {
session_id: string;
mmt_type: number;
data: TGApp.Plugins.Mys.Geetest.reqResp;
}
/**
* @description 短信验证码登录返回数据
* @since Beta v0.5.1

98
src/plugins/Mys/types/Geetest.d.ts vendored Normal file
View File

@@ -0,0 +1,98 @@
/**
* @file plugins/Mys/types/Geetest.d.ts
* @description Mys 插件 Geetest 类型定义文件
* @since Beta v0.5.1
*/
/**
* @description Mys 插件 Geetest 类型
* @since Beta v0.5.1
* @namespace TGApp.Plugins.Mys.Geetest
* @memberof TGApp.Plugins.Mys
*/
declare namespace TGApp.Plugins.Mys.Geetest {
/**
* @description 极验验证的响应数据
* @since Beta v0.5.1
* @interface reqResp
* @property {string} gt - 极验验证 gt
* @property {string} challenge - 极验验证 challenge
* @property {number} new_captcha - 极验验证 new_captcha
* @property {number} success - 极验验证 success
* @return reqResp
*/
interface reqResp {
gt: string;
challenge: string;
new_captcha: number;
success: number;
}
/**
* @description 极验验证的请求数据
* @since Beta v0.5.1
* @interface postData
* @property {string} challenge - 极验验证 challenge
* @property {string} validate - 极验验证 validate
* @return postData
*/
interface postData {
challenge: string;
validate: string;
}
/**
* @description 极验验证的请求方法-请求参数
* @since Beta v0.5.1
* @interface InitGeetestParams
* @property {string} gt - 极验验证 gt
* @property {string} challenge - 极验验证 challenge
* @property {boolean} offline - 极验验证 offline
* @property {boolean} new_captcha - 极验验证 new_captcha
* @property {string} product - 极验验证 product
* @property {string} width - 极验验证 width
* @property {string} area - 极验验证 area
* @return InitGeetestParams
*/
interface InitGeetestParams {
gt: string;
challenge: string;
offline: boolean;
new_captcha: boolean;
product: string;
width: string;
area: string;
}
/**
* @description Geetest 插件 captchaObj
* @since Beta v0.5.1
* @interface GeetestCaptcha
* @property {Function} appendTo
* @property {Function} getValidate
* @property {Function} onSuccess
* @property {Function} onClose
* @return GeetestCaptcha
*/
interface GeetestCaptcha {
appendTo: (selector: string) => void;
getValidate: () => validateResp;
onSuccess: (callback: () => void) => void;
onClose: (callback: () => void) => void;
}
/**
* @description Geetest 插件 validate
* @since Beta v0.5.1
* @interface validateResp
* @property {string} geetest_challenge
* @property {string} geetest_validate
* @property {string} geetest_seccode
* @return validateResp
*/
interface validateResp {
geetest_challenge: string;
geetest_validate: string;
geetest_seccode: string;
}
}