Skip to content

Commit 60ee9e7

Browse files
Add Tencent method
1 parent 7e48fcb commit 60ee9e7

5 files changed

Lines changed: 111 additions & 1 deletion

File tree

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Examples of API requests for different captcha types are available on the [JavaS
4141
- [Rotate](#rotate)
4242
- [KeyCaptcha](#keycaptcha)
4343
- [Cutcaptcha](#cutcaptcha)
44+
- [Tencent](#tencent)
4445
- [Other methods](#other-methods)
4546
- [goodReport](#goodreport)
4647
- [badReport](#badreport)
@@ -605,6 +606,25 @@ console.log(err);
605606
})
606607
```
607608

609+
### Tencent
610+
611+
<sup>[API method description.](https://2captcha.com/2captcha-api#tencent)</sup>
612+
613+
Use this method to solve Tencent captcha. Returns the response in JSON.
614+
615+
```js
616+
solver.tencent({
617+
pageurl: "https://mysite.com/page/with/tencent",
618+
appId: "189956587"
619+
})
620+
.then((res) => {
621+
console.log(res);
622+
})
623+
.catch((err) => {
624+
console.log(err);
625+
})
626+
```
627+
608628
## Other methods
609629

610630
### goodReport

examples/tencent.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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.tencent({
7+
pageurl: "https://mysite.com/page/with/tencent",
8+
appId: "189956587"
9+
})
10+
.then((res) => {
11+
console.log(res);
12+
})
13+
.catch((err) => {
14+
console.log(err);
15+
})

src/structs/2captcha.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@ export interface paramsKeyCaptcha {
274274
proxytype?: string
275275
}
276276

277+
export interface paramsTencent {
278+
pageurl: string,
279+
appId: string,
280+
pingback?: string,
281+
proxy?: string,
282+
proxytype?: string
283+
}
284+
277285
/**
278286
* An object containing properties of the captcha solution.
279287
* @typedef {Object} CaptchaAnswer
@@ -1712,6 +1720,66 @@ public async keyCaptcha(params: paramsKeyCaptcha): Promise<CaptchaAnswer> {
17121720
}
17131721
}
17141722

1723+
/**
1724+
* ### Solves a Tencent.
1725+
*
1726+
* Use this method to solve Tencent captcha. Returns a token.
1727+
* [Read more about Tencent](https://2captcha.com/2captcha-api#tencent).
1728+
*
1729+
* @param {{ pageurl, appId, pingback, proxy, proxytype }} params Parameters for solving Tencent as an object.
1730+
* @param {string} params.pageurl The URL where the captcha is located.
1731+
* @param {string} params.appId The value of `appId` parameter in the website source code.
1732+
* @param {string} [params.pingback] Optional param. URL for pingback (callback) response when captcha is solved.
1733+
* @param {string} [params.proxy] Optional param. Proxy to use while solving the captcha. Format: `login:password@123.123.123.123:3128`.
1734+
* @param {string} [params.proxytype] Optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1735+
*
1736+
* @returns {Promise<CaptchaAnswer>} The result from the solve.
1737+
* @throws APIError
1738+
*
1739+
* @example
1740+
* solver.tencent({
1741+
* pageurl: "https://mysite.com/page/with/tencent",
1742+
* appId: "189956587"
1743+
* })
1744+
* .then((res) => {
1745+
* console.log(res);
1746+
* })
1747+
* .catch((err) => {
1748+
* console.log(err);
1749+
* })
1750+
*/
1751+
public async tencent(params: paramsTencent): Promise<CaptchaAnswer> {
1752+
params = await renameParams(params)
1753+
checkCaptchaParams(params, "tencent")
1754+
1755+
const payload = {
1756+
...params,
1757+
method: "tencent",
1758+
...this.defaultPayload,
1759+
}
1760+
1761+
const URL = this.in
1762+
const response = await fetch(URL, {
1763+
body: JSON.stringify(payload),
1764+
method: "post",
1765+
headers: {'Content-Type': 'application/json'}
1766+
})
1767+
const result = await response.text()
1768+
1769+
let data;
1770+
try {
1771+
data = JSON.parse(result)
1772+
} catch {
1773+
throw new APIError(result)
1774+
}
1775+
1776+
if (data.status == 1) {
1777+
return this.pollResponse(data.request)
1778+
} else {
1779+
throw new APIError(data.request)
1780+
}
1781+
}
1782+
17151783
/**
17161784
* Reports a captcha as correctly solved.
17171785
*

src/utils/checkCaptchaParams.ts

Lines changed: 5 additions & 1 deletion
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']
3+
"turnstile", "base64", "capy","datadome", "cybersiara", "mt_captcha", "bounding_box", 'friendly_captcha', 'grid', 'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent']
44

55
// Names of required fields that must be contained in the parameters captcha
66
const recaptchaRequiredFields = ['pageurl','googlekey']
@@ -26,6 +26,7 @@ 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']
2930

3031
/**
3132
* Getting required arguments for a captcha.
@@ -103,6 +104,9 @@ const getRequiredFildsArr = (method: string):Array<string> => {
103104
case "cutcaptcha":
104105
requiredFieldsArr = cutcaptchaRequiredFields
105106
break;
107+
case "tencent":
108+
requiredFieldsArr = tencentRequiredFields
109+
break;
106110
}
107111
return requiredFieldsArr
108112
}

src/utils/renameParams.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export default function renameParams(params: any) {
3333
// Cutcaptcha
3434
"miseryKey":"misery_key",
3535
"apiKey":"api_key",
36+
37+
// Tencent
38+
"appId": "app_id",
3639
}
3740

3841
for(let key in params) {

0 commit comments

Comments
 (0)