Created
June 15, 2015 12:27
-
-
Save kas-cor/d5535a5a5d347b71ca88 to your computer and use it in GitHub Desktop.
RuCaptcha.com and html2canvas.hertzen.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rucaptcha(obj, callback) { | |
obj.ready(function () { | |
console.log("Capture captcha..."); | |
obj.html2canvas({ | |
allowTaint: true, | |
onrendered: function (canvas) { | |
var captcha = canvas.toDataURL("image/png"); | |
console.log("Send to decode captcha..."); | |
$.post("http://rucaptcha.com/in.php", "method=base64&key={API_KEY}&body=" + encodeURI(captcha), function (res) { | |
console.log(res); | |
var res_arr = res.split("|"); | |
if (res_arr[0] === "OK") { | |
console.log("Check result..."); | |
var repeat = setInterval(function () { | |
$.get("http://rucaptcha.com/res.php", "key={API_KEY}&action=get&id=" + encodeURI(res_arr[1]), function (res) { | |
console.log(res); | |
if (res[0] === "E") { | |
clearInterval(repeat); | |
callback(res); | |
} | |
var res_arr = res.split("|"); | |
if (res_arr[0] === "OK") { | |
clearInterval(repeat); | |
callback(res_arr[1]); | |
} | |
}); | |
}, 3000); | |
} | |
}); | |
} | |
}); | |
}); | |
} | |
// Use | |
rucaptcha($("#id_object"), function (res) { | |
console.log(res); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment