fix: captcha retry with 30s delay on OCR failure, max 2 attempts
This commit is contained in:
parent
72478bc3cb
commit
2227233dde
@ -113,29 +113,40 @@ export class WosService {
|
|||||||
fid: string,
|
fid: string,
|
||||||
code: string,
|
code: string,
|
||||||
): Promise<{ success: boolean; message: string; err_code?: number }> {
|
): Promise<{ success: boolean; message: string; err_code?: number }> {
|
||||||
let captchaCode: string;
|
for (let attempt = 1; attempt <= 2; attempt++) {
|
||||||
try {
|
if (attempt > 1) {
|
||||||
captchaCode = await this.solveCaptcha(fid);
|
this.logger.warn(`[${fid}] ${code} 캡차 오인식, 30초 대기 후 재시도`);
|
||||||
} catch (err: any) {
|
await new Promise((r) => setTimeout(r, 30000));
|
||||||
return { success: false, message: `캡차 오류: ${err.message}` };
|
}
|
||||||
|
|
||||||
|
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();
|
return { success: false, message: '알 수 없는 오류' };
|
||||||
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,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async redeemAll(fid: string) {
|
async redeemAll(fid: string) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user