Telegram uchun virtual raqamlar xizmati. Oson integratsiya va ishonchli xizmat.
DearSMS API Telegram uchun virtual telefon raqamlarini olish va SMS kodlarni qabul qilish imkonini beradi.
Barcha so'rovlar uchun api_key parametri talab qilinadi.
| Parametr | Tavsif | Majburiy |
|---|---|---|
api_key |
Sizning API kalitingiz | Ha |
action |
Bajarilishi kerak bo'lgan amal | Ha |
Hisobingizdagi balansni tekshirish uchun ushbu endpoint dan foydalaning.
<?php
class DearSMS {
private $api_key;
private $base_url = 'https://dearsms.space/sms/v1';
public function __construct($api_key) {
$this->api_key = $api_key;
}
public function getBalance() {
$url = $this->base_url . '?api_key=' . $this->api_key . '&action=getBalance';
$response = file_get_contents($url);
return json_decode($response, true);
}
}
// Foydalanish
$sms = new DearSMS('sizning_api_kalitingiz');
$balance = $sms->getBalance();
if ($balance['ok']) {
echo "Balans: " . $balance['balance']['value'] . " " . $balance['balance']['currency'];
} else {
echo "Xato: " . $balance['message'];
}
?>
const axios = require('axios');
class DearSMS {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseUrl = 'https://dearsms.space/sms/v1';
}
async getBalance() {
try {
const response = await axios.get(`${this.baseUrl}?api_key=${this.apiKey}&action=getBalance`);
return response.data;
} catch (error) {
throw new Error('API so\'rovida xato: ' + error.message);
}
}
}
// Foydalanish
const sms = new DearSMS('sizning_api_kalitingiz');
sms.getBalance()
.then(balance => {
if (balance.ok) {
console.log(`Balans: ${balance.balance.value} ${balance.balance.currency}`);
} else {
console.log(`Xato: ${balance.message}`);
}
})
.catch(error => {
console.error(error.message);
});
import requests
import json
class DearSMS:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = 'https://dearsms.space/sms/v1'
def get_balance(self):
url = f"{self.base_url}?api_key={self.api_key}&action=getBalance"
try:
response = requests.get(url)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
raise Exception(f"API so'rovida xato: {e}")
# Foydalanish
sms = DearSMS('sizning_api_kalitingiz')
try:
balance = sms.get_balance()
if balance['ok']:
print(f"Balans: {balance['balance']['value']} {balance['balance']['currency']}")
else:
print(f"Xato: {balance['message']}")
except Exception as e:
print(e)
Mavjud davlatlar va ularning narxlarini ko'rish uchun ushbu endpoint dan foydalaning.
public function getCountries() {
$url = $this->base_url . '?api_key=' . $this->api_key . '&action=getCountries';
$response = file_get_contents($url);
return json_decode($response, true);
}
// Foydalanish
$countries = $sms->getCountries();
foreach ($countries as $country) {
echo $country['name'] . " - " . $country['price'] . " UZS (" . $country['count'] . " ta mavjud)\n";
}
async getCountries() {
try {
const response = await axios.get(`${this.baseUrl}?api_key=${this.apiKey}&action=getCountries`);
return response.data;
} catch (error) {
throw new Error('API so\'rovida xato: ' + error.message);
}
}
// Foydalanish
sms.getCountries()
.then(countries => {
countries.forEach(country => {
console.log(`${country.name} - ${country.price} UZS (${country.count} ta mavjud)`);
});
})
.catch(error => {
console.error(error.message);
});
def get_countries(self):
url = f"{self.base_url}?api_key={self.api_key}&action=getCountries"
try:
response = requests.get(url)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
raise Exception(f"API so'rovida xato: {e}")
# Foydalanish
try:
countries = sms.get_countries()
for country in countries:
print(f"{country['name']} - {country['price']} UZS ({country['count']} ta mavjud)")
except Exception as e:
print(e)
Tanlangan davlatdan virtual telefon raqami olish uchun ushbu endpoint dan foydalaning.
| Parametr | Tavsif | Misol |
|---|---|---|
country |
Davlat kodi | ke, us, uz |
public function getNumber($country) {
$url = $this->base_url . '?api_key=' . $this->api_key . '&action=getNumber&country=' . $country;
$response = file_get_contents($url);
return json_decode($response, true);
}
// Foydalanish
$result = $sms->getNumber('ke');
if ($result['ok']) {
echo "Nomer: " . $result['data']['number'] . "\n";
echo "Buyurtma ID: " . $result['data']['order_id'] . "\n";
echo "Davlat: " . $result['country']['name'] . "\n";
} else {
echo "Xato: " . $result['message'];
}
async getNumber(country) {
try {
const response = await axios.get(`${this.baseUrl}?api_key=${this.apiKey}&action=getNumber&country=${country}`);
return response.data;
} catch (error) {
throw new Error('API so\'rovida xato: ' + error.message);
}
}
// Foydalanish
sms.getNumber('ke')
.then(result => {
if (result.ok) {
console.log(`Nomer: ${result.data.number}`);
console.log(`Buyurtma ID: ${result.data.order_id}`);
console.log(`Davlat: ${result.country.name}`);
} else {
console.log(`Xato: ${result.message}`);
}
})
.catch(error => {
console.error(error.message);
});
def get_number(self, country):
url = f"{self.base_url}?api_key={self.api_key}&action=getNumber&country={country}"
try:
response = requests.get(url)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
raise Exception(f"API so'rovida xato: {e}")
# Foydalanish
try:
result = sms.get_number('ke')
if result['ok']:
print(f"Nomer: {result['data']['number']}")
print(f"Buyurtma ID: {result['data']['order_id']}")
print(f"Davlat: {result['country']['name']}")
else:
print(f"Xato: {result['message']}")
except Exception as e:
print(e)
Olgan raqamingizga kelgan SMS kodni olish uchun ushbu endpoint dan foydalaning.
| Parametr | Tavsif | Misol |
|---|---|---|
order_id |
getNumber dan olingan buyurtma ID | 1, 2, 3 |
public function getCode($order_id) {
$url = $this->base_url . '?api_key=' . $this->api_key . '&action=getCode&order_id=' . $order_id;
$response = file_get_contents($url);
return json_decode($response, true);
}
// Foydalanish (SMS kelishini kutish)
$order_id = 1; // getNumber dan olingan ID
$max_attempts = 30; // Maksimal urinishlar soni
$attempt = 0;
do {
sleep(10); // 10 soniya kutish
$result = $sms->getCode($order_id);
$attempt++;
if ($result['ok'] && $result['data']['status'] === 'completed') {
echo "SMS kod: " . $result['data']['sms_code'] . "\n";
echo "Parol: " . $result['data']['password'] . "\n";
break;
}
echo "SMS kutilmoqda... ($attempt/$max_attempts)\n";
} while ($attempt < $max_attempts);
async getCode(orderId) {
try {
const response = await axios.get(`${this.baseUrl}?api_key=${this.apiKey}&action=getCode&order_id=${orderId}`);
return response.data;
} catch (error) {
throw new Error('API so\'rovida xato: ' + error.message);
}
}
// SMS kelishini kutish funksiyasi
async waitForSMS(orderId, maxAttempts = 30) {
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try {
const result = await this.getCode(orderId);
if (result.ok && result.data.status === 'completed') {
return {
success: true,
smsCode: result.data.sms_code,
password: result.data.password,
number: result.data.number
};
}
console.log(`SMS kutilmoqda... (${attempt}/${maxAttempts})`);
await new Promise(resolve => setTimeout(resolve, 10000)); // 10 soniya kutish
} catch (error) {
console.error(`Urinish ${attempt}: ${error.message}`);
}
}
return { success: false, message: 'SMS kelmadi' };
}
// Foydalanish
const orderId = 1;
sms.waitForSMS(orderId)
.then(result => {
if (result.success) {
console.log(`SMS kod: ${result.smsCode}`);
console.log(`Parol: ${result.password}`);
} else {
console.log(result.message);
}
});
import time
def get_code(self, order_id):
url = f"{self.base_url}?api_key={self.api_key}&action=getCode&order_id={order_id}"
try:
response = requests.get(url)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
raise Exception(f"API so'rovida xato: {e}")
def wait_for_sms(self, order_id, max_attempts=30):
"""SMS kelishini kutish funksiyasi"""
for attempt in range(1, max_attempts + 1):
try:
result = self.get_code(order_id)
if result['ok'] and result['data']['status'] == 'completed':
return {
'success': True,
'sms_code': result['data']['sms_code'],
'password': result['data']['password'],
'number': result['data']['number']
}
print(f"SMS kutilmoqda... ({attempt}/{max_attempts})")
time.sleep(10) # 10 soniya kutish
except Exception as e:
print(f"Urinish {attempt}: {e}")
return {'success': False, 'message': 'SMS kelmadi'}
# Foydalanish
order_id = 1
result = sms.wait_for_sms(order_id)
if result['success']:
print(f"SMS kod: {result['sms_code']}")
print(f"Parol: {result['password']}")
else:
print(result['message'])