Reads:52092Replies:2
PHP API Struggle
I am in a desperate struggle to get the PHP API to work. Please explain why this code returns an IncompleteSignature error each time. I have tried every possible approach for several days to get this to work and have had no success.
<?php //DescribeRegions.php $accessKeyID=//"MY ACCESS KEY ID HERE"; $accessKeySecret=//"MY ACCESS KEY HERE"; date_default_timezone_set('UTC'); $dateString = date("Y-m-d"); $timeString = date("H:i:s"); $timeStamp =$dateString.'T'.$timeString.'Z'; $nonce=generateNonce(); $requestParameterKeys = array("AccessKeyId", "Action", "Format", "RegionId", "SignatureMethod", "SignatureNonce", "SignatureVersion", "Timestamp", "Version"); $requestParameterValues = array($accessKeyID, "DescribeRegions", "JSON", "region1", "HMAC-SHA1", $nonce, "1.0", $timeStamp, "2014-05-26"); $stringToSign = generateStringToSign($requestParameterKeys,$requestParameterValues); $signature = base64_encode(hash_hmac('sha1',$stringToSign,$accessKeySecret.'&',$raw_output=TRUE)); $destinationURL=("http://ecs.aliyuncs.com/?".listParameters($requestParameterKeys,$requestParameterValues)."&Signature=".urlencode($signature)); header('Location: '.$destinationURL); function generateStringToSign($keys,$values){ $canonicalizedQueryString=""; for ($i=0;$i<count($keys);$i++){ if($i!=0){ $canonicalizedQueryString=$canonicalizedQueryString.'&'; } $canonicalizedQueryString=$canonicalizedQueryString.$keys[$i].'='.$values[$i]; } return('GET'.'&'.urlencode('/').'&'.urlencode($canonicalizedQueryString)); } function listParameters($keys,$values){ $parameters=""; for($i=0;$i<count($keys);$i++){ if($i!=0){ $parameters=$parameters.'&'; } $parameters=$parameters.urlencode($keys[$i]).'='.urlencode($values[$i]); } return $parameters; } function generateNonce($length = 16) { return substr(str_shuffle(str_repeat($x='0123456789', ceil($length/strlen($x)) )),1,$length); } ?> |
|
1st Reply#
Posted time:Aug 30, 2016 19:11 PM
Refer to the php code in this doc:
https://help.aliyun.com/knowledge_detail/40603.html Clear the browser cache before open the above url. |
|
2nd Reply#
Posted time:Aug 30, 2016 19:28 PM
Sorry, the user is banned
|
|