Файл: system/classes/Api.php
Строк: 32
<?php
class Api
{
protected
$url_api = 'http://netscms.ru/api/',
$id_client,
$secret_key,
$init;
public function __construct()
{
global $config;
$this->id_client= $config['id_client'];
$this->secret_key = $config['secret_key'];
$this->init = curl_init();
}
public function query($method, $param)
{
$main = [
'method' => $method,
'id_client' => $this->id_client,
'secret_key' => $this->secret_key
];
$result = $this->curl($this->url_api, http_build_query(array_merge($main, $param)));
$array = json_decode($result, true);
if (isset($array['response']))
{
return $array['response'];
}
else
{
return $array['error'];
}
}
function curl($url, $post)
{
$options = [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $post
];
curl_setopt_array($this->init, $options);
return curl_exec($this->init);
}
}