Code Examples
Ready-to-use code snippets in multiple languages
JavaScript / Node.js
Complete Example
const axios = require('axios');
class MyDisctSolver {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseUrl = 'https://solver-api.mydisct.com';
}
async createTask(captchaData) {
try {
const response = await axios.post(`${this.baseUrl}/createTask`, {
auth: { token: this.apiKey },
context: { source: 'api', version: '1.0.0' },
captcha: captchaData
}, {
headers: {
'Content-Type': 'application/json',
'apikey': this.apiKey
}
});
return response.data;
} catch (error) {
throw new Error(`Create task failed: ${error.message}`);
}
}
async getTaskResult(taskId) {
const response = await axios.post(`${this.baseUrl}/fetchResult`, {
taskId: taskId
}, {
headers: {
'Content-Type': 'application/json',
'apikey': this.apiKey
}
});
return response.data;
}
async getBalance() {
const response = await axios.get(`${this.baseUrl}/balance`, {
headers: { 'apikey': this.apiKey }
});
return response.data.balance;
}
}
const solver = new MyDisctSolver('YOUR_API_KEY');
async function main() {
const createResult = await solver.createTask({
type: 'RECAPTCHA_V2_TOKEN',
metadata: {
siteKey: 'your_sitekey',
siteUrl: 'https://example.com'
}
});
const taskId = createResult.task.id;
console.log('Task created:', taskId);
let result;
while (true) {
await new Promise(resolve => setTimeout(resolve, 3000));
result = await solver.getTaskResult(taskId);
if (result.task.status === 'completed') {
console.log('Token:', result.task.result.token);
break;
}
}
console.log('Balance:', await solver.getBalance());
}
main();
Python
Complete Example
import requests
import time
class MyDisctSolver:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = 'https://solver-api.mydisct.com'
self.headers = {
'apikey': api_key,
'Content-Type': 'application/json'
}
def create_task(self, captcha_data):
response = requests.post(
f'{self.base_url}/createTask',
json={
'auth': {'token': self.api_key},
'context': {'source': 'api', 'version': '1.0.0'},
'captcha': captcha_data
},
headers=self.headers
)
response.raise_for_status()
return response.json()
def get_task_result(self, task_id):
response = requests.post(
f'{self.base_url}/fetchResult',
json={'taskId': task_id},
headers=self.headers
)
return response.json()
def get_balance(self):
response = requests.get(
f'{self.base_url}/balance',
headers=self.headers
)
return response.json()['balance']
# Usage
solver = MyDisctSolver('YOUR_API_KEY')
# Create task
create_result = solver.create_task({
'type': 'RECAPTCHA_V2_TOKEN',
'metadata': {
'siteKey': 'your_sitekey',
'siteUrl': 'https://example.com'
}
})
task_id = create_result['task']['id']
print('Task created:', task_id)
# Poll for result
while True:
time.sleep(3)
result = solver.get_task_result(task_id)
if result['task']['status'] == 'completed':
print('Token:', result['task']['result']['token'])
break
print('Balance:', solver.get_balance())
PHP
Complete Example
apiKey = $apiKey;
}
public function createTask($captchaData) {
$ch = curl_init($this->baseUrl . '/createTask');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'auth' => ['token' => $this->apiKey],
'context' => ['source' => 'api', 'version' => '1.0.0'],
'captcha' => $captchaData
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'apikey: ' . $this->apiKey,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
public function getTaskResult($taskId) {
$ch = curl_init($this->baseUrl . '/fetchResult');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'taskId' => $taskId
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'apikey: ' . $this->apiKey,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
public function getBalance() {
$ch = curl_init($this->baseUrl . '/balance');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'apikey: ' . $this->apiKey
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true)['balance'];
}
}
$solver = new MyDisctSolver('YOUR_API_KEY');
$createResult = $solver->createTask([
'type' => 'RECAPTCHA_V2_TOKEN',
'metadata' => [
'siteKey' => 'your_sitekey',
'siteUrl' => 'https://example.com'
]
]);
$taskId = $createResult['task']['id'];
echo 'Task created: ' . $taskId . PHP_EOL;
while (true) {
sleep(3);
$result = $solver->getTaskResult($taskId);
if ($result['task']['status'] === 'completed') {
echo 'Token: ' . $result['task']['result']['token'] . PHP_EOL;
break;
}
}
echo 'Balance: ' . $solver->getBalance() . PHP_EOL;
?>