<?php
header('Content-Type: text/html; charset=utf-8');
$ak = "";
$sk = "";
$terminal_id = bin2hex(random_bytes(16));
$default_empty_payload = "{}";
$ct = "application/json; charset=utf-8";
$host = "api-smbcloud.tplinkcloud.com.cn";
$endpoint = "https://" . $host;
$algorithm = "HmacSHA256";
$timestamp = time();
$nonce = bin2hex(random_bytes(16));
$method = "POST";
$path = "/tums/open/resource/v1/getPagedRootRegions";
$payload = json_encode(array("start" => 0, "limit" => 10, "needDevNum" => 0));
$hashed_request_payload = hash_hmac("sha256", $payload, "", true);
$credential_scope = $method . " " . $path . " " . "tp-link_request";
$string_to_sign = $algorithm . "\n" .
$timestamp . "\n" .
$credential_scope . "\n" .
$hashed_request_payload;
function sign($key, $msg) {
return hash_hmac("sha256", $msg, $key, true);
}
$secret_date = sign($sk, $timestamp);
$secret_service = sign($secret_date, $path);
$secret_signing = sign($secret_service, "tp-link");
$signature = hash_hmac("sha256", $string_to_sign, $secret_signing);
$authorization = "Timestamp=" . $timestamp . "," .
"Nonce=" . $nonce . "," .
"AccessKey=" . $ak . "," .
"Signature=" . bin2hex($signature) . "," .
"TerminalId=" . $terminal_id;
echo "Authorization: " . $authorization . "\n";
echo 'curl -X POST ' . $endpoint . $path .
' -H "X-Authorization: ' . $authorization . '"' .
' -H "Content-Type: ' . $ct . '"' .
' -H "Host: ' . $host . '"' .
" -d '" . $payload . "'\n";
?>