9kw-captcha-node 中文文档教程
1. 9kw
这是 9kw 验证码求解器服务的 api 包装器。 需要一个 Api 密钥,使用 9kw 网站生成。
1.1. Installation
节点:
npm install 9kw-captcha-node
该库支持环境变量来传递参数,例如 API 密钥:
ENV variable | Type | Description |
---|---|---|
CAPTCHAAPIKEY_9KW | String | API Key |
CAPTCHASOURCE9KW | String | 9kw Source (app indicator) |
CAPTCHAOLDSOURCE_9KW | String | 9kw Old Source (indicator for captcha type) |
CAPTCHAPRIO9KW | Number | 9kw default priority |
CAPTCHADEBUG9KW | Number | Don't spend credits and get fake solutions. For testing… |
或者,您可以在实例化 API 构造函数时将其作为参数传递
1.2. Promises - Async/Await
const Api9kw = require("9kw-captcha-node");
const api = new Api9kw(/* You can pass parameters here or just use the ENV vars */);
(async () => {
try {
// Get the balance of credits from 9kw
const balance = await api.asyncGetBalance();
console.log(`BALANCE: ${balance} credits`);
// Submit a local image file with the captcha
// const captchaId = await api.asyncSubmitFile(config.pathToFile);
// Submit using a Image Base 64 of the captha
// const captchaId = await api.asyncSubmitBase64(config.image_base64);
// Submit using a Image URL of the captha
// const captchaId = await api.asyncSubmit(config.image_url);
// Submit CaptchaV2 (using a siteKey + siteUrl)
// CaptchaV2 will need to be solved by someone in real time
// so using the priority becomes important if you want faster captchas
// 300 seconds (with 0 prio) is a reasonable number so you don't miss solved captchas
// If you want them faster, up the prio and you will pay one extra credit per captcha
const captchaId = await api.asyncSubmit(
SITEKEY,
SITEURL,
OVERWRITE_PRIO_IF_YOU_WANT
);
console.log(`CAPTCHA ID: ${captchaId}`);
// Get the solution of the captcha with a timeout of 40 seconds (optional)
// this means that the callback will be called when the captcha is solved
// For image Solving 9kw seems to store the solutions in their own DB
// and some are instantaneous others may take some more but usually under 30 sec
// For CaptchaV2 (sitekey + siteUrl) will need to be solved by someone in real time
// so using the priority becomes important if you want faster captchas
// 300 seconds (with 0 prio) is a reasonable number so you don't miss solved captchas
// If you want them faster, up the prio and you will pay one extra credit per captcha
// usually is solved under 30s (default timeout is 30 seconds)
const solution = await api.asyncGetSolutionLoop(captchaId, 300);
console.log("SOLUTION: ", solution);
// Give feedback
successSolve
? await api9kw.asyncIsCorrect(captchaId, true)
: await api9kw.asyncIsCorrect(captchaId);
} catch (err) {
console.error(err); // Timeout or NO_USER
}
})();
1.3. Callbacks
const Api9kw = require("9kw");
const api = new Api9kw(/* You can pass parameters here or just use the ENV vars */);
// Get your account balance (credits)
api.getBalance((err, balance) => {
console.log(balance);
});
// Submit a local image file with the captcha
// api.submitFile("./captcha.png", (err, newID) => {
// if (err) {
// console.log(err);
// return;
// }
// console.log("Captcha uploaded!: " + captchaId);
// // Next step is to get the solution of the uploaded captcha using the new captchaID
// });
// Submit using a Image Base 64 of the captha
// api.submitBase64(base64, (err, newID) => {
// if (err) {
// console.log(err);
// return;
// }
// console.log("Captcha uploaded!: " + captchaId);
// // Next step is to get the solution of the uploaded captcha using the new captchaID
// });
// Submit using a Image URL of the captha
api.submit(URL, (err, newID) => {
if (err) {
console.log(err);
return;
}
console.log("Captcha uploaded!: " + captchaId);
// Next step is to get the solution of the uploaded captcha using the new captchaID
});
// Submit CaptchaV2 (using a siteKey + siteUrl)
// CaptchaV2 will need to be solved by someone in real time
// so using the priority becomes important if you want faster captchas
// 300 seconds (with 0 prio) is a reasonable number so you don't miss solved captchas
// If you want them faster, up the prio and you will pay one extra credit per captcha
api.submit(
SITE_KEY,
(err, newID) => {
if (err) {
console.log(err);
return;
}
console.log("Captcha uploaded!: " + captchaId);
// Next step is to get the solution of the uploaded captcha using the new captchaID
},
SITE_URL,
OVERWRITE_PRIO_IF_YOU_WANT
);
// Get the solution of the captcha with a timeout of 40 seconds (optional)
// this means that the callback will be called when the captcha is solved
// usually is solved under 30s (default timeout is 30 seconds)
api.getSolutionLoop(captchaId, 40, (err, solution) => {
if (err) {
console.log(err);
return;
}
console.log("Solution: " + solution);
});
// Tell 9kw the solution was correct or not
api.isCorrect(captchaId, true);
// Get the 9kw server check info
api.serverCheck((err, serverInfo) => {
console.log(serverInfo);
});
1.4. Development
1.4.1. Linting and Generating Docs
npm run flow
1.4.2. Tests
为了运行测试,创建一个 .env 文件作为 .env.default 并将您的帐户详细信息放入正确的 ENV 变量,然后运行:
npm run test
Tests are not working on Node > 10
1.5. Credits
这个项目最初是 iamfreee/9kw_node 的一个分支
1. 9kw
This is an api wrapper for the 9kw captcha solver service. An Api Key is needed, generate using the 9kw website.
1.1. Installation
node:
npm install 9kw-captcha-node
This library supports environment variables to pass parameters like API Key:
ENV variable | Type | Description |
---|---|---|
CAPTCHAAPIKEY_9KW | String | API Key |
CAPTCHASOURCE9KW | String | 9kw Source (app indicator) |
CAPTCHAOLDSOURCE_9KW | String | 9kw Old Source (indicator for captcha type) |
CAPTCHAPRIO9KW | Number | 9kw default priority |
CAPTCHADEBUG9KW | Number | Don't spend credits and get fake solutions. For testing… |
In alternative you can pass it as parameters when instantiating the API constructor
1.2. Promises - Async/Await
const Api9kw = require("9kw-captcha-node");
const api = new Api9kw(/* You can pass parameters here or just use the ENV vars */);
(async () => {
try {
// Get the balance of credits from 9kw
const balance = await api.asyncGetBalance();
console.log(`BALANCE: ${balance} credits`);
// Submit a local image file with the captcha
// const captchaId = await api.asyncSubmitFile(config.pathToFile);
// Submit using a Image Base 64 of the captha
// const captchaId = await api.asyncSubmitBase64(config.image_base64);
// Submit using a Image URL of the captha
// const captchaId = await api.asyncSubmit(config.image_url);
// Submit CaptchaV2 (using a siteKey + siteUrl)
// CaptchaV2 will need to be solved by someone in real time
// so using the priority becomes important if you want faster captchas
// 300 seconds (with 0 prio) is a reasonable number so you don't miss solved captchas
// If you want them faster, up the prio and you will pay one extra credit per captcha
const captchaId = await api.asyncSubmit(
SITEKEY,
SITEURL,
OVERWRITE_PRIO_IF_YOU_WANT
);
console.log(`CAPTCHA ID: ${captchaId}`);
// Get the solution of the captcha with a timeout of 40 seconds (optional)
// this means that the callback will be called when the captcha is solved
// For image Solving 9kw seems to store the solutions in their own DB
// and some are instantaneous others may take some more but usually under 30 sec
// For CaptchaV2 (sitekey + siteUrl) will need to be solved by someone in real time
// so using the priority becomes important if you want faster captchas
// 300 seconds (with 0 prio) is a reasonable number so you don't miss solved captchas
// If you want them faster, up the prio and you will pay one extra credit per captcha
// usually is solved under 30s (default timeout is 30 seconds)
const solution = await api.asyncGetSolutionLoop(captchaId, 300);
console.log("SOLUTION: ", solution);
// Give feedback
successSolve
? await api9kw.asyncIsCorrect(captchaId, true)
: await api9kw.asyncIsCorrect(captchaId);
} catch (err) {
console.error(err); // Timeout or NO_USER
}
})();
1.3. Callbacks
const Api9kw = require("9kw");
const api = new Api9kw(/* You can pass parameters here or just use the ENV vars */);
// Get your account balance (credits)
api.getBalance((err, balance) => {
console.log(balance);
});
// Submit a local image file with the captcha
// api.submitFile("./captcha.png", (err, newID) => {
// if (err) {
// console.log(err);
// return;
// }
// console.log("Captcha uploaded!: " + captchaId);
// // Next step is to get the solution of the uploaded captcha using the new captchaID
// });
// Submit using a Image Base 64 of the captha
// api.submitBase64(base64, (err, newID) => {
// if (err) {
// console.log(err);
// return;
// }
// console.log("Captcha uploaded!: " + captchaId);
// // Next step is to get the solution of the uploaded captcha using the new captchaID
// });
// Submit using a Image URL of the captha
api.submit(URL, (err, newID) => {
if (err) {
console.log(err);
return;
}
console.log("Captcha uploaded!: " + captchaId);
// Next step is to get the solution of the uploaded captcha using the new captchaID
});
// Submit CaptchaV2 (using a siteKey + siteUrl)
// CaptchaV2 will need to be solved by someone in real time
// so using the priority becomes important if you want faster captchas
// 300 seconds (with 0 prio) is a reasonable number so you don't miss solved captchas
// If you want them faster, up the prio and you will pay one extra credit per captcha
api.submit(
SITE_KEY,
(err, newID) => {
if (err) {
console.log(err);
return;
}
console.log("Captcha uploaded!: " + captchaId);
// Next step is to get the solution of the uploaded captcha using the new captchaID
},
SITE_URL,
OVERWRITE_PRIO_IF_YOU_WANT
);
// Get the solution of the captcha with a timeout of 40 seconds (optional)
// this means that the callback will be called when the captcha is solved
// usually is solved under 30s (default timeout is 30 seconds)
api.getSolutionLoop(captchaId, 40, (err, solution) => {
if (err) {
console.log(err);
return;
}
console.log("Solution: " + solution);
});
// Tell 9kw the solution was correct or not
api.isCorrect(captchaId, true);
// Get the 9kw server check info
api.serverCheck((err, serverInfo) => {
console.log(serverInfo);
});
1.4. Development
1.4.1. Linting and Generating Docs
npm run flow
1.4.2. Tests
In order to run the tests, create a .env file as .env.default and put your account details in the correct ENV variables, then run:
npm run test
Tests are not working on Node > 10
1.5. Credits
This project was initially a fork of iamfreee/9kw_node