Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getCaptchaText(image){
- var apiEndPointIn = "http://2captcha.com/in.php";
- var apiEndPointRes = "http://2captcha.com/res.php";
- var apiKey = "bbddbad6f8853f493c7ba9f4ab4bfa7b";
- return new Promise((resolve, reject) => {
- axios.post(apiEndPointIn, {
- key: apiKey,
- method: "base64",
- body: image.toString('base64')
- }).then((res) => {
- var captchaId = "";
- if(res.data.indexOf("OK") > -1){
- captchaId = res.data.split('|')[1];
- axios.post(apiEndPointRes, "key="+apiKey+"&action=get&id="+captchaId).then((res) => {
- var data = res.data;
- var counter = 0;
- console.log(data);
- while(data.indexOf('CAPCHA_NOT_READY') > -1){
- setTimeout((_) => {
- counter++;
- if(counter == 6) reject("Error");
- axios.post(apiEndPointRes, "key="+apiKey+"&action=get&id="+captchaId).then((res) => {
- if (res.data.indexOf('OK')) resolve(res.data.split('|')[1]);
- });
- });
- }
- });
- }
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement