From ac01895800f4a5714491d021d19c1073f4a7a194 Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Fri, 12 Sep 2025 07:43:58 +0300 Subject: [PATCH 01/11] private $extendedResponse = 0; --- src/TwoCaptcha.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/TwoCaptcha.php b/src/TwoCaptcha.php index 901796f..6fbdb52 100644 --- a/src/TwoCaptcha.php +++ b/src/TwoCaptcha.php @@ -80,6 +80,8 @@ class TwoCaptcha */ private $apiClient; + private $extendedResponse = 0; + /** * TwoCaptcha constructor. * @param $options string|array @@ -99,6 +101,7 @@ public function __construct($options) if (!empty($options['defaultTimeout'])) $this->defaultTimeout = $options['defaultTimeout']; if (!empty($options['recaptchaTimeout'])) $this->recaptchaTimeout = $options['recaptchaTimeout']; if (!empty($options['pollingInterval'])) $this->pollingInterval = $options['pollingInterval']; + if (!empty($options['extendedResponse'])) $this->extendedResponse = $options['extendedResponse']; $this->apiClient = new ApiClient($this->server); } From 679d336fe7e4506c68278e27a43311f4b042fa41 Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Fri, 12 Sep 2025 10:24:28 +0300 Subject: [PATCH 02/11] json result --- src/TwoCaptcha.php | 48 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/TwoCaptcha.php b/src/TwoCaptcha.php index 6fbdb52..dffaa00 100644 --- a/src/TwoCaptcha.php +++ b/src/TwoCaptcha.php @@ -80,7 +80,11 @@ class TwoCaptcha */ private $apiClient; - private $extendedResponse = 0; + + /** + * JSON response + */ + private $json = 0; /** * TwoCaptcha constructor. @@ -101,7 +105,7 @@ public function __construct($options) if (!empty($options['defaultTimeout'])) $this->defaultTimeout = $options['defaultTimeout']; if (!empty($options['recaptchaTimeout'])) $this->recaptchaTimeout = $options['recaptchaTimeout']; if (!empty($options['pollingInterval'])) $this->pollingInterval = $options['pollingInterval']; - if (!empty($options['extendedResponse'])) $this->extendedResponse = $options['extendedResponse']; + if (!empty($options['json'])) $this->json = $options['json']; $this->apiClient = new ApiClient($this->server); } @@ -497,10 +501,10 @@ public function canvas($captcha) $this->requireFileOrBase64($captcha); $captcha['method'] = empty($captcha['base64']) ? 'post' : 'base64'; - $captcha['recaptcha']=1; + $captcha['recaptcha'] = 1; $captcha['canvas'] = 1; - if ( empty($captcha['hintText']) && empty($captcha['hintImg']) ) { + if (empty($captcha['hintText']) && empty($captcha['hintImg'])) { throw new ValidationException('At least one of parameters: hintText or hintImg required!'); } @@ -543,7 +547,8 @@ public function coordinates($captcha) * @throws TimeoutException * @throws ValidationException */ - public function audio($captcha){ + public function audio($captcha) + { if (is_string($captcha)) { if (!file_exists($captcha)) { throw new ValidationException('File not found (' . $captcha . ')'); @@ -704,17 +709,36 @@ public function getResult($id) $response = $this->res([ 'action' => 'get', 'id' => $id, + 'json' => $this->json, ]); - if ($response == 'CAPCHA_NOT_READY') { - return null; - } - if (mb_strpos($response, 'OK|') !== 0) { - throw new ApiException('Cannot recognise api response (' . $response . ')'); - } + $jsonObj = json_decode($response, true); - return mb_substr($response, 3); + if (json_last_error() === JSON_ERROR_NONE) { + $request = $jsonObj['request']; + $status = $jsonObj['status']; + + + if ($request == "CAPCHA_NOT_READY") { + return null; + } + + if ($status == 1) { + return $response; + } + } else { + + if ($response == 'CAPCHA_NOT_READY') { + return null; + } + + if (mb_strpos($response, 'OK|') !== 0) { + throw new ApiException('Cannot recognise api response (' . $response . ')'); + } + + return mb_substr($response, 3); + } } /** From 93862af324222e40f494dc5b1191ecce1fd9b182 Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Mon, 15 Sep 2025 12:58:56 +0300 Subject: [PATCH 03/11] send($captcha) --- examples/h_captcha.php | 19 +++++++++++++++++++ src/TwoCaptcha.php | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 examples/h_captcha.php diff --git a/examples/h_captcha.php b/examples/h_captcha.php new file mode 100644 index 0000000..efb0d14 --- /dev/null +++ b/examples/h_captcha.php @@ -0,0 +1,19 @@ +hcaptcha([ + 'sitekey' => 'c0421d06-b92e-47fc-ab9a-5caa43c04538', + 'url' => 'https://api.solvecaptcha.com/demo/hcaptcha', + 'json' => 1 + ]); +} catch (\Exception $e) { + die($e->getMessage()); +} + +die('Captcha solved: ' . $result->code); \ No newline at end of file diff --git a/src/TwoCaptcha.php b/src/TwoCaptcha.php index dffaa00..26ccd04 100644 --- a/src/TwoCaptcha.php +++ b/src/TwoCaptcha.php @@ -689,13 +689,48 @@ public function send($captcha) $response = $this->apiClient->in($captcha, $files); + $jsonObj = json_decode($response, true); + + if (json_last_error() === JSON_ERROR_NONE) { + $request = $jsonObj['request']; + $status = $jsonObj['status']; + + if ($request == "CAPCHA_NOT_READY") { + return null; + } + + if ($status == 1) { + return $request; + } + } else { + + if (mb_strpos($response, 'OK|') !== 0) { + throw new ApiException('Cannot recognise api response (' . $response . ')'); + } + + return mb_substr($response, 3); + } + } + + /* victor todo: remove + public function send($captcha) + { + $this->sendAttachDefaultParams($captcha); + + $files = $this->extractFiles($captcha); + + $this->mapParams($captcha, $captcha['method']); + $this->mapParams($files, $captcha['method']); + + $response = $this->apiClient->in($captcha, $files); + if (mb_strpos($response, 'OK|') !== 0) { throw new ApiException('Cannot recognise api response (' . $response . ')'); } return mb_substr($response, 3); } - +*/ /** * Returns result of captcha if it was solved or `null`, if result is not ready * @@ -712,7 +747,7 @@ public function getResult($id) 'json' => $this->json, ]); - + echo $response; $jsonObj = json_decode($response, true); if (json_last_error() === JSON_ERROR_NONE) { From 1e7b211b11a4d2b233ae7bd1ef385507ccd078b3 Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Mon, 15 Sep 2025 13:53:21 +0300 Subject: [PATCH 04/11] 'json' => 1 --- examples/h_captcha.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/h_captcha.php b/examples/h_captcha.php index efb0d14..6b2b9aa 100644 --- a/examples/h_captcha.php +++ b/examples/h_captcha.php @@ -4,7 +4,11 @@ require(__DIR__ . '/../src/autoloader.php'); -$solver = new \TwoCaptcha\TwoCaptcha('YOUR_API_KEY'); +$solver = new \TwoCaptcha\TwoCaptcha([ + 'apiKey' => 'YOUR_API_KEY', + 'server' => 'http://2captcha.com', + 'json' => 1 +]); try { $result = $solver->hcaptcha([ From c835db6f0cff96ed310e32fe5d6f917b0bf0b64e Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Tue, 16 Sep 2025 15:15:27 +0300 Subject: [PATCH 05/11] strpos(json_encode($response), 'ERROR_' --- examples/h_captcha.php | 3 +-- src/ApiClient.php | 5 +++-- src/TwoCaptcha.php | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/h_captcha.php b/examples/h_captcha.php index 6b2b9aa..cd709df 100644 --- a/examples/h_captcha.php +++ b/examples/h_captcha.php @@ -13,8 +13,7 @@ try { $result = $solver->hcaptcha([ 'sitekey' => 'c0421d06-b92e-47fc-ab9a-5caa43c04538', - 'url' => 'https://api.solvecaptcha.com/demo/hcaptcha', - 'json' => 1 + 'url' => 'https://api.solvecaptcha.com/demo/hcaptcha' ]); } catch (\Exception $e) { die($e->getMessage()); diff --git a/src/ApiClient.php b/src/ApiClient.php index dd9e76e..ced9d75 100644 --- a/src/ApiClient.php +++ b/src/ApiClient.php @@ -18,7 +18,8 @@ class ApiClient * ApiClient constructor. * @param $options string */ - public function __construct($options) { + public function __construct($options) + { if (is_string($options)) { $this->server = $options; } @@ -101,7 +102,7 @@ private function execute() throw new NetworkException(curl_error($this->curl)); } - if (mb_strpos($response, 'ERROR_') === 0) { + if (strpos(json_encode($response), 'ERROR_') !== false) { throw new ApiException($response); } diff --git a/src/TwoCaptcha.php b/src/TwoCaptcha.php index 26ccd04..fa97adc 100644 --- a/src/TwoCaptcha.php +++ b/src/TwoCaptcha.php @@ -834,6 +834,7 @@ private function res($query) private function sendAttachDefaultParams(&$captcha) { $captcha['key'] = $this->apiKey; + $captcha['json'] = $this->json; if ($this->callback) { if (!isset($captcha['callback'])) { From 8a182068df9b5a578ca945af03b23e8a8e80f479 Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Wed, 17 Sep 2025 12:12:08 +0300 Subject: [PATCH 06/11] echo --- src/TwoCaptcha.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/TwoCaptcha.php b/src/TwoCaptcha.php index fa97adc..5f22428 100644 --- a/src/TwoCaptcha.php +++ b/src/TwoCaptcha.php @@ -747,7 +747,6 @@ public function getResult($id) 'json' => $this->json, ]); - echo $response; $jsonObj = json_decode($response, true); if (json_last_error() === JSON_ERROR_NONE) { From 7c5b92cd339ed35d3c1dd3d8aac19b4160c0b99f Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Fri, 19 Sep 2025 09:06:29 +0300 Subject: [PATCH 07/11] json param added --- tests/AbstractWrapperTestCase.php | 3 ++- tests/HCaptchaTest.php | 3 ++- tests/LeminTest.php | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/AbstractWrapperTestCase.php b/tests/AbstractWrapperTestCase.php index 11d2c7c..c52c6b2 100644 --- a/tests/AbstractWrapperTestCase.php +++ b/tests/AbstractWrapperTestCase.php @@ -23,6 +23,7 @@ protected function checkIfCorrectParamsSendAndResultReturned($data) $apiKey = 'API_KEY'; $captchaId = '123'; $code = '2763'; + $json = '0'; $apiClient = $this->createMock(ApiClient::class); @@ -40,7 +41,7 @@ protected function checkIfCorrectParamsSendAndResultReturned($data) $apiClient ->expects($this->once()) ->method('res') - ->with($this->equalTo(['action' => 'get', 'id' => $captchaId, 'key' => $apiKey])) + ->with($this->equalTo(['action' => 'get', 'id' => $captchaId, 'key' => $apiKey, 'json' => $json])) ->willReturn('OK|' . $code); $solver = new TwoCaptcha([ diff --git a/tests/HCaptchaTest.php b/tests/HCaptchaTest.php index 9f59b75..ad2b62d 100644 --- a/tests/HCaptchaTest.php +++ b/tests/HCaptchaTest.php @@ -23,7 +23,8 @@ public function testAllOptions() 'pageurl' => 'https://www.site.com/page/', 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', - 'soft_id' => '4585', + 'soft_id' => 4585, + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ diff --git a/tests/LeminTest.php b/tests/LeminTest.php index 851ff41..22c1a86 100644 --- a/tests/LeminTest.php +++ b/tests/LeminTest.php @@ -26,6 +26,7 @@ public function testAllOptions() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ From 136757ea7d976847d869b658e72c4c37831f10fc Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Fri, 19 Sep 2025 11:24:28 +0300 Subject: [PATCH 08/11] 'json' => '0' --- tests/AmazonWafTest.php | 1 + tests/AtbCaptchaTest.php | 1 + tests/AudioTest.php | 1 + tests/CanvasTest.php | 1 + tests/CapyTest.php | 1 + tests/CoordinatesTest.php | 1 + tests/CutcaptchaTest.php | 1 + tests/CyberSiaraTest.php | 1 + tests/DatadomeTest.php | 1 + tests/FriendlyCaptchaTest.php | 1 + tests/FunCaptchaTest.php | 1 + tests/GeeTest.php | 1 + tests/GeeTestV4.php | 1 + tests/GridTest.php | 1 + tests/KeyCaptchaTest.php | 1 + tests/MTCaptchaTest.php | 1 + tests/NormalTest.php | 1 + tests/ReCaptchaTest.php | 1 + tests/RotateTest.php | 1 + tests/TencentTest.php | 1 + tests/TextTest.php | 6 +++--- tests/TurnstileTest.php | 1 + tests/YandexTest.php | 1 + 23 files changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/AmazonWafTest.php b/tests/AmazonWafTest.php index 7f00011..c0cbd70 100644 --- a/tests/AmazonWafTest.php +++ b/tests/AmazonWafTest.php @@ -28,6 +28,7 @@ public function testAllOptions() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ diff --git a/tests/AtbCaptchaTest.php b/tests/AtbCaptchaTest.php index 48f7d44..7022d25 100644 --- a/tests/AtbCaptchaTest.php +++ b/tests/AtbCaptchaTest.php @@ -26,6 +26,7 @@ public function testAllOptions() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ diff --git a/tests/AudioTest.php b/tests/AudioTest.php index 84ba00d..4e27610 100644 --- a/tests/AudioTest.php +++ b/tests/AudioTest.php @@ -21,6 +21,7 @@ public function test() 'method' => 'audio', 'body' => base64_encode(file_get_contents($audio)), 'soft_id' => '4585', + 'json' => '0' ]; diff --git a/tests/CanvasTest.php b/tests/CanvasTest.php index b5140e1..c27fba8 100644 --- a/tests/CanvasTest.php +++ b/tests/CanvasTest.php @@ -58,6 +58,7 @@ public function testAllParameters() 'recaptcha' => 1, 'textinstructions' => $this->hintText, 'soft_id' => '4585', + 'json' => '0' ]; $sendFiles = [ diff --git a/tests/CapyTest.php b/tests/CapyTest.php index 8d9e8a2..871bc39 100644 --- a/tests/CapyTest.php +++ b/tests/CapyTest.php @@ -18,6 +18,7 @@ public function testAllOptions() 'captchakey' => 'PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v', 'pageurl' => 'http://mysite.com/', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ diff --git a/tests/CoordinatesTest.php b/tests/CoordinatesTest.php index 0159200..f20581a 100644 --- a/tests/CoordinatesTest.php +++ b/tests/CoordinatesTest.php @@ -52,6 +52,7 @@ public function testAllParameters() 'lang' => 'en', 'textinstructions' => 'Select all images with an Orange', 'soft_id' => '4585', + 'json' => '0' ]; $sendFiles = [ diff --git a/tests/CutcaptchaTest.php b/tests/CutcaptchaTest.php index b70c7d9..693a9c2 100644 --- a/tests/CutcaptchaTest.php +++ b/tests/CutcaptchaTest.php @@ -26,6 +26,7 @@ public function testAllOptions() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ diff --git a/tests/CyberSiaraTest.php b/tests/CyberSiaraTest.php index 34e2241..5a8f1f2 100644 --- a/tests/CyberSiaraTest.php +++ b/tests/CyberSiaraTest.php @@ -26,6 +26,7 @@ public function testAllOptions() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ diff --git a/tests/DatadomeTest.php b/tests/DatadomeTest.php index 6acec6f..8afd20c 100644 --- a/tests/DatadomeTest.php +++ b/tests/DatadomeTest.php @@ -26,6 +26,7 @@ public function testAllOptions() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ diff --git a/tests/FriendlyCaptchaTest.php b/tests/FriendlyCaptchaTest.php index d4e927f..8e9b375 100644 --- a/tests/FriendlyCaptchaTest.php +++ b/tests/FriendlyCaptchaTest.php @@ -24,6 +24,7 @@ public function testAllOptions() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ diff --git a/tests/FunCaptchaTest.php b/tests/FunCaptchaTest.php index f345ba2..e641bef 100644 --- a/tests/FunCaptchaTest.php +++ b/tests/FunCaptchaTest.php @@ -30,6 +30,7 @@ public function testAllOptions() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ diff --git a/tests/GeeTest.php b/tests/GeeTest.php index 9766155..a814066 100644 --- a/tests/GeeTest.php +++ b/tests/GeeTest.php @@ -28,6 +28,7 @@ public function testAllOptions() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ diff --git a/tests/GeeTestV4.php b/tests/GeeTestV4.php index 960b2bc..b967b06 100644 --- a/tests/GeeTestV4.php +++ b/tests/GeeTestV4.php @@ -26,6 +26,7 @@ public function testAllOptions() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; diff --git a/tests/GridTest.php b/tests/GridTest.php index a77fc13..54ffde5 100644 --- a/tests/GridTest.php +++ b/tests/GridTest.php @@ -59,6 +59,7 @@ public function testAllParameters() 'lang' => 'en', 'textinstructions' => 'Select all images with an Orange', 'soft_id' => '4585', + 'json' => '0' ]; $sendFiles = [ diff --git a/tests/KeyCaptchaTest.php b/tests/KeyCaptchaTest.php index f146378..89545f5 100644 --- a/tests/KeyCaptchaTest.php +++ b/tests/KeyCaptchaTest.php @@ -30,6 +30,7 @@ public function testAllOptions() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ diff --git a/tests/MTCaptchaTest.php b/tests/MTCaptchaTest.php index 4b52179..c79ddcc 100644 --- a/tests/MTCaptchaTest.php +++ b/tests/MTCaptchaTest.php @@ -24,6 +24,7 @@ public function testAllOptions() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ diff --git a/tests/NormalTest.php b/tests/NormalTest.php index 778e617..f5af55c 100644 --- a/tests/NormalTest.php +++ b/tests/NormalTest.php @@ -63,6 +63,7 @@ public function testAllParameters() 'lang' => 'en', 'textinstructions' => 'Type red symbols only', 'soft_id' => '4585', + 'json' => '0' ]; $sendFiles = [ diff --git a/tests/ReCaptchaTest.php b/tests/ReCaptchaTest.php index e99085f..2c652e1 100644 --- a/tests/ReCaptchaTest.php +++ b/tests/ReCaptchaTest.php @@ -28,6 +28,7 @@ public function testV2() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ diff --git a/tests/RotateTest.php b/tests/RotateTest.php index 64c47c3..f4d3d94 100644 --- a/tests/RotateTest.php +++ b/tests/RotateTest.php @@ -25,6 +25,7 @@ public function testAllParameters() 'textinstructions' => 'Put the images in the correct way up', 'body' => '...', 'soft_id' => '4585', + 'json' => '0' ]; $sendFiles = [ diff --git a/tests/TencentTest.php b/tests/TencentTest.php index cb70549..3604844 100644 --- a/tests/TencentTest.php +++ b/tests/TencentTest.php @@ -24,6 +24,7 @@ public function testAllOptions() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ diff --git a/tests/TextTest.php b/tests/TextTest.php index 2737955..c3fcaf2 100644 --- a/tests/TextTest.php +++ b/tests/TextTest.php @@ -10,7 +10,7 @@ public function testSimpleText() { $this->checkIfCorrectParamsSendAndResultReturned([ 'params' => 'Today is monday?', - 'sendParams' => ['method' => 'post', 'textcaptcha' => 'Today is monday?','soft_id' => '4585'], + 'sendParams' => ['method' => 'post', 'textcaptcha' => 'Today is monday?','soft_id' => '4585','json' => '0'], 'sendFiles' => [], ]); } @@ -19,7 +19,7 @@ public function testTextParameter() { $this->checkIfCorrectParamsSendAndResultReturned([ 'params' => ['text' => 'Today is monday?'], - 'sendParams' => ['method' => 'post', 'textcaptcha' => 'Today is monday?','soft_id' => '4585'], + 'sendParams' => ['method' => 'post', 'textcaptcha' => 'Today is monday?','soft_id' => '4585','json' => '0'], 'sendFiles' => [], ]); } @@ -28,7 +28,7 @@ public function testAllParameters() { $this->checkIfCorrectParamsSendAndResultReturned([ 'params' => ['text' => 'Today is monday?', 'lang' => 'en'], - 'sendParams' => ['method' => 'post', 'textcaptcha' => 'Today is monday?', 'lang' => 'en','soft_id' => '4585'], + 'sendParams' => ['method' => 'post', 'textcaptcha' => 'Today is monday?', 'lang' => 'en','soft_id' => '4585','json' => '0'], 'sendFiles' => [], ]); } diff --git a/tests/TurnstileTest.php b/tests/TurnstileTest.php index 457c86b..e4f51ee 100644 --- a/tests/TurnstileTest.php +++ b/tests/TurnstileTest.php @@ -24,6 +24,7 @@ public function testAllOptions() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ diff --git a/tests/YandexTest.php b/tests/YandexTest.php index dc71cab..a8f5965 100644 --- a/tests/YandexTest.php +++ b/tests/YandexTest.php @@ -24,6 +24,7 @@ public function testAllOptions() 'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321', 'proxytype' => 'HTTPS', 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ From 3f3ceaee8cb03708513fcf432c7ce9bcc98b400d Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Fri, 19 Sep 2025 13:38:33 +0300 Subject: [PATCH 09/11] json param added --- tests/AudioTest.php | 3 ++- tests/CanvasTest.php | 4 ++-- tests/CoordinatesTest.php | 6 +++--- tests/GridTest.php | 6 +++--- tests/NormalTest.php | 6 +++--- tests/ReCaptchaTest.php | 1 + 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/AudioTest.php b/tests/AudioTest.php index 4e27610..718e58e 100644 --- a/tests/AudioTest.php +++ b/tests/AudioTest.php @@ -21,7 +21,7 @@ public function test() 'method' => 'audio', 'body' => base64_encode(file_get_contents($audio)), 'soft_id' => '4585', - 'json' => '0' + 'json' => '0' ]; @@ -48,6 +48,7 @@ public function testAllParameters() 'body' => base64_encode(file_get_contents($audio)), 'lang' => 'ru', 'soft_id' => '4585', + 'json' => '0' ]; diff --git a/tests/CanvasTest.php b/tests/CanvasTest.php index c27fba8..32e11d2 100644 --- a/tests/CanvasTest.php +++ b/tests/CanvasTest.php @@ -22,7 +22,7 @@ public function testSingleFileParameter() { $this->checkIfCorrectParamsSendAndResultReturned([ 'params' => ['file' => $this->captchaImg, 'hintText' => $this->hintText], - 'sendParams' => ['method' => 'post', 'canvas' => 1, 'recaptcha' => 1, 'textinstructions' => $this->hintText, 'soft_id' => '4585'], + 'sendParams' => ['method' => 'post', 'canvas' => 1, 'recaptcha' => 1, 'textinstructions' => $this->hintText, 'soft_id' => '4585', 'json' => '0'], 'sendFiles' => ['file' => $this->captchaImg], ]); } @@ -31,7 +31,7 @@ public function testBase64() { $this->checkIfCorrectParamsSendAndResultReturned([ 'params' => ['base64' => '...', 'hintText' => $this->hintText], - 'sendParams' => ['method' => 'base64', 'canvas' => 1, 'body' => '...', 'recaptcha' => 1, 'textinstructions' => $this->hintText, 'soft_id' => '4585'], + 'sendParams' => ['method' => 'base64', 'canvas' => 1, 'body' => '...', 'recaptcha' => 1, 'textinstructions' => $this->hintText, 'soft_id' => '4585', 'json' => '0'], 'sendFiles' => [], ]); } diff --git a/tests/CoordinatesTest.php b/tests/CoordinatesTest.php index f20581a..1bbf0ed 100644 --- a/tests/CoordinatesTest.php +++ b/tests/CoordinatesTest.php @@ -12,7 +12,7 @@ public function testSingleFile() { $this->checkIfCorrectParamsSendAndResultReturned([ 'params' => $this->captchaImg, - 'sendParams' => ['method' => 'post', 'coordinatescaptcha' => 1, 'soft_id' => '4585'], + 'sendParams' => ['method' => 'post', 'coordinatescaptcha' => 1, 'soft_id' => '4585', 'json' => '0'], 'sendFiles' => ['file' => $this->captchaImg], ]); } @@ -21,7 +21,7 @@ public function testSingleFileParameter() { $this->checkIfCorrectParamsSendAndResultReturned([ 'params' => ['file' => $this->captchaImg], - 'sendParams' => ['method' => 'post', 'coordinatescaptcha' => 1,'soft_id' => '4585'], + 'sendParams' => ['method' => 'post', 'coordinatescaptcha' => 1,'soft_id' => '4585', 'json' => '0'], 'sendFiles' => ['file' => $this->captchaImg], ]); } @@ -30,7 +30,7 @@ public function testBase64() { $this->checkIfCorrectParamsSendAndResultReturned([ 'params' => ['base64' => '...'], - 'sendParams' => ['method' => 'base64', 'coordinatescaptcha' => 1, 'body' => '...','soft_id' => '4585'], + 'sendParams' => ['method' => 'base64', 'coordinatescaptcha' => 1, 'body' => '...','soft_id' => '4585', 'json' => '0'], 'sendFiles' => [], ]); } diff --git a/tests/GridTest.php b/tests/GridTest.php index 54ffde5..5967420 100644 --- a/tests/GridTest.php +++ b/tests/GridTest.php @@ -12,7 +12,7 @@ public function testSingleFile() { $this->checkIfCorrectParamsSendAndResultReturned([ 'params' => $this->captchaImg, - 'sendParams' => ['method' => 'post','soft_id' => '4585'], + 'sendParams' => ['method' => 'post','soft_id' => '4585', 'json' => '0'], 'sendFiles' => ['file' => $this->captchaImg], ]); } @@ -21,7 +21,7 @@ public function testSingleFileParameter() { $this->checkIfCorrectParamsSendAndResultReturned([ 'params' => ['file' => $this->captchaImg], - 'sendParams' => ['method' => 'post','soft_id' => '4585'], + 'sendParams' => ['method' => 'post','soft_id' => '4585', 'json' => '0'], 'sendFiles' => ['file' => $this->captchaImg], ]); } @@ -30,7 +30,7 @@ public function testBase64() { $this->checkIfCorrectParamsSendAndResultReturned([ 'params' => ['base64' => '...'], - 'sendParams' => ['method' => 'base64', 'body' => '...','soft_id' => '4585'], + 'sendParams' => ['method' => 'base64', 'body' => '...','soft_id' => '4585', 'json' => '0'], 'sendFiles' => [], ]); } diff --git a/tests/NormalTest.php b/tests/NormalTest.php index f5af55c..97e7a45 100644 --- a/tests/NormalTest.php +++ b/tests/NormalTest.php @@ -12,7 +12,7 @@ public function testSingleFile() { $this->checkIfCorrectParamsSendAndResultReturned([ 'params' => $this->captchaImg, - 'sendParams' => ['method' => 'post','soft_id' => '4585'], + 'sendParams' => ['method' => 'post','soft_id' => '4585', 'json' => '0'], 'sendFiles' => ['file' => $this->captchaImg], ]); } @@ -21,7 +21,7 @@ public function testSingleFileParameter() { $this->checkIfCorrectParamsSendAndResultReturned([ 'params' => ['file' => $this->captchaImg], - 'sendParams' => ['method' => 'post','soft_id' => '4585'], + 'sendParams' => ['method' => 'post','soft_id' => '4585', 'json' => '0'], 'sendFiles' => ['file' => $this->captchaImg], ]); } @@ -30,7 +30,7 @@ public function testBase64() { $this->checkIfCorrectParamsSendAndResultReturned([ 'params' => ['base64' => '...'], - 'sendParams' => ['method' => 'base64', 'body' => '...','soft_id' => '4585'], + 'sendParams' => ['method' => 'base64', 'body' => '...','soft_id' => '4585', 'json' => '0'], 'sendFiles' => [], ]); } diff --git a/tests/ReCaptchaTest.php b/tests/ReCaptchaTest.php index 2c652e1..4a4cfd7 100644 --- a/tests/ReCaptchaTest.php +++ b/tests/ReCaptchaTest.php @@ -56,6 +56,7 @@ public function testV3() 'action' => 'verify', 'min_score' => 0.3, 'soft_id' => '4585', + 'json' => '0' ]; $this->checkIfCorrectParamsSendAndResultReturned([ From b7d856788dab6998219304b5532f8f8011240d1b Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Mon, 22 Sep 2025 10:20:46 +0300 Subject: [PATCH 10/11] hCaptcha readme --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6105836..250aff4 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ $solver = new \TwoCaptcha\TwoCaptcha([ 'defaultTimeout' => 120, 'recaptchaTimeout' => 600, 'pollingInterval' => 10, + 'json' => 1, ]); ``` @@ -92,11 +93,12 @@ $solver = new \TwoCaptcha\TwoCaptcha([ | Option | Default value | Description | | ---------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | -| softId | 4585 | your software ID obtained after publishing in [2captcha software catalog] | +| softId | 4585 | your software ID obtained after publishing in [2captcha software catalog] | | callback | - | URL of your web-sever that receives the captcha recognition result. The URl should be first registered in [pingback settings] of your account | | defaultTimeout | 120 | Polling timeout in seconds for all captcha types except reCAPTCHA. Defines how long the module tries to get the answer from `res.php` API endpoint | | recaptchaTimeout | 600 | Polling timeout for reCAPTCHA in seconds. Defines how long the module tries to get the answer from `res.php` API endpoint | | pollingInterval | 10 | Interval in seconds between requests to `res.php` API endpoint, setting values less than 5 seconds is not recommended | +| json | 0 | Json or String format response from `res.php` API endpoint, json = 1 returns JSON format response | > [!IMPORTANT] > Once `callback` is defined for `TwoCaptcha` instance, all methods return only the captcha ID and DO NOT poll the API to get the result. The result will be sent to the callback URL. @@ -444,6 +446,18 @@ $result = $solver->cybersiara([ ]); ``` +### hCaptcha + +[API method description.](https://2captcha.com/2captcha-api#hCaptcha) + +Use this method to bypass hCaptcha. + +```php +$result = $solver->hcaptcha([ + 'sitekey' => 'c0421d06-b92e-47fc-ab9a-5caa43c04538', + 'url' => 'https://api.solvecaptcha.com/demo/hcaptcha' +]); +``` ## Other methods From 043a45d65f18de6bcf57d8f6bebab2899056f8f0 Mon Sep 17 00:00:00 2001 From: victorkowalski Date: Thu, 25 Sep 2025 16:07:07 +0300 Subject: [PATCH 11/11] rm --- examples/h_captcha.php | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 examples/h_captcha.php diff --git a/examples/h_captcha.php b/examples/h_captcha.php deleted file mode 100644 index cd709df..0000000 --- a/examples/h_captcha.php +++ /dev/null @@ -1,22 +0,0 @@ - 'YOUR_API_KEY', - 'server' => 'http://2captcha.com', - 'json' => 1 -]); - -try { - $result = $solver->hcaptcha([ - 'sitekey' => 'c0421d06-b92e-47fc-ab9a-5caa43c04538', - 'url' => 'https://api.solvecaptcha.com/demo/hcaptcha' - ]); -} catch (\Exception $e) { - die($e->getMessage()); -} - -die('Captcha solved: ' . $result->code); \ No newline at end of file