Skip to content

Commit 2716af3

Browse files
NEW added captcha tasks
1 parent c38120d commit 2716af3

File tree

4 files changed

+104
-3
lines changed

4 files changed

+104
-3
lines changed

Diff for: hcaptcha.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ function test_api() {
1919

2020
// extra parameters, useful for enterprise
2121
// submit userAgent from requests too, when this is used
22-
# $params['HcaptchaEnterprise'] = array(
23-
# "rqdata" => "take value from web requests"
24-
# );
22+
// $params['HcaptchaEnterprise'] = array(
23+
// "rqdata" => "take value from web requests"
24+
// );
2525

2626
//$params['proxy'] = '126.45.34.53:123'; // - optional
2727
//$params['user_agent'] = 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0'; // - optional

Diff for: lib/imagetyperzapi.php

+30
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
define('HCAPTCHA_ENDPOINT', 'http://captchatypers.com/captchaapi/UploadHCaptchaUser.ashx');
1616
define('TIKTOK_ENDPOINT', 'http://captchatypers.com/captchaapi/UploadTikTokCaptchaUser.ashx');
1717
define('FUNCAPTCHA_ENDPOINT', 'http://captchatypers.com/captchaapi/UploadFunCaptcha.ashx');
18+
define('TASK_ENDPOINT', 'http://captchatypers.com/captchaapi/UploadCaptchaTask.ashx');
1819

1920
define('CAPTCHA_ENDPOINT_CONTENT_TOKEN', 'http://captchatypers.com/Forms/UploadFileAndGetTextNEWToken.ashx');
2021
define('CAPTCHA_ENDPOINT_URL_TOKEN', 'http://captchatypers.com/Forms/FileUploadAndGetTextCaptchaURLToken.ashx');
@@ -427,6 +428,35 @@ function submit_funcaptcha($d) {
427428
return json_decode($response, true)[0]['CaptchaId'];
428429
}
429430

431+
function submit_task($d) {
432+
$d['captchatype'] = '16';
433+
$d['action'] = 'UPLOADCAPTCHA';
434+
435+
if (!empty($this->_username)) {
436+
$d["username"] = $this->_username;
437+
$d["password"] = $this->_password;
438+
} else {
439+
$d['token'] = $this->_access_token;
440+
}
441+
442+
// affiliate
443+
if (!empty($this->_affiliate_id)) {
444+
$d['affiliateid'] = $this->_affiliate_id;
445+
}
446+
447+
if (isset($d['variables'])) {
448+
$d['variables'] = json_encode($d['variables']);
449+
}
450+
451+
// check for user agent
452+
if (isset($d['user_agent'])) $d["useragent"] = $d['user_agent'];
453+
$response = Utils::post(TASK_ENDPOINT, $d, USER_AGENT, $this->_timeout);
454+
if (strpos($response, 'ERROR:') !== false) {
455+
throw new Exception(trim(explode('ERROR:', $response)[1]));
456+
}
457+
return json_decode($response, true)[0]['CaptchaId'];
458+
}
459+
430460
function retrieve_response($captcha_id) {
431461
$data = array(
432462
"action" => "GETTEXT",

Diff for: readme.md

+25
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ $params = array();
160160
$params['page_url'] = 'https://your-site.com';
161161
$params['sitekey'] = '1c7062c7-cae6-4e12-96fb-303fbec7fe4f';
162162
//$params['invisible'] = '1'; // if captcha is invisible - optional
163+
164+
// extra parameters, useful for enterprise
165+
// submit userAgent from requests too, when this is used
166+
// $params['HcaptchaEnterprise'] = array(
167+
// "rqdata" => "take value from web requests"
168+
// );
169+
163170
//$params['proxy'] = '126.45.34.53:123'; // - optional
164171
//$params['user_agent'] = 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0'; // - optional
165172
$captcha_id = $i->submit_hcaptcha($params);
@@ -206,6 +213,24 @@ $params['data'] = '{"a":"b"}';
206213
$captcha_id = $i->submit_funcaptcha($params);
207214
```
208215

216+
### Task
217+
218+
Requires template_name, pageurl and usually variables
219+
220+
```php
221+
$params = array();
222+
$params['template_name'] = 'Login test page';
223+
$params['sitekey'] = '1c7062c7-cae6-4e12-96fb-303fbec7fe4f';
224+
$params['pageurl'] = 'https://imagetyperz.net/automation/login';
225+
$params['variables'] = array(
226+
"username" => "abc",
227+
"password" => 'paZZW0rd'
228+
);
229+
//$params['proxy'] = '126.45.34.53:123'; // - optional
230+
//$params['user_agent'] = 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0'; // - optional
231+
$captcha_id = $i->submit_task($params);
232+
```
233+
209234
## Retrieve response
210235

211236
Regardless of the captcha type (and method) used in submission of the captcha, this method is used

Diff for: task.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/php
2+
3+
<?php
4+
require('lib/imagetyperzapi.php'); // load API library
5+
6+
function test_api() {
7+
# grab token from https://imagetyperz.com
8+
$access_token = 'your_access_token';
9+
$i = new ImagetyperzAPI($access_token); // init API lib obj
10+
11+
$balance = $i->account_balance(); // get balance
12+
echo "Balance: $balance\n";
13+
14+
echo "Solving captcha ...\n";
15+
$params = array();
16+
$params['template_name'] = 'Login test page';
17+
$params['pageurl'] = 'https://imagetyperz.net/automation/login';
18+
$params['variables'] = array(
19+
"username" => "abc",
20+
"password" => 'paZZW0rd'
21+
);
22+
23+
//$params['proxy'] = '126.45.34.53:123'; // - optional
24+
//$params['user_agent'] = 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0'; // - optional
25+
$captcha_id = $i->submit_task($params);
26+
echo "Waiting for captcha to be solved...\n";
27+
$response = null;
28+
while($response === null) {
29+
sleep(10);
30+
$response = $i->retrieve_response($captcha_id);
31+
}
32+
echo "Response: ";
33+
var_dump($response);
34+
}
35+
36+
// Main method
37+
function main() {
38+
try {
39+
test_api(); // test API
40+
} catch (Exception $ex) {
41+
echo "Error occured: " . $ex->getMessage(); // print error
42+
}
43+
}
44+
45+
main(); // run main function
46+
?>

0 commit comments

Comments
 (0)