Skip to content

Commit e832b59

Browse files
authored
Add TSPD captcha support (#34)
1 parent 70332fb commit e832b59

6 files changed

Lines changed: 136 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Examples of API requests for different captcha types are available on the [JavaS
5252
- [Audio Captcha](#audio-captcha)
5353
- [Yidun NECaptcha](#yidun-necaptcha)
5454
- [Alibaba Captcha](#alibaba-captcha)
55+
- [TSPD](#tspd)
5556
- [Other methods](#other-methods)
5657
- [goodReport](#goodreport)
5758
- [badReport](#badreport)
@@ -859,6 +860,33 @@ console.log(err);
859860
})
860861
```
861862

863+
### TSPD
864+
865+
<sup>[API method description.](https://2captcha.com/2captcha-api#tspd)</sup>
866+
867+
Cookie-based method for automatic solving of TSPD captcha. Returns cookies that can be used to access the target page.
868+
869+
Required parameters: `pageurl`, `tspdCookie`, `htmlPageBase64`, `proxy`, `proxytype`.
870+
871+
**Important:** `tspdCookie` and `htmlPageBase64` are dynamic — extract them immediately before creating the task. A proxy with a static session and the same IP must be used at all stages.
872+
873+
```js
874+
solver.tspd({
875+
pageurl: "https://example.com/login",
876+
tspdCookie: "TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c",
877+
htmlPageBase64: "PCFET0NUWVBFIGh0bWw+...",
878+
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
879+
proxy: "login:password@1.2.3.4:8080",
880+
proxytype: "HTTP"
881+
})
882+
.then((res) => {
883+
console.log(res);
884+
})
885+
.catch((err) => {
886+
console.log(err);
887+
})
888+
```
889+
862890
## Other methods
863891

864892
### goodReport

‎examples/tspd.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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.tspd({
7+
pageurl: "https://example.com/login",
8+
tspdCookie: "TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c",
9+
htmlPageBase64: "PCFET0NUWVBFIGh0bWw+...",
10+
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
11+
proxy: "login:password@1.2.3.4:8080",
12+
proxytype: "HTTP"
13+
})
14+
.then((res) => {
15+
console.log(res);
16+
})
17+
.catch((err) => {
18+
console.log(err);
19+
})

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"Binance",
5858
"Audio Recognition",
5959
"Yidun NECaptcha",
60-
"Alibaba Captcha"
60+
"Alibaba Captcha",
61+
"TSPD"
6162
],
6263
"scripts": {
6364
"build": "tsc && node ./dist/index.js",

‎src/structs/2captcha.ts‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,15 @@ export interface paramsAlibaba {
353353
proxytype?: string,
354354
}
355355

356+
export interface paramsTspd {
357+
pageurl: string,
358+
tspdCookie: string,
359+
htmlPageBase64: string,
360+
proxy: string,
361+
proxytype: string,
362+
userAgent?: string,
363+
}
364+
356365
/**
357366
* An object containing properties of the captcha solution.
358367
* @typedef {Object} CaptchaAnswer
@@ -2502,6 +2511,74 @@ public async alibaba(params: paramsAlibaba): Promise<CaptchaAnswer> {
25022511
}
25032512
}
25042513

2514+
/**
2515+
* ### Solves TSPD Captcha
2516+
*
2517+
* Cookie-based method for automatic solving of TSPD captcha.
2518+
* [Read more about TSPD captcha](https://2captcha.com/2captcha-api#tspd-captcha).
2519+
*
2520+
* **Important:** `tspdCookie` and `htmlPageBase64` are dynamic — extract them immediately before creating the task,
2521+
* otherwise the solve may fail. A proxy with a static session and the same IP must be used at all stages.
2522+
*
2523+
* @param {{ pageurl, tspdCookie, htmlPageBase64, proxy, proxytype, userAgent }} params Parameters TSPD Captcha as an object.
2524+
* @param {string} params.pageurl Full URL of the page where you see the captcha.
2525+
* @param {string} params.tspdCookie Cookies received on the TSPD challenge page. Values starting with `TS...` or `Tspd_...`.
2526+
* @param {string} params.htmlPageBase64 Full HTML of the challenge page encoded in base64.
2527+
* @param {string} params.proxy Proxy in format: `login:password@123.123.123.123:3128`. You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
2528+
* @param {string} params.proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
2529+
* @param {string} params.userAgent Optional. Browser User-Agent. We recommend sending a valid Windows browser string.
2530+
*
2531+
* @returns {Promise<CaptchaAnswer>} The result from the solve.
2532+
* @throws APIError
2533+
*
2534+
* @example
2535+
* solver.tspd({
2536+
* pageurl: "https://example.com/login",
2537+
* tspdCookie: "TS386a400d029=082670...010245; TS386a400d078=082670...dbb3b0c",
2538+
* htmlPageBase64: "PCFET0NUWVBFIGh0bWw+...",
2539+
* userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
2540+
* proxy: "login:password@1.2.3.4:8080",
2541+
* proxytype: "HTTP"
2542+
* })
2543+
* .then((res) => {
2544+
* console.log(res);
2545+
* })
2546+
* .catch((err) => {
2547+
* console.log(err);
2548+
* })
2549+
*/
2550+
public async tspd(params: paramsTspd): Promise<CaptchaAnswer> {
2551+
params = renameParams(params)
2552+
2553+
checkCaptchaParams(params, "tspd")
2554+
2555+
const payload = {
2556+
...this.defaultPayload,
2557+
...params,
2558+
method: "tspd",
2559+
};
2560+
2561+
const response = await fetch(this.in, {
2562+
body: JSON.stringify(payload),
2563+
method: "post",
2564+
headers: { "Content-Type": "application/json" }
2565+
})
2566+
const result = await response.text()
2567+
2568+
let data;
2569+
try {
2570+
data = JSON.parse(result)
2571+
} catch {
2572+
throw new APIError(result)
2573+
}
2574+
2575+
if (data.status == 1) {
2576+
return this.pollResponse(data.request)
2577+
} else {
2578+
throw new APIError(data.request)
2579+
}
2580+
}
2581+
25052582
/**
25062583
* Reports a captcha as correctly solved.
25072584
*

‎src/utils/checkCaptchaParams.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Captcha methods for which parameter checking is available
22
const supportedMethods = ["userrecaptcha", "hcaptcha", "geetest", "geetest_v4","yandex","funcaptcha","lemin","amazon_waf",
33
"turnstile", "base64", "capy","datadome", "cybersiara", "mt_captcha", "bounding_box", 'friendly_captcha', 'grid',
4-
'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent', 'atb_captcha', 'prosopo', 'captchafox', 'vkimage', 'vkcaptcha', 'temu', 'altcha', 'binance', 'audio', 'yidun', 'alibaba']
4+
'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent', 'atb_captcha', 'prosopo', 'captchafox', 'vkimage', 'vkcaptcha', 'temu', 'altcha', 'binance', 'audio', 'yidun', 'alibaba', 'tspd']
55

66
// Names of required fields that must be contained in the parameters captcha
77
const recaptchaRequiredFields = ['pageurl','googlekey']
@@ -39,6 +39,7 @@ const binanceRequiredFields = ['pageurl', 'sitekey', 'validate_id']
3939
const audioRequiredFields = ['body', 'lang']
4040
const yidunRequiredFields = ['pageurl', 'sitekey']
4141
const alibabaRequiredFields = ['pageurl', 'scene_id', 'prefix']
42+
const tspdRequiredFields = ['pageurl', 'tspd_cookie', 'html_page_base64', 'proxy', 'proxytype']
4243

4344
/**
4445
* Getting required arguments for a captcha.
@@ -152,6 +153,9 @@ const getRequiredFildsArr = (method: string):Array<string> => {
152153
case "alibaba":
153154
requiredFieldsArr = alibabaRequiredFields
154155
break;
156+
case "tspd":
157+
requiredFieldsArr = tspdRequiredFields
158+
break;
155159
}
156160
return requiredFieldsArr
157161
}

‎src/utils/renameParams.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ export default function renameParams(params: any) {
5656
"sceneId": "scene_id",
5757
"verifyType": "verify_type",
5858
"userCertifyId": "user_certify_id",
59-
"apiGetLib": "api_get_lib"
59+
"apiGetLib": "api_get_lib",
60+
61+
// TSPD
62+
"tspdCookie": "tspd_cookie",
63+
"htmlPageBase64": "html_page_base64"
6064
}
6165

6266
for(let key in params) {

0 commit comments

Comments
 (0)