Your IP : 18.217.241.79


Current Path : /home/bitrix/ext_www/dev.ballu.in.ua/
Upload File :
Current File : /home/bitrix/ext_www/dev.ballu.in.ua/service_list.php

<? require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");
if ($_REQUEST['k'] != '2k3lkrtpljkp') {
}
global $API_URL, $API_ADDRESS, $API_KEY;

$API_URL = 'http://api.rusklimat.ru/v0/ebasc/get';
$API_ADDRESS = ['ebasc/get', 'ebap/get'];
$API_KEY = 'WWYzZEd3V29jMXFxMDJweTcvSjJOZz09';

function getRest($address, $data = [], $method = "GET", $direct = false) {
	global $API_URL;
	global $API_ADDRESS;
	global $API_KEY;

	if ($direct == false)
		$service = $API_ADDRESS[$address];
	else
		$service = $address;

	$url = $API_URL . $service;

	$opts = array('http' =>
		array(
			'method' => $method,
			'header' => "Authorization: " . $API_KEY,
		)
	);
	if (!empty($data) && $method != "GET") {
		$opts['http']['content'] = http_build_query($data);
	} elseif (!empty($data) && $method == "GET") {
		$toSend = http_build_query($data);
		$url .= "?" . $toSend;
	}

	$context = stream_context_create($opts);
	$result = file_get_contents($url, false, $context);

	if ($result !== false)
		$responce = json_decode($result, true);
	else
		$responce = "error";
	return $responce;
}

$errors = [];
$result = getRest('', '', 'GET', false);

$data = $result['data']['services']['service'];
foreach ($data as $service) {
	$services[$service['city_id']][] = $service;
}

echo '<pre>'.print_r($result, true).'</pre>';