forked from priyankjain/deathbycatpcha
-
Notifications
You must be signed in to change notification settings - Fork 0
riven60/deathbycatpcha
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title>DeathByCaptcha API Clients</title></head> <body> <h1>DeathByCaptcha API Clients</h1> <h2>Introduction</h2> <p>DeathByCaptcha offers APIs of two types — HTTP and socket-based, with the latter being recommended for having faster responses and overall better performance. Switching between different APIs is usually as easy as changing the client class and/or package name, the interface stays the same.</p> <p>When using the socket API, please make sure that outgoing TCP traffic to <em>api.dbcapi.me</em> to the ports range <em>8123–8130</em> is not blocked on your side.</p> <h2>How to Use DBC API Clients</h2> <h3>Thread-safety notes</h3> <p><em>.NET</em>, <em>Java</em> and <em>Python</em> clients are thread-safe, means it is perfectly fine to share a client between multiple threads (although in a heavily multithreaded applications it is a better idea to keep a pool of clients).</p> <p><em>PHP</em> itself is not multithreaded so the clients are not thread-safe.</p> <p><em>Perl</em> clients are not thread-safe at this moment, use a client instance per thread.</p> <h3>Common Clients' Interface</h3> <p>All the clients have to be instantiated with two string arguments: your DeathByCaptcha account's <em>username</em> and <em>password</em>.</p> <p>All the clients provide a few methods to handle your CAPTCHAs and your DBC account. Below you will find those methods' short summary summary and signatures in pseudo-code. Check the example scripts and the clients' source code for more details.</p> <h4>Upload()</h4> <p>Uploads a CAPTCHA to the DBC service for solving, returns uploaded CAPTCHA details on success, <code>NULL</code> otherwise. Here are the signatures in pseudo-code:</p> <dl> <dt>.NET</dt> <dd><code>DeathByCaptcha.Captcha DeathByCaptcha.Client.Upload(byte[] imageData)</code></dd> <dd><code>DeathByCaptcha.Captcha DeathByCaptcha.Client.Upload(Stream imageStream)</code></dd> <dd><code>DeathByCaptcha.Captcha DeathByCaptcha.Client.Upload(string imageFileName)</code></dd> <dt>Java</dt> <dd><code>com.DeathByCaptcha.Captcha com.DeathByCaptcha.Client.upload(byte[] imageData)</code></dd> <dd><code>com.DeathByCaptcha.Captcha com.DeathByCaptcha.Client.upload(InputStream imageStream)</code></dd> <dd><code>com.DeathByCaptcha.Captcha com.DeathByCaptcha.Client.upload(File imageFile)</code></dd> <dd><code>com.DeathByCaptcha.Captcha com.DeathByCaptcha.Client.upload(String imageFileName)</code></dd> <dt>Perl</dt> <dd><code>hash DeathByCaptcha.Client->upload(string $imageFileName)</code></dd> <dt>PHP</dt> <dd><code>array DeathByCaptcha_Client->upload(resource $imageFile)</code></dd> <dd><code>array DeathByCaptcha_Client->upload(string $imageFileName)</code></dd> <dt>Python</dt> <dd><code>dict deathbycaptcha.Client.upload(file imageFile)</code></dd> <dd><code>dict deathbycaptcha.Client.upload(str imageFileName)</code></dd> </dl> <h4>GetCaptcha()</h4> <p>Fetches uploaded CAPTCHA details, returns <code>NULL</code> on failures.</p> <dl> <dt>.NET</dt> <dd><code>DeathByCaptcha.Captcha DeathByCaptcha.Client.GetCaptcha(int captchaId)</code></dd> <dd><code>DeathByCaptcha.Captcha DeathByCaptcha.Client.GetCaptcha(DeathByCaptcha.Captcha captcha)</code></dd> <dt>Java</dt> <dd><code>com.DeathByCaptcha.Captcha com.DeathByCaptcha.Client.getCaptcha(int captchaId)</code></dd> <dd><code>com.DeathByCaptcha.Captcha com.DeathByCaptcha.Client.getCaptcha(com.DeathByCaptcha.Captcha captcha)</code></dd> <dt>Perl</dt> <dd><code>hash DeathByCaptcha.Client->getCaptcha(int $captchaId)</code></dd> <dt>PHP</dt> <dd><code>array DeathByCaptcha_Client->get_captcha(int $captchaId)</code></dd> <dt>Python</dt> <dd><code>dict deathbycaptcha.Client.get_captcha(dict imageFileName)</code></dd> </dl> <h4>Report()</h4> <p>Reports incorrectly solved CAPTCHA for refund, returns <code>true</code> on success, <code>false</code> otherwise.</p> <p>Please make sure the CAPTCHA you're reporting was in fact incorrectly solved, do not just report them thoughtlessly, or else you'll be flagged as abuser and banned.</p> <dl> <dt>.NET</dt> <dd><code>bool DeathByCaptcha.Client.Report(int captchaId)</code></dd> <dd><code>bool DeathByCaptcha.Client.Report(DeathByCaptcha.Captcha captcha)</code></dd> <dt>Java</dt> <dd><code>boolean com.DeathByCaptcha.Client.report(int captchaId)</code></dd> <dd><code>boolean com.DeathByCaptcha.Client.report(com.DeathByCaptcha.Captcha captcha)</code></dd> <dt>Perl</dt> <dd><code>bool DeathByCaptcha.Client->report(int $captchaId)</code></dd> <dt>PHP</dt> <dd><code>bool DeathByCaptcha.Client->report(int $captchaId)</code></dd> <dt>Python</dt> <dd><code>bool deathbycaptcha.Client.report(int captchaId)</code></dd> </dl> <h4>Decode()</h4> <p>This method uploads a CAPTCHA, then polls for its status until it's solved or times out; returns solved CAPTCHA details on success, <code>NULL</code> otherwise.</p> <dl> <dt>.NET</dt> <dd><code>DeathByCaptcha.Captcha DeathByCaptcha.Client.Decode(byte[] imageData, int timeout)</code></dd> <dd><code>DeathByCaptcha.Captcha DeathByCaptcha.Client.Decode(Stream imageStream, int timeout)</code></dd> <dd><code>DeathByCaptcha.Captcha DeathByCaptcha.Client.Decode(string imageFileName, int timeout)</code></dd> <dt>Java</dt> <dd><code>com.DeathByCaptcha.Captcha com.DeathByCaptcha.Client.decode(byte[] imageData, int timeout)</code></dd> <dd><code>com.DeathByCaptcha.Captcha com.DeathByCaptcha.Client.decode(InputStream imageStream, int timeout)</code></dd> <dd><code>com.DeathByCaptcha.Captcha com.DeathByCaptcha.Client.decode(File imageFile, int timeout)</code></dd> <dd><code>com.DeathByCaptcha.Captcha com.DeathByCaptcha.Client.decode(string imageFileName, int timeout)</code></dd> <dt>Perl</dt> <dd><code>hash DeathByCaptcha.Client->decode(string $imageFileName, int $timeout)</code></dd> <dt>PHP</dt> <dd><code>array DeathByCaptcha.Client->decode(resource $imageFile, int $timeout)</code></dd> <dd><code>array DeathByCaptcha.Client->decode(string $imageFileName, int $timeout)</code></dd> <dt>Python</dt> <dd><code>dict deathbycaptcha.Client.decode(file imageFile, int timeout)</code></dd> <dd><code>dict deathbycaptcha.Client.decode(str imageFileName, int timeout)</code></dd> </dl> <h4>GetBalance()</h4> <p>Fetches your current DBC credit balance (in US cents).</p> <dl> <dt>.NET</dt> <dd><code>double DeathByCaptcha.Client.GetBalance()</code></dd> <dt>Java</dt> <dd><code>double com.DeathByCaptcha.Client.getBalance()</code></dd> <dt>Perl</dt> <dd><code>float DeathByCaptcha.Client->getBalance()</code></dd> <dt>PHP</dt> <dd><code>float DeathByCaptcha.Client->get_balance()</code></dd> <dt>Python</dt> <dd><code>float deathbycaptcha.Client.get_balance()</code></dd> </dl> <h3>CAPTCHA objects/details hashes</h3> <p><em>.NET</em> and <em>Java</em> clients wrap CAPTCHA details in <code>DeathByCaptcha.Captcha</code> and <code>com.DeathByCaptcha.Captcha</code> objects respectively, exposing CAPTCHA details through the following properties and methods:</p> <ul> <li>CAPTCHA numeric ID as integer <code>Id</code> (.NET) and <code>id</code> (Java) properties;</li> <li>CAPTCHA text as string <code>Text</code> (.NET) and <code>text</code> (Java) properties;</li> <li>a flag showing whether the CAPTCHA was uploaded, as boolean <code>Uploaded</code> property (.NET) and <code>isUploaded()</code> (Java) method;</li> <li>a flag showing whether the CAPTCHA was solved, as boolean <code>Solved</code> property (.NET) and <code>isSolved()</code> (Java) method;</li> <li>a flag showing whether the CAPTCHA was solved correctly, as boolean <code>Correct</code> property (.NET) and <code>isCorrect()</code> (Java) method.</li> </ul> <p>Clients in other languages use simple hashes (dictionaries, associative arrays etc.) to store CAPTCHA details, keeping numeric IDs under <code>"captcha"</code> key, CAPTCHA text under <code>"text"</code> key, and the correctness flag under <code>"is_correct"</code> key.</p> <h3>Examples</h3> <p>Below you can find a few DBC API clients' usage examples.</p> <h4>C#</h4> <code><pre> using DeathByCaptcha; /* Put your DeathByCaptcha account username and password here. Use HttpClient for HTTP API. */ Client client = (Client)new SocketClient(username, password); try { double balance = client.GetBalance(); /* Put your CAPTCHA file name, or file object, or arbitrary stream, or an array of bytes, and optional solving timeout (in seconds) here: */ Captcha captcha = client.Decode(captchaFileName, timeout); if (null != captcha) { /* The CAPTCHA was solved; captcha.Id property holds its numeric ID, and captcha.Text holds its text. */ Console.WriteLine("CAPTCHA {0} solved: {1}", captcha.Id, captcha.Text); if (/* check if the CAPTCHA was incorrectly solved */) { client.Report(captcha); } } } catch (AccessDeniedException e) { /* Access to DBC API denied, check your credentials and/or balance */ } </pre></code> <h4>Java</h4> <code><pre> import com.DeathByCaptcha.AccessDeniedException; import com.DeathByCaptcha.Captcha; import com.DeathByCaptcha.Client; import com.DeathByCaptcha.SocketClient; import com.DeathByCaptcha.HttpClient; /* Put your DeathByCaptcha account username and password here. Use HttpClient for HTTP API. */ Client client = (Client)new SocketClient(username, password); try { double balance = client.getBalance(); /* Put your CAPTCHA file name, or file object, or arbitrary input stream, or an array of bytes, and optional solving timeout (in seconds) here: */ Captcha captcha = client.decode(captchaFileName, timeout); if (null != captcha) { /* The CAPTCHA was solved; captcha.id property holds its numeric ID, and captcha.text holds its text. */ System.out.println("CAPTCHA " + captcha.id + " solved: " + captcha.text); if (/* check if the CAPTCHA was incorrectly solved */) { client.report(captcha); } } } catch (AccessDeniedException e) { /* Access to DBC API denied, check your credentials and/or balance */ } </pre></code> <h4>PHP</h4> <code><pre> require_once "deathbycaptcha.php"; /* Put your DBC account username and password here. Use DeathByCaptcha_HttpClient for HTTP API. */ $client = new DeathByCaptcha_SocketClient($username, $password); try { $balance = $client->get_balance(); /* Put your CAPTCHA file name or opened file handler, and optional solving timeout (in seconds) here: */ $captcha = $client->decode($captcha_file_name, $timeout); if ($captcha) { /* The CAPTCHA was solved; captcha["captcha"] item holds its numeric ID, and captcha["text"] item its text. */ echo "CAPTCHA {$captcha["captcha"]} solved: {$captcha["text"]}"; if (/* check if the CAPTCHA was incorrectly solved */) { $client->report($captcha["captcha"]); } } } catch (DeathByCaptcha_AccessDeniedException) { /* Access to DBC API denied, check your credentials and/or balance */ } </pre></code> <h4>Python</h4> <code><pre> import deathbycaptcha # Put your DBC account username and password here. # Use deathbycaptcha.HttpClient for HTTP API. client = deathbycaptcha.SocketClient(username, password) try: balance = client.get_balance() # Put your CAPTCHA file name or file-like object, and optional # solving timeout (in seconds) here: captcha = client.decode(captcha_file_name, timeout) if captcha: # The CAPTCHA was solved; captcha["captcha"] item holds its # numeric ID, and captcha["text"] item its text. print "CAPTCHA %s solved: %s" % (captcha["captcha"], captcha["text"]) if ...: # check if the CAPTCHA was incorrectly solved client.report(captcha["captcha"]) except deathbycaptcha.AccessDeniedException: # Access to DBC API denied, check your credentials and/or balance </pre></code> </body> </html>
About
A program in PHP to get image from a website (captcha like image) and integrate it using deathbycaptcha api
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- HTML 69.7%
- PHP 28.0%
- CSS 2.3%