Mercurial > hg > ywww
comparison xml/aws_signed_request.php @ 6:077b0a0a3e6d
remaining originals according to dependency walk
| author | Robert Boland <robert@markup.co.uk> |
|---|---|
| date | Thu, 16 Feb 2017 22:29:02 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 5:55445b456ad0 | 6:077b0a0a3e6d |
|---|---|
| 1 <?php | |
| 2 | |
| 3 //20090627/Jaap van Ganswijk: This is a modified version, see the | |
| 4 //return statement some lines before the end of the last function. | |
| 5 | |
| 6 if (!function_exists("aws_signed_request")) { | |
| 7 function aws_signed_request($region, $params, $public_key, $private_key) | |
| 8 { | |
| 9 /* | |
| 10 Copyright (c) 2009 Ulrich Mierendorff | |
| 11 | |
| 12 Permission is hereby granted, free of charge, to any person obtaining a | |
| 13 copy of this software and associated documentation files (the "Software"), | |
| 14 to deal in the Software without restriction, including without limitation | |
| 15 the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
| 16 and/or sell copies of the Software, and to permit persons to whom the | |
| 17 Software is furnished to do so, subject to the following conditions: | |
| 18 | |
| 19 The above copyright notice and this permission notice shall be included in | |
| 20 all copies or substantial portions of the Software. | |
| 21 | |
| 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| 23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| 24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
| 25 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| 26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
| 27 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
| 28 DEALINGS IN THE SOFTWARE. | |
| 29 */ | |
| 30 | |
| 31 /* | |
| 32 Parameters: | |
| 33 $region - the Amazon(r) region (ca,com,co.uk,de,fr,jp) | |
| 34 $params - an array of parameters, eg. array("Operation"=>"ItemLookup", | |
| 35 "ItemId"=>"B000X9FLKM", "ResponseGroup"=>"Small") | |
| 36 $public_key - your "Access Key ID" | |
| 37 $private_key - your "Secret Access Key" | |
| 38 */ | |
| 39 | |
| 40 // some paramters | |
| 41 $method = "GET"; | |
| 42 $host = "ecs.amazonaws.".$region; | |
| 43 $uri = "/onca/xml"; | |
| 44 | |
| 45 // additional parameters | |
| 46 $params["Service"] = "AWSECommerceService"; | |
| 47 $params["AWSAccessKeyId"] = $public_key; | |
| 48 // GMT timestamp | |
| 49 $params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z"); | |
| 50 // API version | |
| 51 $params["Version"] = "2011-08-01"; | |
| 52 | |
| 53 // sort the parameters | |
| 54 ksort($params); | |
| 55 | |
| 56 // create the canonicalized query | |
| 57 $canonicalized_query = array(); | |
| 58 foreach ($params as $param=>$value) | |
| 59 { | |
| 60 $param = str_replace("%7E", "~", rawurlencode($param)); | |
| 61 $value = str_replace("%7E", "~", rawurlencode($value)); | |
| 62 $canonicalized_query[] = $param."=".$value; | |
| 63 } | |
| 64 $canonicalized_query = implode("&", $canonicalized_query); | |
| 65 | |
| 66 // create the string to sign | |
| 67 $string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query; | |
| 68 | |
| 69 // calculate HMAC with SHA256 and base64-encoding | |
| 70 $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True)); | |
| 71 | |
| 72 // encode the signature for the request | |
| 73 $signature = str_replace("%7E", "~", rawurlencode($signature)); | |
| 74 | |
| 75 // create request | |
| 76 $request = "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature; | |
| 77 | |
| 78 //20090627 and 20090804/Jaap van Ganswijk: I added the next lines | |
| 79 //and commented out the others to prevent getting the file and | |
| 80 //interpreting the XML because my script likes to do that itself. | |
| 81 | |
| 82 return $request; | |
| 83 | |
| 84 // // do request | |
| 85 // $response = @file_get_contents($request); | |
| 86 // | |
| 87 // if ($response === False) | |
| 88 // { | |
| 89 // return False; | |
| 90 // } | |
| 91 // else | |
| 92 // { | |
| 93 // // parse XML | |
| 94 // $pxml = simplexml_load_string($response); | |
| 95 // if ($pxml === False) | |
| 96 // { | |
| 97 // return False; // no xml | |
| 98 // } | |
| 99 // else | |
| 100 // { | |
| 101 // return $pxml; | |
| 102 // } | |
| 103 // } | |
| 104 } | |
| 105 } | |
| 106 ?> |
