<?
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/include/sale_delivery/delivery_ratekapi.php");
CModule::IncludeModule("sale");
CModule::IncludeModule("main");
class RATEKClient {
/**
* Описние обработчика
*/
function Init()
{
//настройки
return array(
"SID" => "RATEK", // Идентификатор службы доставки
"NAME" => "Ратэк",
"DESCRIPTION" => "Описание его для клиентов сайта",
"DESCRIPTION_INNER" => "Описание для администраторов сайта",
"BASE_CURRENCY" => "RUR",
"HANDLER" => __FILE__,
/* Определение методов */
"DBGETSETTINGS" => array("RATEKClient", "GetSettings"),
"DBSETSETTINGS" => array("RATEKClient", "SetSettings"),
"GETCONFIG" => array("RATEKClient", "GetConfig"),
"COMPABILITY" => array("RATEKClient", "Compability"),
"CALCULATOR" => array("RATEKClient", "Calculate"),
/* Список профилей */
"PROFILES" => array(
"all" => array(
"TITLE" => "Без ограничений",
"DESCRIPTION" => "Профиль доставки без каких-либо ограничений",
"RESTRICTIONS_WEIGHT" => array(0),
"RESTRICTIONS_SUM" => array(0),
),
)
);
}
function __construct($key){
$key?$this->key = $key:die("There is no key");
}
function calc($params = array()){
$url = 'http://api.rateksib.ru/v1/calc.json';
$body = $params;
$body["key"] = $this->key;
$opts = array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded\r\n"
. "Content-Length: " . strlen(http_build_query($body)) . "\r\n",
'content' => http_build_query($body),
)
);
$result = file_get_contents($url, false, stream_context_create($opts));
$this->calcresult = (array)json_decode($result);
}
function track($nakl)
{
$url = 'http://api.rateksib.ru/v1/track.json';
$body = array ("number" => $nakl);
$body["key"] = $this->key;
$opts = array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded\r\n"
. "Content-Length: " . strlen(http_build_query($body)) . "\r\n",
'content' => http_build_query($body),
)
);
$result = file_get_contents($url, false, stream_context_create($opts));
echo $result; exit();
$this->trackresult = (array)json_decode($result);
}
function cityList()
{
$body = array ("key" => $this->key);
$opts = array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded\r\n"
. "Content-Length: " . strlen(http_build_query($body)) . "\r\n",
'content' => http_build_query($body),
)
);
$url = 'http://api.rateksib.ru/v2/cityList.json';
$result = file_get_contents($url, false, stream_context_create($opts));
$this->cityListresult = (array)json_decode($result);
}
}
$key = 'DVr6RE3ANJvxVikaz9D7pAyOK'; // key here
$client = new RATEKClient($key);
// params example:
$params = array();
$params['weight'] = 400;
$params['volume'] = 0.5;
$params['width'] = 0.2;
$params['height'] = 1.2;
$params['length'] = 11.4;
$params['price'] = 3000;
$params['marked'] = false;
$params['negabarit'] = false;
$params['weight_ng'] = 0;
$params['volume_ng'] = 0;
$params['volume_obr'] = 0; // Вес обрешётки, этот параметр может быть равен общему объёму груза, но НЕ МОЖЕТ БЫТЬ БОЛЬШЕ общего объёма груза.
$params['from'] = 6307423;
$params['to'] = 6342128;
/* $client->calc($params);
print_r ($client->calcresult);*/
/* $client->track('Чел1101204828'); // Track number in utf-8 here
print_r ($client->trackresult);
*/
/* $client->cityList();
print_r ($client->cityListresult); */
AddEventHandler("sale", "onSaleDeliveryHandlersBuildList", array("RATEKClient", "Init"));
?>
|