errors = null; $this->_id = $accessKeyId; $this->_secretKey = $secretAccessKey; } /** * @see http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/ItemSearch.html */ public function searchItems($searchIndex) { $this->addParam('Operation', 'ItemSearch'); $this->addParam('SearchIndex', $searchIndex); return $this->_sendRequest(); } public function lookUpItem($itemId) { $this->addParam('Operation', 'ItemLookup'); $this->addParam('ItemId', $itemId); $xml = $this->_sendRequest(); return $xml->Item; } /** * @see http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/rest-signature.html */ private function _sendRequest() { $this->addParam('Service', 'AWSECommerceService'); $this->addParam('AWSAccessKeyId', $this->_id); $this->addParam('Version', $this->apiVersion); $this->addParam('Timestamp', gmdate('Y-m-d\TH:i:s\Z')); ksort($this->_params); //暗号化する文字列を作る $parsed = parse_url($this->url); $src = "GET\n"; $src .= $parsed['host'] . "\n"; $src .= $parsed['path'] . "\n"; //RFC 3986のURLエンコードに合わせる $src .= strtr($this->_arr2qs('UTF-8'), array('%7E' => '~', '+' => '%20')); //署名を作る $hash = hash_hmac('sha256', $src, $this->_secretKey, true); $this->addParam('Signature', base64_encode($hash)); $xml = parent::request($this->url); if ($xml->Items->Request->IsValid == 'False') { $this->errors = $xml->Items->Request->Errors; $this->status = 2000; throw new Exception('リクエストに誤りがあります'); } return $xml->Items; } }