Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?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"; ?>
Copy Clear