如何解决数字 captcha
要使用我们的服务破解数字 captcha,您需要使用 HTTP POST 请求向我们 API 的 URL 上传图片:
https://2captcha.com/in.php
服务器接受multipart或base64格式的图像。代码示例:
阅读更多 - captcha处理API文档。
// https://github.com/2captcha/2captcha-php require(__DIR__ . '/../src/autoloader.php'); $solver = new \TwoCaptcha\TwoCaptcha('YOUR_API_KEY'); try { $result = $solver->normal([ 'file' => 'path/to/captcha.jpg', 'numeric' => 1, ]); } catch (\Exception $e) { die($e->getMessage()); } die('Captcha solved: ' . $result->code);
# https://github.com/2captcha/2captcha-python import sys import os sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) from twocaptcha import TwoCaptcha api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY') solver = TwoCaptcha(api_key) try: result = solver.normal('path/to/captcha.jpg', numeric=1) except Exception as e: sys.exit(e) else: sys.exit('solved: ' + str(result))
// https://github.com/2captcha/2captcha-csharp using System; using System.Linq; using TwoCaptcha.Captcha; namespace TwoCaptcha.Examples { public class NormalExample { public static void Main() { var solver = new TwoCaptcha("YOUR_API_KEY"); Normal captcha = new Normal("path/to/captcha.jpg"); captcha.SetNumeric(1); try { solver.Solve(captcha).Wait(); Console.WriteLine("Captcha solved: " + captcha.Code); } catch (AggregateException e) { Console.WriteLine("Error occurred: " + e.InnerExceptions.First().Message); } } } }
// https://github.com/2captcha/2captcha-java package examples; import com.twocaptcha.TwoCaptcha; import com.twocaptcha.captcha.Normal; public class NormalExample { public static void main(String[] args) { TwoCaptcha solver = new TwoCaptcha("YOUR_API_KEY"); Normal captcha = new Normal("path/to/captcha.jpg"); captcha.setNumeric(1); try { solver.solve(captcha); System.out.println("Captcha solved: " + captcha.getCode()); } catch (Exception e) { System.out.println("Error occurred: " + e.getMessage()); } } }
// https://github.com/2captcha/2captcha-go package main import ( "fmt" "log" "github.com/2captcha/2captcha-go" ) func main() { client := api2captcha.NewClient("API_KEY") captcha := api2captcha.Normal{ File: "/path/to/captcha.jpg", Numeric: 1, } code, err := client.Solve(captcha.ToRequest()) if err != nil { log.Fatal(err); } fmt.Println("code "+code) }
// https://github.com/2captcha/2captcha-cpp #include <cstdio> #include "curl_http.hpp" #include "api2captcha.hpp" int main (int ac, char ** av) { if (ac < 2) { printf ("Usage: ./normal path/to/image.jpg\n"); return 0; } api2captcha::curl_http_t http; http.set_verbose (true); api2captcha::client_t client; client.set_http_client (&http); client.set_api_key (API_KEY); assert (ac > 1); api2captcha::normal_t cap; cap.set_file (av[1]); cap.set_numeric (1); try { client.solve (cap); printf ("code '%s'\n", cap.code ().c_str ()); } catch (std::exception & e) { fprintf (stderr, "Failed: %s\n", e.what ()); } return 0; }
# https://github.com/2captcha/2captcha-ruby require 'api_2captcha' client = Api2Captcha.new("YOUR_API_KEY") result = client.normal({ image: 'path/to/captcha.jpg', numeric: 1 })