<?php
function calculateSignature($method, $url, $body, $secret) {
// Формируем строку для подписи
$stringToSign = $method . $url . ($body ?? '');
// Вычисляем HMAC-SHA256
$signature = hash_hmac('sha256', $stringToSign, $secret, true);
return base64_encode($signature);
}
// Пример использования
$method = 'POST';
$url = 'https://api.meridian.vip/api/v1/resource';
$body = json_encode([
'key' => 'value',
'data' => 'example'
]);
// Ваш API ключ в формате: luma_keyId:luma_secret
$apiKey = 'luma_abc123...:luma_xyz789...';
list($keyId, $secret) = explode(':', $apiKey);
$signature = calculateSignature($method, $url, $body, $secret);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'X-API-Key: ' . $apiKey,
'X-Signature: ' . $signature
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
?>