My favorites
|
Sign in
p2-php-framework
This is an MVC framework and library on PHP.
Project Home
Wiki
Source
Checkout
|
Browse
|
Changes
|
‹r164
r178
Source path:
svn
/
trunk
/
Service
/
Amazon.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* P2_Service_Amazon
*
* require
* * Hash (PHP 5.1.2+)
* * P2_Service_Base
*
* @version 2.2.2
* @see http://code.google.com/p/p2-php-framework/
* @license The MIT license (http://www.opensource.org/licenses/mit-license.php)
*/
class P2_Service_Amazon extends P2_Service_Base {
public $url = 'http://ecs.amazonaws.jp/onca/xml'; //対象は日本のAmazon
public $apiVersion = '2009-03-31';
public $errors;
private $_id;
private $_secretKey;
public static static function getUrl($asin, $trackingId) {
return "http://amazon.jp/o/ASIN/$asin/$trackingId/ref=nosim";
}
public function __construct($accessKeyId, $secretAccessKey) {
parent::__construct();
$this->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;
}
}
Show details
Hide details
Change log
r175
by andozz on Nov 25, 2009
Diff
[No log message]
Go to:
/trunk/Auth.php
/trunk/Cache.php
/trunk/Client.php
/trunk/Controller.php
/trunk/Db.php
/trunk/Feeder.php
/trunk/Feeder2.php
/trunk/Filter.php
/trunk/Form.php
/trunk/Html.php
/trunk/List.php
/trunk/Loader.php
/trunk/Log.php
/trunk/Service/Amazon.php
/trunk/Service/Flickr.php
/trunk/Service/Rakuten.php
/trunk/Service/Twitter.php
/trunk/Service/YahooJp.php
/trunk/Util.php
/trunk/Video.php
/trunk/VideoExt.php
/trunk/Xml.php
/trunk/globalFunctions.php
Project members,
sign in
to write a code review
Older revisions
r164
by andozz on May 27, 2009
Diff
[No log message]
r163
by andozz on May 21, 2009
Diff
[No log message]
r138
by andozz on Jan 28, 2009
Diff
[No log message]
All revisions of this file
File info
Size: 2405 bytes, 80 lines
View raw file
Hosted by