Skip to content

Commit 875e22a

Browse files
authored
added yidun captcha (#32)
1 parent 8cfdf9c commit 875e22a

6 files changed

Lines changed: 143 additions & 5 deletions

File tree

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Examples of API requests for different captcha types are available on the [JavaS
5050
- [Altcha](#altcha)
5151
- [Binance](#binance)
5252
- [Audio Captcha](#audio-captcha)
53+
- [Yidun NECaptcha](#yidun-necaptcha)
5354
- [Other methods](#other-methods)
5455
- [goodReport](#goodreport)
5556
- [badReport](#badreport)
@@ -801,6 +802,33 @@ solver.audio({
801802
})
802803
```
803804

805+
### Yidun NECaptcha
806+
807+
<sup>[API method description.](https://2captcha.com/2captcha-api#yidun)</sup>
808+
809+
This method can be used to solve Yidun NECaptcha. Returns a token.
810+
811+
```js
812+
solver.yidun({
813+
pageurl: "https://mysite.com/page/with/yidun",
814+
sitekey: "your_site_key",
815+
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
816+
yidunGetLib: "https://cstaticdun.126.net/load.min.js",
817+
yidunApiServerSubdomain: "cstaticdun.126.net",
818+
challenge: "12345678abc90123d4567ef8a9012345",
819+
hcg: "your_hcg_value",
820+
hct: 1234567890,
821+
proxy: "login:password@1.2.3.4:8888",
822+
proxytype: "HTTP"
823+
})
824+
.then((res) => {
825+
console.log(res);
826+
})
827+
.catch((err) => {
828+
console.log(err);
829+
})
830+
```
831+
804832
## Other methods
805833

806834
### goodReport

examples/yidun.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.yidun({
7+
pageurl: "https://mysite.com/page/with/yidun",
8+
sitekey: "your_site_key",
9+
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
10+
yidunGetLib: "https://cstaticdun.126.net/load.min.js",
11+
yidunApiServerSubdomain: "cstaticdun.126.net",
12+
challenge: "12345678abc90123d4567ef8a9012345",
13+
hcg: "your_hcg_value",
14+
hct: 1234567890,
15+
proxy: "login:password@1.2.3.4:8888",
16+
proxytype: "HTTP"
17+
})
18+
.then((res) => {
19+
console.log(res);
20+
})
21+
.catch((err) => {
22+
console.log(err);
23+
})

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
"atbCAPTCHA",
5656
"Altcha",
5757
"Binance",
58-
"Audio Recognition"
58+
"Audio Recognition",
59+
"Yidun NECaptcha"
5960
],
6061
"scripts": {
6162
"build": "tsc && node ./dist/index.js",

src/structs/2captcha.ts

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,19 @@ export interface paramsAudioCaptcha {
325325
pingback?: string,
326326
}
327327

328+
export interface paramsYidun {
329+
pageurl: string,
330+
sitekey: string,
331+
userAgent?: string,
332+
yidunGetLib?: string,
333+
yidunApiServerSubdomain?: string,
334+
challenge?: string,
335+
hcg?: string,
336+
hct?: number,
337+
proxy?: string,
338+
proxytype?: string,
339+
}
340+
328341
/**
329342
* An object containing properties of the captcha solution.
330343
* @typedef {Object} CaptchaAnswer
@@ -2338,14 +2351,79 @@ public async audio(params: paramsAudioCaptcha): Promise<CaptchaAnswer> {
23382351
}
23392352
}
23402353

2354+
/**
2355+
* ### Solves Yidun NECaptcha
2356+
*
2357+
* This method can be used to solve Yidun NECaptcha. Returns a token.
2358+
* [Read more about Yidun NECaptcha Method](https://2captcha.com/2captcha-api#yidun).
2359+
*
2360+
* @param {{ pageurl, sitekey, userAgent, yidunGetLib, yidunApiServerSubdomain, challenge, hcg, hct, proxy, proxytype }} params Parameters Yidun NECaptcha as an object.
2361+
* @param {string} params.pageurl Full URL of the page where you see the captcha.
2362+
* @param {string} params.sitekey The value of `id` or `sitekey` parameter found on the page.
2363+
* @param {string} params.userAgent Optional. Browser User-Agent string.
2364+
* @param {string} params.yidunGetLib Optional. URL of the JavaScript file used to load the captcha.
2365+
* @param {string} params.yidunApiServerSubdomain Optional. Custom API server subdomain.
2366+
* @param {string} params.challenge Optional. Dynamic challenge value obtained from network requests.
2367+
* @param {string} params.hcg Optional. Captcha hash value.
2368+
* @param {number} params.hct Optional. Numeric timestamp identifier.
2369+
* @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).
2370+
* @param {string} params.proxytype Optional. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
2371+
*
2372+
* @returns {Promise<CaptchaAnswer>} The result from the solve.
2373+
* @throws APIError
2374+
*
2375+
* @example
2376+
* solver.yidun({
2377+
* pageurl: "https://mysite.com/page/with/yidun",
2378+
* sitekey: "your_site_key"
2379+
* })
2380+
* .then((res) => {
2381+
* console.log(res);
2382+
* })
2383+
* .catch((err) => {
2384+
* console.log(err);
2385+
* })
2386+
*/
2387+
public async yidun(params: paramsYidun): Promise<CaptchaAnswer> {
2388+
params = renameParams(params)
2389+
2390+
checkCaptchaParams(params, "yidun")
2391+
2392+
const payload = {
2393+
...this.defaultPayload,
2394+
...params,
2395+
method: "yidun",
2396+
};
2397+
2398+
const response = await fetch(this.in, {
2399+
body: JSON.stringify(payload),
2400+
method: "post",
2401+
headers: { "Content-Type": "application/json" }
2402+
})
2403+
const result = await response.text()
2404+
2405+
let data;
2406+
try {
2407+
data = JSON.parse(result)
2408+
} catch {
2409+
throw new APIError(result)
2410+
}
2411+
2412+
if (data.status == 1) {
2413+
return this.pollResponse(data.request)
2414+
} else {
2415+
throw new APIError(data.request)
2416+
}
2417+
}
2418+
23412419
/**
23422420
* Reports a captcha as correctly solved.
2343-
*
2421+
*
23442422
* @param {string} id The ID of the captcha
23452423
* @throws APIError
23462424
* @example
23472425
* solver.goodReport("7031854546")
2348-
*
2426+
*
23492427
*/
23502428
public async goodReport(id: string): Promise<void> {
23512429
const payload = {

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']
4+
'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent', 'atb_captcha', 'prosopo', 'captchafox', 'vkimage', 'vkcaptcha', 'temu', 'altcha', 'binance', 'audio', 'yidun']
55

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

4142
/**
4243
* Getting required arguments for a captcha.
@@ -144,6 +145,9 @@ const getRequiredFildsArr = (method: string):Array<string> => {
144145
case "audio":
145146
requiredFieldsArr = audioRequiredFields
146147
break;
148+
case "yidun":
149+
requiredFieldsArr = yidunRequiredFields
150+
break;
147151
}
148152
return requiredFieldsArr
149153
}

src/utils/renameParams.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ export default function renameParams(params: any) {
4646

4747
//Binance
4848
"validateId": "validate_id",
49-
"userAgent": "useragent"
49+
"userAgent": "useragent",
50+
51+
// Yidun
52+
"yidunGetLib": "yidun_get_lib",
53+
"yidunApiServerSubdomain": "yidun_api_server_subdomain"
5054
}
5155

5256
for(let key in params) {

0 commit comments

Comments
 (0)