Skip to content
Open
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
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Examples of API requests for different captcha types are available on the [JavaS
- [Altcha](#altcha)
- [Binance](#binance)
- [Audio Captcha](#audio-captcha)
- [Yidun NECaptcha](#yidun-necaptcha)
- [Other methods](#other-methods)
- [goodReport](#goodreport)
- [badReport](#badreport)
Expand Down Expand Up @@ -801,6 +802,33 @@ solver.audio({
})
```

### Yidun NECaptcha

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

This method can be used to solve Yidun NECaptcha. Returns a token.

```js
solver.yidun({
pageurl: "https://mysite.com/page/with/yidun",
sitekey: "your_site_key",
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
yidunGetLib: "https://cstaticdun.126.net/load.min.js",
yidunApiServerSubdomain: "cstaticdun.126.net",
challenge: "12345678abc90123d4567ef8a9012345",
hcg: "your_hcg_value",
hct: 1234567890,
proxy: "login:password@1.2.3.4:8888",
proxytype: "HTTP"
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
```

## Other methods

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

solver.yidun({
pageurl: "https://mysite.com/page/with/yidun",
sitekey: "your_site_key",
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
yidunGetLib: "https://cstaticdun.126.net/load.min.js",
yidunApiServerSubdomain: "cstaticdun.126.net",
challenge: "12345678abc90123d4567ef8a9012345",
hcg: "your_hcg_value",
hct: 1234567890,
proxy: "login:password@1.2.3.4:8888",
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 @@ -55,7 +55,8 @@
"atbCAPTCHA",
"Altcha",
"Binance",
"Audio Recognition"
"Audio Recognition",
"Yidun NECaptcha"
],
"scripts": {
"build": "tsc && node ./dist/index.js",
Expand Down
82 changes: 80 additions & 2 deletions src/structs/2captcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,19 @@ export interface paramsAudioCaptcha {
pingback?: string,
}

export interface paramsYidun {
pageurl: string,
sitekey: string,
userAgent?: string,
yidunGetLib?: string,
yidunApiServerSubdomain?: string,
challenge?: string,
hcg?: string,
hct?: number,
proxy?: string,
proxytype?: string,
}

/**
* An object containing properties of the captcha solution.
* @typedef {Object} CaptchaAnswer
Expand Down Expand Up @@ -2338,14 +2351,79 @@ public async audio(params: paramsAudioCaptcha): Promise<CaptchaAnswer> {
}
}

/**
* ### Solves Yidun NECaptcha
*
* This method can be used to solve Yidun NECaptcha. Returns a token.
* [Read more about Yidun NECaptcha Method](https://2captcha.com/2captcha-api#yidun).
*
* @param {{ pageurl, sitekey, userAgent, yidunGetLib, yidunApiServerSubdomain, challenge, hcg, hct, proxy, proxytype }} params Parameters Yidun NECaptcha as an object.
* @param {string} params.pageurl Full URL of the page where you see the captcha.
* @param {string} params.sitekey The value of `id` or `sitekey` parameter found on the page.
* @param {string} params.userAgent Optional. Browser User-Agent string.
* @param {string} params.yidunGetLib Optional. URL of the JavaScript file used to load the captcha.
* @param {string} params.yidunApiServerSubdomain Optional. Custom API server subdomain.
* @param {string} params.challenge Optional. Dynamic challenge value obtained from network requests.
* @param {string} params.hcg Optional. Captcha hash value.
* @param {number} params.hct Optional. Numeric timestamp identifier.
* @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.yidun({
* pageurl: "https://mysite.com/page/with/yidun",
* sitekey: "your_site_key"
* })
* .then((res) => {
* console.log(res);
* })
* .catch((err) => {
* console.log(err);
* })
*/
public async yidun(params: paramsYidun): Promise<CaptchaAnswer> {
params = renameParams(params)

checkCaptchaParams(params, "yidun")

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

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.
*
*
* @param {string} id The ID of the captcha
* @throws APIError
* @example
* solver.goodReport("7031854546")
*
*
*/
public async goodReport(id: string): Promise<void> {
const payload = {
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']
'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent', 'atb_captcha', 'prosopo', 'captchafox', 'vkimage', 'vkcaptcha', 'temu', 'altcha', 'binance', 'audio', 'yidun']

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

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

//Binance
"validateId": "validate_id",
"userAgent": "useragent"
"userAgent": "useragent",

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

for(let key in params) {
Expand Down