Update captcha.service.ts

This commit is contained in:
Baobhan Sith
2025-04-25 23:40:47 +08:00
parent 640810c4df
commit 542b3b5d51
@@ -57,12 +57,13 @@ export class CaptchaService {
private async _verifyHCaptcha(token: string, secretKey: string): Promise<boolean> { private async _verifyHCaptcha(token: string, secretKey: string): Promise<boolean> {
console.log('[CaptchaService] 正在验证 hCaptcha 令牌...'); console.log('[CaptchaService] 正在验证 hCaptcha 令牌...');
try { try {
const response = await axios.post(HCAPTCHA_VERIFY_URL, null, { // 使用 POST,数据在 params // 正确方式:将数据放在 POST body 中,并使用 URLSearchParams 格式化
params: { const params = new URLSearchParams();
secret: secretKey, params.append('secret', secretKey);
response: token, params.append('response', token);
// remoteip: 可选,用户 IP 地址 // params.append('remoteip', userIpAddress); // 如果需要传递用户 IP
},
const response = await axios.post(HCAPTCHA_VERIFY_URL, params, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' } headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}); });