修复邮箱注册验证码报错的bug

This commit is contained in:
xiaojunnuo
2025-10-28 15:30:31 +08:00
parent 0c8b8647f3
commit d32f4fc38e
4 changed files with 66 additions and 56 deletions
@@ -3,57 +3,54 @@ import { ICaptchaAddon } from "../api.js";
import { TencentAccess } from "@certd/plugin-lib";
@IsAddon({
addonType:"captcha",
name: 'tencent',
title: '腾讯云验证码',
desc: '',
showTest:false,
addonType: "captcha",
name: "tencent",
title: "腾讯云验证码",
desc: "",
showTest: false,
})
export class TencentCaptcha extends BaseAddon implements ICaptchaAddon{
export class TencentCaptcha extends BaseAddon implements ICaptchaAddon {
@AddonInput({
title: '腾讯云授权',
helper: '腾讯云授权',
title: "腾讯云授权",
helper: "腾讯云授权",
component: {
name: 'access-selector',
vModel:"modelValue",
name: "access-selector",
vModel: "modelValue",
from: "sys",
type: 'tencent', //固定授权类型
type: "tencent", //固定授权类型
},
required: true,
})
accessId :number;
accessId: number;
@AddonInput({
title: '验证ID',
title: "验证ID",
component: {
name:"a-input-number",
placeholder: 'CaptchaAppId',
name: "a-input-number",
placeholder: "CaptchaAppId",
},
helper:"[腾讯云验证码](https://cloud.tencent.com/act/cps/redirect?redirect=37716&cps_key=b3ef73330335d7a6efa4a4bbeeb6b2c9)",
helper: "[腾讯云验证码](https://cloud.tencent.com/act/cps/redirect?redirect=37716&cps_key=b3ef73330335d7a6efa4a4bbeeb6b2c9)",
required: true,
})
captchaAppId:number;
captchaAppId: number;
@AddonInput({
title: '验证Key',
title: "验证Key",
component: {
placeholder: 'AppSecretKey',
placeholder: "AppSecretKey",
},
required: true,
})
appSecretKey = '';
appSecretKey = "";
async onValidate(data?:any) {
async onValidate(data?: any) {
if (!data) {
return false
return false;
}
const access = await this.getAccess<TencentAccess>(this.accessId);
const access = await this.getAccess<TencentAccess>(this.accessId)
const sdk =await import("tencentcloud-sdk-nodejs/tencentcloud/services/captcha/v20190722/index.js");
const sdk = await import("tencentcloud-sdk-nodejs/tencentcloud/services/captcha/v20190722/index.js");
const CaptchaClient = sdk.v20190722.Client;
@@ -70,35 +67,40 @@ export class TencentCaptcha extends BaseAddon implements ICaptchaAddon{
},
};
// 实例化要请求产品的client对象,clientProfile是可选的
// 实例化要请求产品的client对象,clientProfile是可选的
const client = new CaptchaClient(clientConfig);
const params = {
"CaptchaType": 9, //固定值9
"UserIp": "127.0.0.1",
"Ticket": data.ticket,
"Randstr": data.randstr,
"AppSecretKey": this.appSecretKey,
"CaptchaAppId": this.captchaAppId,
CaptchaType: 9, //固定值9
UserIp: "127.0.0.1",
Ticket: data.ticket,
Randstr: data.randstr,
AppSecretKey: this.appSecretKey,
CaptchaAppId: this.captchaAppId,
};
const res = await client.DescribeCaptchaResult(params)
if (res.CaptchaCode == 1) {
// 验证成功
// verification successful
return true;
} else {
// 验证失败
// verification failed
this.logger.error("腾讯云验证码验证失败",res.CaptchaMsg)
return false;
try {
const res = await client.DescribeCaptchaResult(params);
if (res.CaptchaCode == 1) {
// 验证成功
// verification successful
return true;
} else {
// 验证失败
// verification failed
this.logger.error("腾讯云验证码验证失败", res.CaptchaMsg);
return false;
}
} catch (err) {
if (data.ticket.startsWith("trerror_") && err.message.includes("账户已欠费")) {
this.logger.error("腾讯云验证码账户欠费,临时放行:", err.message);
return true;
}
throw err
}
}
async getCaptcha(): Promise<any> {
async getCaptcha(): Promise<any> {
return {
captchaAppId: this.captchaAppId,
}
};
}
}