Skip to content

Commit a7086f7

Browse files
Add atbCaptcha method
1 parent 60ee9e7 commit a7086f7

File tree

5 files changed

+117
-2
lines changed

5 files changed

+117
-2
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Examples of API requests for different captcha types are available on the [JavaS
4242
- [KeyCaptcha](#keycaptcha)
4343
- [Cutcaptcha](#cutcaptcha)
4444
- [Tencent](#tencent)
45+
- [atbCAPTCHA](#atbcaptcha)
4546
- [Other methods](#other-methods)
4647
- [goodReport](#goodreport)
4748
- [badReport](#badreport)
@@ -625,6 +626,26 @@ console.log(err);
625626
})
626627
```
627628

629+
### atbCAPTCHA
630+
631+
<sup>[API method description.](https://2captcha.com/2captcha-api#atb-captcha)</sup>
632+
633+
Use this method to solve atbCAPTCHA challenge. Returns a token to bypass the captcha.
634+
635+
```js
636+
solver.atbCaptcha({
637+
pageurl: "https://mysite.com/page/with/atbCAPTCHA",
638+
appId: "af25e409b33d722a95e56a230ff8771c",
639+
apiServer: "https://cap.aisecurius.com"
640+
})
641+
.then((res) => {
642+
console.log(res);
643+
})
644+
.catch((err) => {
645+
console.log(err);
646+
})
647+
```
648+
628649
## Other methods
629650

630651
### goodReport

examples/atbcaptcha.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const TwoCaptcha = require("../dist/index.js");
2+
require('dotenv').config();
3+
const APIKEY = process.env.APIKEY
4+
const solver = new TwoCaptcha.Solver(APIKEY);
5+
6+
solver.atbCaptcha({
7+
pageurl: "https://mysite.com/page/with/atbCAPTCHA",
8+
appId: "af25e409b33d722a95e56a230ff8771c",
9+
apiServer: "https://cap.aisecurius.com"
10+
})
11+
.then((res) => {
12+
console.log(res);
13+
})
14+
.catch((err) => {
15+
console.log(err);
16+
})

src/structs/2captcha.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,15 @@ export interface paramsTencent {
282282
proxytype?: string
283283
}
284284

285+
export interface paramsAtbCaptcha{
286+
pageurl: string,
287+
appId: string,
288+
apiServer: string,
289+
pingback?: string,
290+
proxy?: string,
291+
proxytype?: string
292+
}
293+
285294
/**
286295
* An object containing properties of the captcha solution.
287296
* @typedef {Object} CaptchaAnswer
@@ -1780,6 +1789,68 @@ public async tencent(params: paramsTencent): Promise<CaptchaAnswer> {
17801789
}
17811790
}
17821791

1792+
/**
1793+
* ### Solves a atbCAPTCHA.
1794+
*
1795+
* Use this method to solve atbCAPTCHA captcha. Returns a token.
1796+
* [Read more about atbCAPTCHA](https://2captcha.com/2captcha-api#atb-captcha).
1797+
*
1798+
* @param {{ pageurl, appId, apiServer, pingback, proxy, proxytype }} params Parameters for solving atbCAPTCHA as an object.
1799+
* @param {string} params.pageurl The URL where the captcha is located.
1800+
* @param {string} params.appId The value of `appId` parameter in the website source code.
1801+
* @param {string} params.apiServer The value of `apiServer` parameter in the website source code.
1802+
* @param {string} [params.pingback] Optional param. URL for pingback (callback) response when captcha is solved.
1803+
* @param {string} [params.proxy] Optional param. Proxy to use while solving the captcha. Format: `login:password@123.123.123.123:3128`.
1804+
* @param {string} [params.proxytype] Optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1805+
*
1806+
* @returns {Promise<CaptchaAnswer>} The result from the solve.
1807+
* @throws APIError
1808+
*
1809+
* @example
1810+
* solver.atbCaptcha({
1811+
* pageurl: "https://mysite.com/page/with/tencent",
1812+
* appId: "af25e409b33d722a95e56a230ff8771c",
1813+
apiServer: "https://cap.aisecurius.com"
1814+
* })
1815+
* .then((res) => {
1816+
* console.log(res);
1817+
* })
1818+
* .catch((err) => {
1819+
* console.log(err);
1820+
* })
1821+
*/
1822+
public async atbCaptcha(params: paramsAtbCaptcha): Promise<CaptchaAnswer> {
1823+
params = await renameParams(params)
1824+
checkCaptchaParams(params, "atb_captcha")
1825+
1826+
const payload = {
1827+
...params,
1828+
method: "atb_captcha",
1829+
...this.defaultPayload,
1830+
}
1831+
1832+
const URL = this.in
1833+
const response = await fetch(URL, {
1834+
body: JSON.stringify(payload),
1835+
method: "post",
1836+
headers: {'Content-Type': 'application/json'}
1837+
})
1838+
const result = await response.text()
1839+
1840+
let data;
1841+
try {
1842+
data = JSON.parse(result)
1843+
} catch {
1844+
throw new APIError(result)
1845+
}
1846+
1847+
if (data.status == 1) {
1848+
return this.pollResponse(data.request)
1849+
} else {
1850+
throw new APIError(data.request)
1851+
}
1852+
}
1853+
17831854
/**
17841855
* Reports a captcha as correctly solved.
17851856
*

src/utils/checkCaptchaParams.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Captcha methods for which parameter checking is available
22
const supportedMethods = ["userrecaptcha", "hcaptcha", "geetest", "geetest_v4","yandex","funcaptcha","lemin","amazon_waf",
3-
"turnstile", "base64", "capy","datadome", "cybersiara", "mt_captcha", "bounding_box", 'friendly_captcha', 'grid', 'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent']
3+
"turnstile", "base64", "capy","datadome", "cybersiara", "mt_captcha", "bounding_box", 'friendly_captcha', 'grid', 'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent', 'atb_captcha']
44

55
// Names of required fields that must be contained in the parameters captcha
66
const recaptchaRequiredFields = ['pageurl','googlekey']
@@ -26,7 +26,8 @@ const canvasRequiredFields = ['body'] // and textinstructions or imginstruc
2626
const rotateRequiredFields = ['body']
2727
const keycaptchaRequiredFields = ['pageurl', 's_s_c_user_id', 's_s_c_session_id', 's_s_c_web_server_sign', 's_s_c_web_server_sign2']
2828
const cutcaptchaRequiredFields = ['pageurl', 'misery_key', 'api_key']
29-
const tencentRequiredFields = ['pageurl', 'app_id']
29+
const tencentRequiredFields = ['pageurl', 'app_id']
30+
const atbCaptchaRequiredFields = ['pageurl', 'app_id', 'api_server']
3031

3132
/**
3233
* Getting required arguments for a captcha.
@@ -107,6 +108,9 @@ const getRequiredFildsArr = (method: string):Array<string> => {
107108
case "tencent":
108109
requiredFieldsArr = tencentRequiredFields
109110
break;
111+
case "atb_captcha":
112+
requiredFieldsArr = atbCaptchaRequiredFields
113+
break;
110114
}
111115
return requiredFieldsArr
112116
}

src/utils/renameParams.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export default function renameParams(params: any) {
3636

3737
// Tencent
3838
"appId": "app_id",
39+
40+
// atbCAPTCHA
41+
"apiServer": "api_server",
3942
}
4043

4144
for(let key in params) {

0 commit comments

Comments
 (0)