UNPKG

@cybersify/solvecaptcha

Version:

This is a boilerplate of an Apify actor.

269 lines (219 loc) 8.6 kB
const request = require('request-promise') const api = { in: 'https://solvecaptcha.net/api/createTask', res: 'https://solvecaptcha.net/api/getTaskResult', pollingInterval: 5000 }; const getAnswer = (id,key) => { return new Promise((resolve, reject) => { const polling = setInterval(() => { var requestUrl = api.res ; var requestData = { "api_key": key, "task_id" : id }; request.post(requestUrl, { headers: { 'Authorization':'Bearer ' + key }, json: true, body: (typeof requestData === 'object') ? requestData : null }) .then((res) => { if (res.error_id == 0 && res.status === 'ready') { resolve(res.solution); clearInterval(polling); } else if(res.error_id !== 0){ reject(res.solution); clearInterval(polling); } // console.log(res); }) .catch((error) => { console.log(error); clearInterval(polling) reject(error) }); }, api.pollingInterval); }) } /** * Google Captcha */ const submitCaptchaV2 = (params) => { return new Promise((resolve, reject) => { var requestUrl = api.in ; var requestData = { "task":{ "method": params.type != null ? params.type : params.method != null ? params.method : '', "page_url":params.websiteURL != null ? params.websiteURL : params.page_url != null ? params.page_url : '', "site_key":params.websiteKey != null ? params.websiteKey : params.site_key != null ? params.site_key:'', "affiliate_id":params.affiliate_id != null ? params.affiliate_id : '', /** * data_s, min_score, page_action, * proxy_type, proxy_address, proxy_port, proxy_login, proxy_password,user_agent, cookies */ "data_s":params.data_s != null ? params.data_s : '', "min_score":params.min_score != null ? params.min_score : '', "page_action":params.page_action != null ? params.page_action : '', "proxy_type":params.proxy_type != null ? params.proxy_type : '', "proxy_address":params.proxy_address != null ? params.proxy_address : '', "proxy_port":params.proxy_port != null ? params.proxy_port : '', "proxy_login":params.proxy_login != null ? params.proxy_login : '', "proxy_password":params.proxy_password != null ? params.proxy_password : '', "user_agent":params.user_agent != null ? params.user_agent : '', "cookies": params.cookies != null ? params.cookies : '' } }; request.post(requestUrl, { headers: { 'Authorization':'Bearer ' + params.key }, json: true, body: (typeof requestData === 'object') ? requestData : null }) .then((res) => { if (res.error_id === 0) { resolve(res.task_id) } else { reject(res.task_id) } console.log(res); }) .catch((error) => { reject({ error }) console.log(error); }) }) } const solveCaptchaV2 = async (params) => { try { let id = await submitCaptchaV2(params, api); let answer = await getAnswer(id, params.key) return answer } catch (e) { return e } } /** * Geetest Captch */ const submitGeeTest = (params) => { return new Promise((resolve, reject) => { var requestUrl = api.in ; // method<-> type // page_url <-> websiteURL var requestData = { "task":{ "method": params.type != null ? params.type : params.method != null ? params.method : '', "page_url":params.websiteURL != null ? params.websiteURL : params.page_url != null ? params.page_url : '', "gt":params.gt, "challenge":params.challenge, "geetestApiServerSubdomain":params.geetestApiServerSubdomain, "geetestGetLib": params.geetestGetLib != null ? params.geetestGetLib : '', "affiliate_id":params.affiliate_id != null ? params.affiliate_id : '', "proxy_type":params.proxy_type != null ? params.proxy_type : '', "proxy_address":params.proxy_address != null ? params.proxy_address : '', "proxy_port":params.proxy_port != null ? params.proxy_port : '', "proxy_login":params.proxy_login != null ? params.proxy_login : '', "proxy_password":params.proxy_password != null ? params.proxy_password : '', "user_agent":params.user_agent != null ? params.user_agent : '', "cookies": params.cookies != null ? params.cookies : '' } }; request.post(requestUrl, { headers: { 'Authorization':'Bearer ' + params.key }, json: true, body: (typeof requestData === 'object') ? requestData : null }) .then((res) => { if (res.error_id === 0) { resolve(res.task_id) } else { reject(res.task_id) } console.log(res); }) .catch((error) => { reject({ error }) console.log(error); }) }) } const solveGeeTest = async (params) => { try { let id = await submitGeeTest(params, api); console.log("* Id task:" + id); let answer = await getAnswer(id, params.key); return answer } catch (e) { return e } } /** * hCaptcha */ const submitHCaptcha = (params) => { return new Promise((resolve, reject) => { var requestUrl = api.in ; // method<-> type // page_url <-> websiteURL var requestData = { "task":{ "method": params.type != null ? params.type : params.method != null ? params.method : '', "page_url":params.websiteURL != null ? params.websiteURL : params.page_url != null ? params.page_url : '', "site_key":params.websiteKey != null ? params.websiteKey : params.site_key != null ? params.site_key:'', "affiliate_id":params.affiliate_id != null ? params.affiliate_id : '', "isInvisible":params.isInvisible != null ? params.isInvisible: '', /** * data, proxy_type, proxy_address, proxy_port, proxy_login, proxy_password,user_agent, cookies */ "data":params.data != null ? params.data : '', "proxy_type":params.proxy_type != null ? params.proxy_type : '', "proxy_address":params.proxy_address != null ? params.proxy_address : '', "proxy_port":params.proxy_port != null ? params.proxy_port : '', "proxy_login":params.proxy_login != null ? params.proxy_login : '', "proxy_password":params.proxy_password != null ? params.proxy_password : '', "user_agent":params.user_agent != null ? params.user_agent : '', "cookies": params.cookies != null ? params.cookies : '' } }; request.post(requestUrl, { headers: { 'Authorization':'Bearer ' + params.key }, json: true, body: (typeof requestData === 'object') ? requestData : null }) .then((res) => { if (res.error_id === 0) { resolve(res.task_id) } else { reject(res.task_id) } console.log(res); }) .catch((error) => { reject({ error }) console.log(error); }) }) } const solveHCaptcha = async (params) => { try { let id = await submitHCaptcha(params, api); console.log("* Id task:" + id); let answer = await getAnswer(id, params.key); return answer } catch (e) { return e } } module.exports = { getAnswer, solveCaptchaV2, solveGeeTest, solveHCaptcha }