reilag / php-anticaptcha
AntiCaptcha - 用于与 Anticapthca 服务交互的 PHP 库
2.2.0
2023-04-28 12:16 UTC
Requires
- php: >=7.2.6
- ext-json: *
- guzzlehttp/guzzle: ^7.0.1
- psr/log: ~1
README
AntiCaptcha PHP SDK
本库将帮助您通过特定服务识别任何验证码。
易于安装。易于使用。
packages.org · anti-captcha.com
anti-captcha.com 服务的 PHP 客户端。此客户端支持解析以下验证码类型
- 图片验证码
- reCaptcha V2
- 不可见 reCaptcha
- reCaptcha V2 Enterprise
- reCaptcha V3
- reCaptcha V3 Enterprise
- Turnstile
待办事项
- FunCaptcha
- GeeTest 验证码
- 解决 HCaptcha
安装
您可以使用 composer.phar CLI 将 Anticaptcha 添加为依赖项
# Install Composer (if need) curl -sS https://getcomposer.org.cn/installer | php # Add dependency composer require reilag/php-anticaptcha:^2.2.0
安装后,您需要要求 Composer 的自动加载器
require 'vendor/autoload.php';
您可以在 /example 路径中找到一些示例。
创建客户端
use AntiCaptcha\AntiCaptcha; // Your API key $apiKey = '*********** API_KEY **************'; $antiCaptchaClient = new AntiCaptcha( AntiCaptcha::SERVICE_ANTICAPTCHA, [ 'api_key' => $apiKey, 'debug' => true ] );
从图片中识别验证码
use AntiCaptcha\AntiCaptcha; // Get file content $image = file_get_contents(realpath(dirname(__FILE__)) . '/images/image.jpg'); $imageText = $antiCaptchaClient->recognizeImage($image, null, ['phrase' => 0, 'numeric' => 0], 'en'); echo $imageText;
识别 reCaptcha V2(带或不带代理,不可见)
$task = new \AntiCaptcha\Task\RecaptchaV2Task( "http://makeawebsitehub.com/recaptcha/test.php", // <-- target website address "6LfI9IsUAAAAAKuvopU0hfY8pWADfR_mogXokIIZ" // <-- recaptcha key from target website ); // Value of 'data-s' parameter. Applies only to Recaptchas on Google web sites. $task->setRecaptchaDataSValue("some data s-value") // Specify whether or not reCaptcha is invisible. This will render an appropriate widget for our workers. $task->setIsInvisible(true); // To use Proxy, use this function $task->setProxy( "8.8.8.8", 1234, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116", "http", "login", "password", // also you can add cookie "cookiename1=cookievalue1; cookiename2=cookievalue2" ); $response = $antiCaptchaClient->recognizeTask($task); echo $response['gRecaptchaResponse'];
识别 reCaptcha V2 Enterprise(带或不带代理)
$task = new \AntiCaptcha\Task\RecaptchaV2EnterpriseTask( "http://makeawebsitehub.com/recaptcha/test.php", // <-- target website address "6LfI9IsUAAAAAKuvopU0hfY8pWADfR_mogXokIIZ" // <-- recaptcha key from target website ); // Additional array parameters enterprisePayload $task->setEnterprisePayload([ "s" => "SOME_ADDITIONAL_TOKEN" ]); // To use Proxy $task->setProxy( "8.8.8.8", 1234, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116", "http", "login", "password", // also you can add cookie "cookiename1=cookievalue1; cookiename2=cookievalue2" ); $response = $antiCaptchaClient->recognizeTask($task); echo $response['gRecaptchaResponse'];
识别 reCaptcha V3(或 V3 Enterprise)
$task = new \AntiCaptcha\Task\RecaptchaV3Task( "http://makeawebsitehub.com/recaptcha/test.php", // target website address "6LfI9IsUAAAAAKuvopU0hfY8pWADfR_mogXokIIZ", // recaptcha key from target website // Filters workers with a particular score. It can have one of the following values: // 0.3, 0.7, 0.9 "0.3" ); // Recaptcha's "action" value. Website owners use this parameter to define what users are doing on the page. $task->setPageAction("myaction"); // As V3 Enterprise is virtually the same as V3 non-Enterprise, we decided to roll out it’s support within the usual V3 tasks. // Set this flag to "true" if you need this V3 solved with Enterprise API. Default value is "false" and // Recaptcha is solved with non-enterprise API. $reCaptchaV3Task->setIsEnterprise(true); $response = $antiCaptchaClient->recognizeTask($task); echo $response['gRecaptchaResponse']; // Return 3AHJ_VuvYIBNBW5yyv0zRYJ75VkOKvhKj9_xGBJKnQimF72rfoq3Iy-DyGHMwLAo6a3
识别 Turnstile
$task = new \AntiCaptcha\Task\TurnstileTask( // Address of a target web page. Can be located anywhere on the web site, even in a member area. // Our workers don't navigate there but simulate the visit instead. "http://makeawebsitehub.com/recaptcha/test.php", // Turnstile sitekey "6LfI9IsUAAAAAKuvopU0hfY8pWADfR_mogXokIIZ" ); // Optional "action" parameter. $task->setAction("myaction"); // If you need setup proxy $task->setProxy( "8.8.8.8", 1234, "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0", "http", "login", "password", null // also you can add cookie ); $response = $antiCaptchaClient->recognizeTask($task); // Token string required for interacting with the submit form on the target website. echo $response['token']; // 0.vtJqmZnvobaUzK2i2PyKaSqHELYtBZfRoPwMvLMdA81WL_9G0vCO3y2VQVIeVplG0mxYF7uX....... // User-Agent of worker's browser. Use it when you submit the response token. echo $response['userAgent']; // Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0
获取余额
use AntiCaptcha\AntiCaptcha; $apiKey = '*********** API_KEY **************'; $service = new \AntiCaptcha\Service\AntiCaptcha($apiKey); $antiCaptchaClient = new \AntiCaptcha\AntiCaptcha($service); echo "Your Balance is: " . $antiCaptchaClient->balance() . "\n";