Viewing file: RentLibrary.php (6.69 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Libraries;
class RentLibrary
{
private $countries = [];
private $services = [];
public function __construct()
{
$this->countries = [
'0' => 'Russia',
'1' => 'Ukraine',
'2' => 'Kazakhstan',
'3' => 'China',
'4' => 'Philippines',
'5' => 'Myanmar',
'6' => 'Indonesia',
'7' => 'Malaysia',
'8' => 'Kenya',
'10' => 'Vietnam',
'11' => 'Kyrgyzstan',
'12' => 'USA',
'13' => 'Israel',
'14' => 'HongKong',
'15' => 'Poland',
'16' => 'England',
'17' => 'Madagascar',
'18' => 'Congo',
'19' => 'Nigeria',
'20' => 'Macao',
'21' => 'Egypt',
'22' => 'India',
'23' => 'Ireland',
'24' => 'Cambodia',
'25' => 'Laos',
'26' => 'Haiti',
'27' => 'Ivory',
'28' => 'Gambia',
'29' => 'Serbia',
'30' => 'Yemen',
'31' => 'Southafrica',
'32' => 'Romania',
'33' => 'Colombia',
'34' => 'Estonia',
'35' => 'Azerbaijan',
'36' => 'Canada',
'37' => 'Morocco',
'38' => 'Ghana',
'39' => 'Argentina',
'40' => 'Uzbekistan',
'41' => 'Cameroon',
'42' => 'Chad',
'43' => 'Germany',
'44' => 'Lithuania',
'45' => 'Croatia',
'46' => 'Sweden',
'47' => 'Iraq',
'48' => 'Netherlands',
'49' => 'Latvia',
'50' => 'Austria',
'51' => 'Belarus',
'52' => 'Thailand',
'53' => 'Saudiarabia',
'54' => 'Mexico',
'55' => 'Taiwan',
'56' => 'Spain',
'57' => 'Iran',
'58' => 'Algeria',
'59' => 'Slovenia',
'60' => 'Bangladesh',
'61' => 'Senegal',
'62' => 'Turkey',
'63' => 'Czech',
'64' => 'Srilanka',
'65' => 'Peru',
'66' => 'Pakistan',
'67' => 'Newzealand',
'68' => 'Guinea',
'69' => 'Mali',
'70' => 'Venezuela',
'71' => 'Ethiopia',
'72' => 'Mongolia',
'73' => 'Brazil',
'74' => 'Afghanistan',
'75' => 'Uganda',
'76' => 'Angola',
'77' => 'Cyprus',
'78' => 'France',
'79' => 'Papua',
'80' => 'Mozambique',
'81' => 'Nepal',
'82' => 'Belgium',
'83' => 'Bulgaria',
'84' => 'Hungary',
'85' => 'Moldova',
'86' => 'Italy',
'87' => 'Paraguay',
'88' => 'Honduras',
'89' => 'Tunus',
'90' => 'Nikaragua',
'92' => 'Bolivya',
'93' => 'Kosta Rika',
'94' => 'Guatemala',
'97' => 'Porto Riko',
'98' => 'Sudan',
'100' => 'Kuveyt',
'101' => 'Salvador',
'102' => 'Libya',
'103' => 'Jamaika',
'105' => 'Ekvador',
'108' => 'Bosna Hersek',
'109' => 'Dominik Cumhuriyeti',
'110' => 'Suriye',
'111' => 'Katar',
'112' => 'Panama',
'113' => 'Kuba',
'114' => 'Moritanya',
'116' => 'Jordan',
'117' => 'Portekiz',
'122' => 'Bahamalar',
'128' => 'Gurcistan',
'129' => 'Yunanistan'
];
$this->services = [
'full' => 'Tamamen Kiralama',
'wa' => 'WhatsApp'
];
}
private function request($path)
{
$apiKey = settings('smsactivate_api_key');
$apiUrl = "https://api.sms-activate.org/stubs/handler_api.php?api_key={$apiKey}&{$path}";
$output = file_get_contents($apiUrl);
$output = json_decode($output, true);
if (isset($output['status']) && $output['status'] == 'error') {
die('Hata oluştu.');
}
return $output;
}
public function getCountries()
{
$response = $this->request("action=getRentServicesAndCountries");
$countries = [];
$lang = $this->countries;
foreach ($response['countries'] as $_ => $cid) {
if (isset($lang[$cid])) {
$countries[] = ['id' => $cid, 'name' => $lang[$cid]];
}
}
return $countries;
}
public function getServicesByCountry($country, $time = 4)
{
$response = $this->request("action=getRentServicesAndCountries&rent_time=$time&country=$country");
$services = [];
$lang = $this->services;
$rub = simplexml_load_file("https://www.tcmb.gov.tr/kurlar/today.xml");
$rub = $rub->Currency[14]->ForexSelling;
foreach ($response['services'] as $serviceId => $service) {
$name = isset($lang[$serviceId]) ? $lang[$serviceId] : $service['search_name'];
$count = $service['quant']['current'];
if ($count > 0) {
$services[] = [
'id' => $serviceId,
'name' => $name,
'cost' => number_format((floatval($service['cost']) / 100) * (100 + intval(settings('rent_rate'))) * $rub, 2),
'count' => $count
];
}
}
return $services;
}
public function buyNumber($service, $country, $time)
{
$response = $this->request("action=getRentNumber&service=$service&rent_time=$time&country=$country");
$errors = [
'BAD_KEY' => 'Sunucu kaynaklı bir hata oluştu.',
'BAD_SERVICE' => 'Hatalı servis belirtildi.',
'NO_BALANCE' => 'Sağlayıcı kaynaklı bir hata oluştu.',
'NO_NUMBERS' => 'Stokta yeterli numara bulunmuyor.',
'ACCOUNT_INACTIVE' => 'HATA!!',
'SQL_ERROR' => 'Veritabanı hatası.'
];
return [
'result' => $response,
'status' => $response['status'] == 'success',
'title' => $response['status'] == 'success' ? 'Başarılı! Numara satın alındı.' : $errors[$response['message']]
];
}
public function getStatus($id)
{
$response = $this->request("action=getRentStatus&id=$id");
return $response;
}
}
|