-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathcaptcha.js
35 lines (35 loc) · 1.11 KB
/
captcha.js
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
const request = require('request-promise');
const retry = require('retry');
module.exports = () => {
return (options, response, body) => {
const captcha = response.captcha;
request
.get(
'https://azcaptcha.com/in.php?key=' + process.env.AZCAPTCHA_KEY +
'&method=userrecaptcha' +
'&googlekey=' + encodeURIComponent(captcha.siteKey) +
'&pageurl=' + encodeURIComponent(captcha.uri.href) +
'&json=1'
)
.then(res => {
let json = JSON.parse(res)
let operation = retry.operation({
retries: 5,
factor: 1,
minTimeout: 10000
});
operation.attempt(async() => {
let token = await request.get(
'http://azcaptcha.com/res.php?key=' + process.env.AZCAPTCHA_KEY +
'&action=get' +
'&id=' + json.request
);
if (token == 'CAPTCHA_NOT_READY') return;
captcha.form['g-recaptcha-response'] = token;
captcha.form['h-recaptcha-response'] = token;
captcha.submit();
})
})
.catch(err => captcha.submit(err))
}
}