File size: 1,812 Bytes
7fc5208 ed57b37 7fc5208 ed57b37 7fc5208 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
export async function getVerificationCode(proofApi: string, apiKey: String, proofEmail: string, timestamp: number): Promise<string> {
const maxRetries = 30;
console.log(`εΌε§θ·ειͺθ―η ${proofApi},${apiKey},${timestamp},${new Date(timestamp * 1000)}`);
for (let i = 0; i < maxRetries; i++) {
try {
const params = new URLSearchParams({
to: proofEmail,
from: '[email protected]',
timestamp: timestamp.toString()
});
const url = `${proofApi}?${params.toString()}`;
const response = await fetch(url, {
headers: {
'Authorization': `Bearer ${apiKey}`
},
method: 'GET'
});
if (response.status === 200) {
const data: any = await response.json();
const match = data.text.match(/:\s*(\d+)\n\n/);
if (match) {
console.log(proofEmail, `θ·ειͺθ―η ζε: ${match[1]}`);
return match[1];
}
}
else {
console.log(proofEmail, `θ·ειͺθ―η ε€±θ΄₯: ${await response.text()}`);
}
await new Promise(resolve => setTimeout(resolve, 2000));
} catch (error:any) {
console.error(proofEmail, `θ·ειͺθ―η εΊι: ${error.message}`);
if (i === maxRetries - 1) {
throw new Error("Failed to get verification code after maximum retries");
}
// ιθ――εηεΎ
3η§ειθ―
await new Promise(resolve => setTimeout(resolve, 3000));
continue;
}
}
throw new Error("Failed to get verification code");
} |