C++ Module for 2Captcha API

#1
6a4f834392[1].png
The easiest way to quickly integrate 2Captcha into your code to automate solving of any type of captcha.

Installation
The api code is a single header file api2captcha.hpp, just copy it to your project and include where needed. You need to provide a HTTP-client implementation, as there is no standard one in C++. A sample HTTP-client based on libcurl is in curl_http.hpp (libcurl v. 7.62 or higher required), include it if you are using libcurl.

Configuration
Client instance can be created like this:
Code:
api2captcha::client_t client ("YOUR_API_KEY");
There are few options that can be configured:
Code:
client.set_soft_id (123);
client.set_callback ("https://your.site/result-receiver");
client.set_default_timeout (120);
client.set_recaptcha_timeout (600);
client.set_polling_interval (10);
Example below shows a basic solver call example with error handling.
Code:
api2captcha::normal_t captcha;
captcha.set_file ("path/to/captcha.jpg");
captcha.set_min_len (4);
captcha.set_max_len (20);
captcha.set_case_sensitive (true);
captcha.set_lang ("en");

try
{
    client.solve (captcha);
    printf ("Captcha solved: '%s'\n", captcha.code ().c_str ());
}
catch (std::exception & e)
{
    fprintf (stderr, "Error occurred: %s\n" + e.what ());
}
send / get_result
These methods can be used for manual captcha submission and answer polling.
Code:
std::string captcha_id = solver.send (captcha);

std::this_thread::sleep_for (std::chrono::seconds (10));

std::string code = solver.get_result (captcha_id);
balance
Use this method to get your account's balance
Code:
double balance = solver.get_balance ();
report
Use this method to report good or bad captcha answer.
Code:
solver.report (captcha.id (), true); // captcha solved correctly
solver.report (captcha.id (), false); // captcha solved incorrectly
Error handling
If case of an error captcha solver throws an exception. It's important to properly handle these cases. We recommend to use try catch to handle exceptions.
Code:
try
{
    solver.solve (captcha);
}
catch (api2captcha::network_exception_t & e)
{
    // network error occurred
}
catch (api2captcha::api_exception_t & e)
{
    // api respond with error
}
catch (api2captcha::timeout_exception_t & e)
{
    // captcha is not solved so far
}
Documentation https://github.com/2captcha/2captcha-cpp