|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * ObjectSerializer |
| 5 | + * |
| 6 | + * PHP version 5 |
| 7 | + * |
| 8 | + * @category Class |
| 9 | + * @author rodrigojob |
| 10 | +
|
| 11 | + */ |
| 12 | +/** |
| 13 | + * Selling Partner API for Solicitations |
| 14 | + * |
| 15 | + * With the Solicitations API you can build applications that send non-critical solicitations to buyers. You can get a list of solicitation types that are available for an order that you specify, then call an operation that sends a solicitation to the buyer for that order. Buyers cannot respond to solicitations sent by this API, and these solicitations do not appear in the Messaging section of Seller Central or in the recipient's Message Center. The Solicitations API returns responses that are formed according to the <a href=https://tools.ietf.org/html/draft-kelly-json-hal-08>JSON Hypertext Application Language</a> (HAL) standard. |
| 16 | + * |
| 17 | + * OpenAPI spec version: v1 |
| 18 | + * |
| 19 | + * Generated by: https://github.com/swagger-api/swagger-codegen.git |
| 20 | + * Swagger Codegen version: 3.0.20 |
| 21 | + */ |
| 22 | +/** |
| 23 | + * NOTE: This class is auto generated by the swagger code generator program. |
| 24 | + * https://github.com/swagger-api/swagger-codegen |
| 25 | + * Do not edit the class manually. |
| 26 | + */ |
| 27 | + |
| 28 | +namespace Swagger\Client; |
| 29 | + |
| 30 | +/** |
| 31 | + * Signature Class Doc Comment |
| 32 | + * |
| 33 | + * @category Class |
| 34 | + * @package Swagger\Client |
| 35 | + * @author rodrigojob |
| 36 | + */ |
| 37 | +class SignatureSellingPartner { |
| 38 | + |
| 39 | + /** |
| 40 | + * calculateSignature data |
| 41 | + * |
| 42 | + * @param string $accessKey the Selling Partner Access Key |
| 43 | + * @param string $secretKey the IAM secret |
| 44 | + * @param string $region the region use AWS |
| 45 | + * @param string $accessToken the Selling Partner access-token |
| 46 | + * @param string $userAgent the user-agent to sign |
| 47 | + * @param string $host the host to sign |
| 48 | + * @param string $method the method to sign |
| 49 | + * @param string $uri the uri to sign |
| 50 | + * @param string $queryString the queryString to sign |
| 51 | + * @param mixed $data the data to sign |
| 52 | + * |
| 53 | + * @return array headers signed |
| 54 | + */ |
| 55 | + public static function calculateSignature($accessKey, $secretKey, $region, $accessToken, $userAgent, $host, $method, $uri = "", $queryString = "", $data = array()){ |
| 56 | + $service = 'execute-api'; |
| 57 | + $terminationString = 'aws4_request'; |
| 58 | + $algorithm = 'AWS4-HMAC-SHA256'; |
| 59 | + $amzdate = gmdate('Ymd\THis\Z'); |
| 60 | + $date = substr($amzdate, 0, 8); |
| 61 | + |
| 62 | + $param = json_encode($data); |
| 63 | + if ($param == "[]") { |
| 64 | + $requestPayload = ""; |
| 65 | + } else { |
| 66 | + $requestPayload = strtolower($param); |
| 67 | + } |
| 68 | + $hashedPayload = hash('sha256', $requestPayload); |
| 69 | + |
| 70 | + $canonical_headers = "host:" . $host . "\n" . "user-agent:" . $userAgent . "\n" . "x-amz-access-token:" . $accessToken . "\n" . "x-amz-date:" . $amzdate . "\n"; |
| 71 | + $credential_scope = $date . '/' . $region . '/' . $service . '/' . $terminationString; |
| 72 | + $signed_headers = 'host;user-agent;x-amz-access-token;x-amz-date'; |
| 73 | + |
| 74 | + $canonical_request = $method . "\n" . $uri . "\n" . $queryString . "\n" . $canonical_headers . "\n" . $signed_headers . "\n" . $hashedPayload; |
| 75 | + |
| 76 | + $stringToSign = $algorithm . "\n" . $amzdate . "\n" . $credential_scope . "\n" . hash('sha256', $canonical_request); |
| 77 | + |
| 78 | + $kSecret = "AWS4" . $secretKey; |
| 79 | + $kDate = hash_hmac('sha256', $date, $kSecret, true); |
| 80 | + $kRegion = hash_hmac('sha256', $region, $kDate, true); |
| 81 | + $kService = hash_hmac('sha256', $service, $kRegion, true); |
| 82 | + $kSigning = hash_hmac('sha256', $terminationString, $kService, true); |
| 83 | + |
| 84 | + $signature = trim(hash_hmac('sha256', $stringToSign, $kSigning)); // Without fourth parameter passed as true, returns lowercase hexits as called for by docs |
| 85 | + |
| 86 | + $authorization_header = $algorithm . " Credential={$accessKey}/{$credential_scope}, SignedHeaders={$signed_headers}, Signature={$signature}"; |
| 87 | + |
| 88 | + $headers = array( |
| 89 | + "host" => $host, |
| 90 | + "Authorization" => $authorization_header, |
| 91 | + "user-agent" => $userAgent, |
| 92 | + "x-amz-access-token" => $accessToken, |
| 93 | + "x-amz-date" => $amzdate |
| 94 | + ); |
| 95 | + |
| 96 | + return $headers; |
| 97 | + } |
| 98 | + |
| 99 | +} |
0 commit comments