Calcular signature - LIB em PHP
Lib em PHP construída e fornecida por um Developer Partner da Amazon para acelerar seu desenvolvimento:
<? phpclassAmazon
{
public function calculateAwsSignatureAndReturnHeaders($host, $uri, $requestUrl, $accessKey, $secretKey, $region, $service, $httpRequestMethod, $data, $debug = true)
{
$terminationString = 'aws4_request';
$algorithm = 'AWS4-HMAC-SHA256';
$hpAlgorithm = 'sha256';
$canonicalURI = $uri;
$canonicalQueryString = '';
$signedHeaders = 'content-type;host;x-amz-date';
$currentDateTime = new DateTime('UTC');
$reqDate = $currentDateTime->format('Ymd');
$reqDateTime = $currentDateTime->format('Ymd\THis\Z');
$credentialScope[] = $terminationString;
$credentialScopeStr = implode('/', $credentialScope);
$signature = hash_hmac($hpAlgorithm, $stringToSignStr, $kSigning);
$headers = curl_getinfo($curl, CURLINFO_HEADER_OUT);
echo "<h5>Request</h5>";
echo "<pre>";
echo $headers;
echo "</pre>";
}
curl_close($curl);
if ($err)
{
if ($debug)
{
echo "<h5>Error:" . $responseCode . "</h5>";
echo "<pre>";
echo $err;
echo "</pre>";
}
}
else
{
if ($debug)
{
echo "<h5>Response:" . $responseCode . "</h5>";
echo "<pre>";
echo $response;
echo "</pre>";
}
}
return array(
"responseCode" => $responseCode,
"response" => $response,
"error" => $err
);
}
Updated over 3 years ago