Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
function createSign($secret, $path, $timestamp, array $otherParams = []) {
$queryParams = array_merge(['timestamp' => $timestamp], $otherParams);
unset($queryParams['sign']);
unset($queryParams['access_token']);
ksort($queryParams);
$signString = $path;
foreach ($queryParams as $key => $value) {
$signString .= $key . $value;
}
return hash_hmac('sha256', $secret . $signString . $secret, $secret);
}
// Test Parameters
$secret = "test_sec_456";
$path = "/api/v2/orders";
$timestamp = "2024-05-21T09:30:00Z";
$otherParams = [
'category' => 'electronics',
'sort' => 'price_desc',
'sign' => 'dummy', // Should be ignored
'access_token' => 'dummy' // Should be ignored
];
// Generate Signature
$generatedSign = createSign($secret, $path, $timestamp, $otherParams);
// Debug Output
echo "Secret: $secret\n";
echo "Path: $path\n";
echo "Timestamp: $timestamp\n";
echo "Other Params: " . json_encode($otherParams) . "\n";
echo "Generated Signature: $generatedSign\n";
?>