Viewing file: Fivesim.php (2.96 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Libraries;
class Fivesim
{
private function request($path)
{
$apiKey = settings('fivesim_api_key');
$apiUrl = "http://api1.5sim.biz/stubs/handler_api.php?api_key={$apiKey}&$path";
$output = file_get_contents($apiUrl);
return $output;
}
public function getBalance()
{
$balance = $this->request("action=getBalance");
return explode(':', $balance)[1];
}
public function getCategories()
{
$output = json_decode(file_get_contents("https://5sim.biz/v1/guest/products/any/any"), true);
$categories = [];
foreach ($output as $name => $value) {
$categories[] = [
'id' => $name,
'name' => $name
];
}
return $categories;
}
public function getServices($categoryId)
{
$output = json_decode(file_get_contents("https://5sim.biz/v1/guest/prices?product=$categoryId"), true);
$countries = [];
foreach ($output[$categoryId] as $name => $value) {
$countries[] = [
'id' => $name,
'name' => $name,
'price' => max(array_column($output[$categoryId][$name], 'cost')),
];
}
return $countries;
}
public function getServiceDetails($country, $serviceId)
{
$output = json_decode(file_get_contents("https://5sim.biz/v1/guest/prices?product=$serviceId"), true)[$serviceId][$country];
return [
'id' => "$country,$serviceId",
'price' => max(array_column($output, 'cost')),
'stock' => rand(100, 3000)
];
}
public function getNumber($serviceId, $country)
{
$output = $this->request("action=getNumber&country={$country}&service={$serviceId}&operator=any");
$output = explode(':', $output);
if (count($output) != 3) {
return [
'success' => false,
'data' => $output
];
}
$this->request("action=setStatus&id={$output[1]}&status=1");
return [
'success' => true,
'number' => $output[2],
'number_id' => (int)$output[1]
];
}
public function cancelNumber($numberId)
{
$this->request("action=setStatus&id={$numberId}&status=-1");
return [
'success' => true
];
}
public function getMessage($numberId)
{
$output = $this->request("action=getStatus&id={$numberId}");
$output = explode(":", $output);
if (count($output) > 1) {
$this->request("action=setStatus&id={$numberId}&status=6");
array_shift($output);
return [
'code' => join(':', $output),
'status' => '1'
];
}
return [
'code' => null,
'status' => -1
];
}
}
|