fix: captcha retry with 30s delay on OCR failure, max 2 attempts
All checks were successful
Build and Deploy / deploy-front (push) Successful in 7s
Build and Deploy / deploy-back (push) Successful in 20s

This commit is contained in:
hyoseung 2026-05-19 18:18:55 +09:00
parent 72478bc3cb
commit 2227233dde

View File

@ -113,29 +113,40 @@ export class WosService {
fid: string,
code: string,
): Promise<{ success: boolean; message: string; err_code?: number }> {
let captchaCode: string;
try {
captchaCode = await this.solveCaptcha(fid);
} catch (err: any) {
return { success: false, message: `캡차 오류: ${err.message}` };
for (let attempt = 1; attempt <= 2; attempt++) {
if (attempt > 1) {
this.logger.warn(`[${fid}] ${code} 캡차 오인식, 30초 대기 후 재시도`);
await new Promise((r) => setTimeout(r, 30000));
}
let captchaCode: string;
try {
captchaCode = await this.solveCaptcha(fid);
} catch (err: any) {
return { success: false, message: `캡차 오류: ${err.message}` };
}
const ts = this.now();
const giftSign = this.makeGiftSign(fid, ts, code, captchaCode);
const response = await axios.post(
`${WOS_API_BASE}/gift_code`,
new URLSearchParams({ fid, time: String(ts), sign: giftSign, cdk: code, captcha_code: captchaCode }),
{ headers: { ...COMMON_HEADERS } },
);
const data = response.data;
this.logger.log(`[${fid}] ${code} attempt=${attempt} captcha=${captchaCode} → code=${data.code} err=${data.err_code} msg=${data.msg}`);
if (data.code === 0) return { success: true, message: SUCCESS_MSG };
if (data.err_code === 40103 && attempt < 2) continue;
return {
success: false,
message: data.msg || `실패 (${data.err_code})`,
err_code: data.err_code,
};
}
const ts = this.now();
const giftSign = this.makeGiftSign(fid, ts, code, captchaCode);
const response = await axios.post(
`${WOS_API_BASE}/gift_code`,
new URLSearchParams({ fid, time: String(ts), sign: giftSign, cdk: code, captcha_code: captchaCode }),
{ headers: { ...COMMON_HEADERS } },
);
const data = response.data;
this.logger.log(`[${fid}] ${code} captcha=${captchaCode} → code=${data.code} err=${data.err_code} msg=${data.msg}`);
return {
success: data.code === 0,
message: data.code === 0 ? SUCCESS_MSG : (data.msg || `실패 (${data.err_code})`),
err_code: data.err_code,
};
return { success: false, message: '알 수 없는 오류' };
}
async redeemAll(fid: string) {