Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Examples of API requests for different captcha types are available on the [JavaS
- [Binance](#binance)
- [Audio Captcha](#audio-captcha)
- [Yidun NECaptcha](#yidun-necaptcha)
- [Alibaba Captcha](#alibaba-captcha)
- [Other methods](#other-methods)
- [goodReport](#goodreport)
- [badReport](#badreport)
Expand Down Expand Up @@ -829,6 +830,35 @@ console.log(err);
})
```

### Alibaba Captcha

<sup>[API method description.](https://2captcha.com/2captcha-api#alibaba)</sup>

This method can be used to solve Alibaba captcha (Aliyun). Returns a token.

Required parameters: `pageurl`, `sceneId`, `prefix`.

```js
solver.alibaba({
pageurl: "https://www.example.com",
sceneId: "abc123xyz4",
prefix: "dlw3kug",
user_id: "Abc123Def456Ghi789Jkl012Mno345Pqr678Stu901=",
user_user_id: "Xyz987Abc654Def321Ghi098Jkl765Mno432Pqr109=",
verifyType: "1.0",
region: "sgp",
userCertifyId: "abc123def456ghi789jkl012mno345pq",
apiGetLib: "https://o.example.com/captcha-frontend/aliyunCaptcha/AliyunCaptcha.js?t=2041",
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36"
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
```

## Other methods

### goodReport
Expand Down
25 changes: 25 additions & 0 deletions examples/alibabaCaptcha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const TwoCaptcha = require("../dist/index.js");
require('dotenv').config();
const APIKEY = process.env.APIKEY
const solver = new TwoCaptcha.Solver(APIKEY);

solver.alibaba({
pageurl: "https://www.example.com",
sceneId: "abc123xyz4",
prefix: "dlw3kug",
user_id: "Abc123Def456Ghi789Jkl012Mno345Pqr678Stu901=",
user_user_id: "Xyz987Abc654Def321Ghi098Jkl765Mno432Pqr109=",
verifyType: "1.0",
region: "sgp",
userCertifyId: "abc123def456ghi789jkl012mno345pq",
apiGetLib: "https://o.example.com/captcha-frontend/aliyunCaptcha/AliyunCaptcha.js?t=2041",
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36",
proxy: "login:password@1.2.3.4:8080",
proxytype: "HTTP"
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"Altcha",
"Binance",
"Audio Recognition",
"Yidun NECaptcha"
"Yidun NECaptcha",
"Alibaba Captcha"
],
"scripts": {
"build": "tsc && node ./dist/index.js",
Expand Down
86 changes: 86 additions & 0 deletions src/structs/2captcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,21 @@ export interface paramsYidun {
proxytype?: string,
}

export interface paramsAlibaba {
pageurl: string,
sceneId: string,
prefix: string,
user_id?: string,
user_user_id?: string,
verifyType?: string,
region?: string,
userCertifyId?: string,
apiGetLib?: string,
userAgent?: string,
proxy?: string,
proxytype?: string,
}

/**
* An object containing properties of the captcha solution.
* @typedef {Object} CaptchaAnswer
Expand Down Expand Up @@ -2416,6 +2431,77 @@ public async yidun(params: paramsYidun): Promise<CaptchaAnswer> {
}
}

/**
* ### Solves Alibaba Captcha
*
* This method can be used to solve Alibaba captcha (Aliyun). Returns a token.
* [Read more about Alibaba Captcha Method](https://2captcha.com/2captcha-api#alibaba).
*
* @param {{ pageurl, sceneId, prefix, user_id, user_user_id, verifyType, region, userCertifyId, apiGetLib, userAgent, proxy, proxytype }} params Parameters Alibaba Captcha as an object.
* @param {string} params.pageurl Full URL of the page where you see the captcha.
* @param {string} params.sceneId Value of `sceneId` parameter found in the captcha request on the page.
* @param {string} params.prefix Prefix from the subdomain of the captcha load request URL. For example: `dlw3kug` from `https://dlw3kug.captcha-open.example.aliyuncs.com/`.
* @param {string} params.user_id Optional. User or session identifier on the target site.
* @param {string} params.user_user_id Optional. Additional user identifier.
* @param {string} params.verifyType Optional. Version or type of the verification mechanism.
* @param {string} params.region Optional. Captcha processing region, e.g. `sgp`.
* @param {string} params.userCertifyId Optional. Verification ID of the current captcha session (`traceid` from the captcha request).
* @param {string} params.apiGetLib Optional. URL of the Alibaba Captcha JavaScript library (`AliyunCaptcha.js`).
* @param {string} params.userAgent Optional. Browser User-Agent string.
* @param {string} params.proxy Optional. Format: `login:password@123.123.123.123:3128`. You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
* @param {string} params.proxytype Optional. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
*
* @returns {Promise<CaptchaAnswer>} The result from the solve.
* @throws APIError
*
* @example
* solver.alibaba({
* pageurl: "https://www.example.com",
* sceneId: "abc123xyz4",
* prefix: "dlw3kug",
* region: "sgp",
* apiGetLib: "https://o.example.com/captcha-frontend/aliyunCaptcha/AliyunCaptcha.js?t=2041",
* userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36"
* })
* .then((res) => {
* console.log(res);
* })
* .catch((err) => {
* console.log(err);
* })
*/
public async alibaba(params: paramsAlibaba): Promise<CaptchaAnswer> {
params = renameParams(params)

checkCaptchaParams(params, "alibaba")

const payload = {
...this.defaultPayload,
...params,
method: "alibaba",
};

const response = await fetch(this.in, {
body: JSON.stringify(payload),
method: "post",
headers: { "Content-Type": "application/json" }
})
const result = await response.text()

let data;
try {
data = JSON.parse(result)
} catch {
throw new APIError(result)
}

if (data.status == 1) {
return this.pollResponse(data.request)
} else {
throw new APIError(data.request)
}
}

/**
* Reports a captcha as correctly solved.
*
Expand Down
6 changes: 5 additions & 1 deletion src/utils/checkCaptchaParams.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Captcha methods for which parameter checking is available
const supportedMethods = ["userrecaptcha", "hcaptcha", "geetest", "geetest_v4","yandex","funcaptcha","lemin","amazon_waf",
"turnstile", "base64", "capy","datadome", "cybersiara", "mt_captcha", "bounding_box", 'friendly_captcha', 'grid',
'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent', 'atb_captcha', 'prosopo', 'captchafox', 'vkimage', 'vkcaptcha', 'temu', 'altcha', 'binance', 'audio', 'yidun']
'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent', 'atb_captcha', 'prosopo', 'captchafox', 'vkimage', 'vkcaptcha', 'temu', 'altcha', 'binance', 'audio', 'yidun', 'alibaba']

// Names of required fields that must be contained in the parameters captcha
const recaptchaRequiredFields = ['pageurl','googlekey']
Expand Down Expand Up @@ -38,6 +38,7 @@ const altchaRequiredFields = ['pageurl']
const binanceRequiredFields = ['pageurl', 'sitekey', 'validate_id']
const audioRequiredFields = ['body', 'lang']
const yidunRequiredFields = ['pageurl', 'sitekey']
const alibabaRequiredFields = ['pageurl', 'scene_id', 'prefix']

/**
* Getting required arguments for a captcha.
Expand Down Expand Up @@ -148,6 +149,9 @@ const getRequiredFildsArr = (method: string):Array<string> => {
case "yidun":
requiredFieldsArr = yidunRequiredFields
break;
case "alibaba":
requiredFieldsArr = alibabaRequiredFields
break;
}
return requiredFieldsArr
}
Expand Down
8 changes: 7 additions & 1 deletion src/utils/renameParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ export default function renameParams(params: any) {

// Yidun
"yidunGetLib": "yidun_get_lib",
"yidunApiServerSubdomain": "yidun_api_server_subdomain"
"yidunApiServerSubdomain": "yidun_api_server_subdomain",

// Alibaba
"sceneId": "scene_id",
"verifyType": "verify_type",
"userCertifyId": "user_certify_id",
"apiGetLib": "api_get_lib"
}

for(let key in params) {
Expand Down