标签:http return ace scribe sha php_eol pre limit cal
<?php // step 1: 生成规范请求字符串
$httpRequestMethod = "POST";
$canonicalUri = "/";
$canonicalQueryString = "";
$canonicalHeaders = "content-type:application/json; charset=utf-8\n"."host:".$host."\n";
$signedHeaders = "content-type;host";
$payload = ‘{"Limit": 1, "Filters": [{"Values": ["\u672a\u547d\u540d"], "Name": "instance-name"}]}‘;
$hashedRequestPayload = hash("SHA256", $payload);
$canonicalRequest = $httpRequestMethod."\n"
.$canonicalUri."\n"
.$canonicalQueryString."\n"
.$canonicalHeaders."\n"
.$signedHeaders."\n"
.$hashedRequestPayload;
// echo $canonicalRequest.PHP_EOL;
// step 2: 生成要签名的字符串
$date = gmdate("Y-m-d", $timestamp);
$credentialScope = $date."/".$service."/tc3_request";
$hashedCanonicalRequest = hash("SHA256", $canonicalRequest);
$stringToSign = $algorithm."\n"
.$timestamp."\n"
.$credentialScope."\n"
.$hashedCanonicalRequest;
// echo $stringToSign.PHP_EOL;
// step 3: 签名字符串
$secretDate = hash_hmac("SHA256", $date, "TC3".$this->secretKey, true);
$secretService = hash_hmac("SHA256", $service, $secretDate, true);
$secretSigning = hash_hmac("SHA256", "tc3_request", $secretService, true);
$signature = hash_hmac("SHA256", $stringToSign, $secretSigning);
// echo $signature.PHP_EOL;
// step 4: 生成授权
$authorization = $algorithm
." Credential=".$this->secretId."/".$credentialScope
.", SignedHeaders=content-type;host, Signature=".$signature;
// echo $authorization.PHP_EOL;
$curl = "curl -X POST https://".$host
.‘ -H "Authorization: ‘.$authorization.‘"‘
.‘ -H "Content-Type: application/json; charset=utf-8"‘
.‘ -H "Host: ‘.$host.‘"‘
.‘ -H "X-TC-Action: ‘.$action.‘"‘
.‘ -H "X-TC-Timestamp: ‘.$timestamp.‘"‘
.‘ -H "X-TC-Version: ‘.$version.‘"‘
.‘ -H "X-TC-Region: ‘.$region.‘"‘
." -d ‘".$payload."‘";
return $curl.PHP_EOL;
}
}
标签:http return ace scribe sha php_eol pre limit cal
原文地址:https://blog.51cto.com/13346331/2488855