которые позволят интегрировать на ваш сайт наши возможности.
Используя наш API, вы сможете на своём сайте:
- оформлять квитанции (ТТН) и получать обратно их номер;
- получать трекинг (движение) груза по квитанции;
- узнавать полную информацию по уже созданной квитанции;
- производить расчёт стоимости отправки груза;
- выводить справочную информацию по городам, в которых работает Деливери, и складам, которые там есть.
Реализовать всё, что написано в разделе для владельцев можно, скачав документацию (кнопка ниже) и ознакомившись с методами.
Если для работы вам нужна только справочная информация (списки городов, складов и другое), то методами можно пользоваться прямо сейчас, без предварительной подготовки. Для всего другого - необходима регистрация на сайте Деливери.
Важно! Некоторые функции в документации имеют пометку "Метод требует авторизации", а некоторые "Метод требует авторизации через API". Для второго случая вам необходимо сгенерировать API-ключи (кнопка ниже), а для первого - просто авторизироваться доступными в документации способами.
Отметим, что функции для работы с квитанциями требуют ключей, поэтому лучше не откладывать этот вопрос в долгий ящик.
var apiKey = 'CDBFE2D5-BF02-4C0D-B7D6-5CF277761C50';
var apiSecretKey = '6c131f01b99dfac3529d0cd68b1d6649';
var getHMAC = function (key, timestamp) {
var hash = CryptoJS.HmacSHA1(key + timestamp, apiSecretKey);
return hash.toString();
};
var data = {
"culture": "ru-RU",
"flSave": "false",
"debugMode": "true",
"receiptsList": [
{
"senderid": "CDBFE2D5-BF02-4C0D-B7D6-5CF277761C50",
"areasSendId": "4577d856-322b-e311-8b0d-00155d037960",
"areasResiveId": "16617df3-a42a-e311-8b0d-00155d037960",
"warehouseSendId": "5f2af375-5d70-e211-9ce1-00155d012a15",
"warehouseResiveId": "bdff546c-cb16-e211-89ed-00155d053b5d",
"dateSend": "2018-02-20T00:00:00",
"deliveryScheme": 0,
"posibleResiverReceipt_1": "ee5df311-6565-44d5-84f6-14875aa3e208",
"posibleResiverReceipt_2": "",
"posibleResiverReceipt_3": "",
"posibleResiverReceipt_4": "",
"currency": 100000000,
"InsuranceValue": 5000,
"payerInsuranceId": "1aa70d22-1209-e511-b3b5-000d3a200160",
"payerType": 1,
"paymentType": 0,
"paymentTypeInsuranse": 0,
"deliveryAddressId": "",
"deliveryContactName": "",
"deliveryContactPhone": "",
"DeliveryComment": "",
"ReturnDocuments": false,
"climbingToFloor": 0,
"CustomsCost": 0,
"CustomsCurrency": 100000000,
"CustomsDocuments": false,
"CustomsDescriptions": "",
"cashOnDeliveryType": 2,
"CashOnDeliveryValuta": 100000000,
"CashOnDeliveryValue": 5000,
"CashOnDeliveryCardId": "",
"CashOnDeliveryWarehouseId": "5f2af375-5d70-e211-9ce1-00155d012a15",
"CashOnDeliverySenderFullName": "Семёнов Семён Семёнович",
"CashOnDeliverySenderPhone": "0958888888",
"CashOnDeliveryRasschSchetId": "",
"CashOnDeliveryReceiverFullName": "Петров Пётр Петрович",
"CashOnDeliveryReceiverPhone": "0671234567",
"parentNumber": "",
"CashOnDeliveryDescription": "Описание",
"CashOnDeliveryPayerAccountId": "ee5df311-6565-44d5-84f6-14875aa3e208",
"pickUpDate": "",
"pickUpContactName": "",
"pickUpContactPhone": "",
"pickUpAddressId": "",
"descentFromFloor": 0,
"category": [
{
"categoryId": "00000000-0000-0000-0000-000000000000",
"cargoCategoryId": "f506d03b-9e36-e311-8b0d-00155d037960",
"countPlace": 1,
"helf": 1,
"size": 0.3,
"isEconom": false,
"PartnerNumber": "\"\""
}
]
}
]
};
$.ajax({
url: 'https://www.delivery-auto.com/api/v4/Public/PostCreateReceipts',
type: "POST",
data: data,
dataType: 'json',
beforeSend: function (request) {
request.setRequestHeader('HMACAuthorization', 'amx ' + apiKey + ':' + timestamp + ':' + getHMAC(apiKey, timestamp));
},
success: function (data) {
debugger;
if (data.status == true) {
debugger;
}
},
error: alert('error');
});
public string getHMAC(string publicKey, TimeSpan timestamp, string secretKey) {
string message = publicKey + timestamp.Milliseconds.ToString();
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
HMACSHA1 hmacsha1 = new HMACSHA1(encoding.GetBytes(secretKey));
byte[] hashmessage = hmacsha1.ComputeHash(encoding.GetBytes(message));
return ByteToString(hashmessage);
}
public static string ByteToString(byte[] buff)
{
string sbinary = "";
for (int i = 0; i < buff.Length; i++)
{
sbinary += buff[i].ToString("X2"); // hex format
}
return (sbinary);
}
public ActionResult TestJSApi()
{
string dataString = @"{
"culture": "ru-RU",
"flSave": "false",
"debugMode": "true",
"receiptsList": [
{
"senderid": "CDBFE2D5-BF02-4C0D-B7D6-5CF277761C50",
"areasSendId": "4577d856-322b-e311-8b0d-00155d037960",
"areasResiveId": "16617df3-a42a-e311-8b0d-00155d037960",
"warehouseSendId": "5f2af375-5d70-e211-9ce1-00155d012a15",
"warehouseResiveId": "bdff546c-cb16-e211-89ed-00155d053b5d",
"dateSend": "2018-02-20T00:00:00",
"deliveryScheme": 0,
"posibleResiverReceipt_1": "ee5df311-6565-44d5-84f6-14875aa3e208",
"posibleResiverReceipt_2": "",
"posibleResiverReceipt_3": "",
"posibleResiverReceipt_4": "",
"currency": 100000000,
"InsuranceValue": 5000,
"payerInsuranceId": "1aa70d22-1209-e511-b3b5-000d3a200160",
"payerType": 1,
"paymentType": 0,
"paymentTypeInsuranse": 0,
"deliveryAddressId": "",
"deliveryContactName": "",
"deliveryContactPhone": "",
"DeliveryComment": "",
"ReturnDocuments": false,
"climbingToFloor": 0,
"CustomsCost": 0,
"CustomsCurrency": 100000000,
"CustomsDocuments": false,
"CustomsDescriptions": "",
"cashOnDeliveryType": 2,
"CashOnDeliveryValuta": 100000000,
"CashOnDeliveryValue": 5000,
"CashOnDeliveryCardId": "",
"CashOnDeliveryWarehouseId": "5f2af375-5d70-e211-9ce1-00155d012a15",
"CashOnDeliverySenderFullName": "Семёнов Семён Семёнович",
"CashOnDeliverySenderPhone": "0958888888",
"CashOnDeliveryRasschSchetId": "",
"CashOnDeliveryReceiverFullName": "Петров Пётр Петрович",
"CashOnDeliveryReceiverPhone": "0671234567",
"parentNumber": "",
"CashOnDeliveryDescription": "Описание",
"CashOnDeliveryPayerAccountId": "ee5df311-6565-44d5-84f6-14875aa3e208",
"pickUpDate": "",
"pickUpContactName": "",
"pickUpContactPhone": "",
"pickUpAddressId": "",
"descentFromFloor": 0,
"category": [
{
"categoryId": "00000000-0000-0000-0000-000000000000",
"cargoCategoryId": "f506d03b-9e36-e311-8b0d-00155d037960",
"countPlace": 1,
"helf": 1,
"size": 0.3,
"isEconom": false,
"PartnerNumber": "\"\""
}
]
}
]
}";
var apiKey = "CDBFE2D5-BF02-4C0D-B7D6-5CF277761C50";
var apiSecretKey = "6c131f01b99dfac3529d0cd68b1d6649";
DateTime myDate1 = new DateTime(1970, 1, 9, 0, 0, 00);
DateTime myDate2 = DateTime.Now;
var timestamp = myDate2.Subtract(myDate1);
var HMAC = getHMAC(apiKey, timestamp, apiSecretKey);
var request = (HttpWebRequest)WebRequest.Create("https://www.delivery-auto.com/api/v4/Public/PostCreateReceipts");
var data = System.Text.Encoding.UTF8.GetBytes(dataString);
request.Method = "POST";
request.ContentType = "text/json";
request.ContentLength = data.Length;
request.Headers["HMACAuthorization"] = string.Format("amx {0}:{1}:{2}", apiKey, timestamp.Milliseconds.ToString(), HMAC);
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
/*Приклад взаємодії з Delivery API (PHP) by SNENKO web development*/
class DeliveyAutoApi
{
protected $public_key;
protected $secret_key;
public $culture = 'ru-RU';//en-US, ru-RU, uk-UA
function __construct($culture = '', $public_key = '', $secret_key = '')
{
if (!empty($culture)):
$this->culture = $culture;
endif;
if (!empty($public_key)):
$this->public_key = 'your_key';
endif;
if (!empty($secret_key)):
$this->secret_key = "your_key";
endif;
}
function send($part) //you custom params here
{
$url = 'https://www.delivery-auto.com/api/v4/Public/PostReceiptCalculate';
$data = array(
'culture' => $this->culture,
'areasSendId' => $part['city_sender'],
'areasResiveId' => $part['city_incoming'],
'warehouseSendId' => $part['warehouse_sender'],
'warehouseResiveId' => $part['warehouse_incoming'],
'InsuranceValue' => 1000000,
'CashOnDeliveryValue' => 5000,
'dateSend' => $part['sending_date'],
'deliveryScheme' => 2,
'category' => [[
'categoryId' => "00000000-0000-0000-0000-000000000000",
'countPlace' => 1,
'helf' => $part['weight'],
'size'=> 0.1
]],
'dopUslugaClassificator' => [[
'dopUsluga' => [
'uslugaId' => "2b4247c9-be8c-e211-be60-00155d037919",
'count' => 1
]
]]
);
return curl_POST($url, $data);
}
function curl_POST($url, $data)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
$result = curl_exec($curl);
curl_close($curl);
return json_decode($result);
}
}
Если в процессе работы появились вопросы - задайте их разработчикам компании Delivery, заполнив форму обращения.
Также формой можно воспользоваться если были обнаружены ошибки, о которых вы хотите нам сообщить, или у вас есть предложения по улучшению работы сервиса. Або напишiть розробнику - SBabiy@delivery-auto.com.ua