fix: remove captcha retry - exactly 1 captcha request per coupon to prevent TOO FREQUENT
This commit is contained in:
parent
ae3bd8b72a
commit
72478bc3cb
@ -112,50 +112,30 @@ export class WosService {
|
||||
private async redeemOne(
|
||||
fid: string,
|
||||
code: string,
|
||||
maxRetries = 5,
|
||||
): Promise<{ success: boolean; message: string; err_code?: number }> {
|
||||
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
||||
if (attempt > 1) {
|
||||
await new Promise((r) => setTimeout(r, 3000));
|
||||
}
|
||||
|
||||
let captchaCode: string;
|
||||
try {
|
||||
captchaCode = await this.solveCaptcha(fid);
|
||||
} catch (err: any) {
|
||||
const msg: string = err.message || '';
|
||||
if (msg.includes('TOO FREQUENT') && attempt < maxRetries) {
|
||||
this.logger.warn(`[${fid}] 캡차 TOO FREQUENT (${attempt}회), 10초 대기 후 재시도`);
|
||||
await new Promise((r) => setTimeout(r, 10000));
|
||||
continue;
|
||||
}
|
||||
return { success: false, message: `캡차 오류: ${msg}` };
|
||||
}
|
||||
|
||||
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) {
|
||||
if (attempt < maxRetries) continue;
|
||||
return { success: false, message: `캡차 인식 실패 (${maxRetries}회 시도)`, err_code: data.err_code };
|
||||
}
|
||||
if (data.code !== 0 && (data.err_code === 0 || data.msg === 'Sign Error')) {
|
||||
if (attempt < maxRetries) continue;
|
||||
return { success: false, message: 'Sign Error (캡차 오인식)', err_code: data.err_code };
|
||||
}
|
||||
return { success: false, message: data.msg || `실패 (${data.err_code})`, err_code: data.err_code };
|
||||
let captchaCode: string;
|
||||
try {
|
||||
captchaCode = await this.solveCaptcha(fid);
|
||||
} catch (err: any) {
|
||||
return { success: false, message: `캡차 오류: ${err.message}` };
|
||||
}
|
||||
|
||||
return { success: false, 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} 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) {
|
||||
@ -291,7 +271,7 @@ export class WosService {
|
||||
this.logger.error(`[${user.fid}] ${code} 지급 실패: ${err.message}`);
|
||||
}
|
||||
|
||||
await new Promise((r) => setTimeout(r, 1500));
|
||||
await new Promise((r) => setTimeout(r, 5000));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user