Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1.  
  2. function getCaptchaText(image){
  3. var apiEndPointIn = "http://2captcha.com/in.php";
  4. var apiEndPointRes = "http://2captcha.com/res.php";
  5. var apiKey = "bbddbad6f8853f493c7ba9f4ab4bfa7b";
  6.  
  7. return new Promise((resolve, reject) => {
  8. axios.post(apiEndPointIn, {
  9. key: apiKey,
  10. method: "base64",
  11. body: image.toString('base64')
  12. }).then((res) => {
  13. var captchaId = "";
  14. if(res.data.indexOf("OK") > -1){
  15. captchaId = res.data.split('|')[1];
  16. axios.post(apiEndPointRes, "key="+apiKey+"&action=get&id="+captchaId).then((res) => {
  17. var data = res.data;
  18. var counter = 0;
  19. console.log(data);
  20. while(data.indexOf('CAPCHA_NOT_READY') > -1){
  21. setTimeout((_) => {
  22. counter++;
  23. if(counter == 6) reject("Error");
  24. axios.post(apiEndPointRes, "key="+apiKey+"&action=get&id="+captchaId).then((res) => {
  25. if (res.data.indexOf('OK')) resolve(res.data.split('|')[1]);
  26. });
  27. });
  28. }
  29. });
  30. }
  31. });
  32. });
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement