質問編集履歴
3
無駄な部分を省略
test
CHANGED
File without changes
|
test
CHANGED
@@ -88,222 +88,6 @@
|
|
88
88
|
|
89
89
|
|
90
90
|
|
91
|
-
```PHP
|
92
|
-
|
93
|
-
<?php
|
94
|
-
|
95
|
-
/**
|
96
|
-
|
97
|
-
* Amazon検索クラス
|
98
|
-
|
99
|
-
*
|
100
|
-
|
101
|
-
*
|
102
|
-
|
103
|
-
*/
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
App::uses('Model', 'Model');
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
class Amazon extends Model {
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
//メンバ変数
|
118
|
-
|
119
|
-
private $associate_tag = "";
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
private $aws_access_key_id = "";
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
private $aws_secret_key = "";
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
public $params = array();
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
//コンストラクタ
|
136
|
-
|
137
|
-
public function __construct()
|
138
|
-
|
139
|
-
{
|
140
|
-
|
141
|
-
$this->params = array(
|
142
|
-
|
143
|
-
"Service" => "AWSECommerceService",
|
144
|
-
|
145
|
-
"Operation" => "ItemSearch",
|
146
|
-
|
147
|
-
"AWSAccessKeyId" => $this->aws_access_key_id,
|
148
|
-
|
149
|
-
"AssociateTag" => $this->associate_tag,
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
"SearchIndex" => "",
|
154
|
-
|
155
|
-
"ResponseGroup" => "",
|
156
|
-
|
157
|
-
"Sort" => "",
|
158
|
-
|
159
|
-
"Keywords" => ""
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
);
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
}
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
public function getUrl()
|
180
|
-
|
181
|
-
{
|
182
|
-
|
183
|
-
$endpoint = "webservices.amazon.co.jp";
|
184
|
-
|
185
|
-
$uri = "/onca/xml";
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
// Set current timestamp if not set
|
190
|
-
|
191
|
-
if (!isset($this->params["Timestamp"])) {
|
192
|
-
|
193
|
-
$this->params["Timestamp"] = gmdate('Y-m-d\TH:i:s\Z');
|
194
|
-
|
195
|
-
}
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
// Sort the parameters by key
|
200
|
-
|
201
|
-
ksort($this->params);
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
$pairs = array();
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
foreach ($this->params as $key => $value) {
|
210
|
-
|
211
|
-
array_push($pairs, rawurlencode($key)."=".rawurlencode($value));
|
212
|
-
|
213
|
-
}
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
// Generate the canonical query
|
218
|
-
|
219
|
-
$canonical_query_string = join("&", $pairs);
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
// Generate the string to be signed
|
224
|
-
|
225
|
-
$string_to_sign = "GET\n".$endpoint."\n".$uri."\n".$canonical_query_string;
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
// Generate the signature required by the Product Advertising API
|
230
|
-
|
231
|
-
$signature = base64_encode(hash_hmac("sha256", $string_to_sign, $this->aws_secret_key, true));
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
// Generate the signed URL
|
236
|
-
|
237
|
-
$request_url = 'http://'.$endpoint.$uri.'?'.$canonical_query_string.'&Signature='.rawurlencode($signature);
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
//echo "Signed URL: \"".$request_url."\"";
|
242
|
-
|
243
|
-
//echo "<a href=\"" . $request_url . "\" target=\"_blank\">結果</a>";
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
return $request_url;
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
}
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
// APIリクエスト
|
268
|
-
|
269
|
-
public function request($url){
|
270
|
-
|
271
|
-
$ch = curl_init();
|
272
|
-
|
273
|
-
curl_setopt($ch, CURLOPT_URL, $url);
|
274
|
-
|
275
|
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
276
|
-
|
277
|
-
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
278
|
-
|
279
|
-
$response = curl_exec($ch);
|
280
|
-
|
281
|
-
curl_close($ch);
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
return simplexml_load_string($response);
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
}
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
```
|
306
|
-
|
307
91
|
|
308
92
|
|
309
93
|
XMLから配列に変換する方法が間違っているでしょうか?
|
@@ -318,6 +102,8 @@
|
|
318
102
|
|
319
103
|
|
320
104
|
|
105
|
+
cakePHPのバージョンは2.xです。
|
106
|
+
|
321
107
|
|
322
108
|
|
323
109
|
以上、分かる方居ましたらアドバイス宜しくお願い致します。
|
2
アマゾンクラス追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -80,7 +80,229 @@
|
|
80
80
|
|
81
81
|
|
82
82
|
|
83
|
-
|
83
|
+
上記は、$this->amazonのアマゾンクラスは省略してました。追記します。
|
84
|
+
|
85
|
+
以下を参考にしました
|
86
|
+
|
87
|
+
http://blog.codebook-10000.com/entry/20131112/1384191896
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
```PHP
|
92
|
+
|
93
|
+
<?php
|
94
|
+
|
95
|
+
/**
|
96
|
+
|
97
|
+
* Amazon検索クラス
|
98
|
+
|
99
|
+
*
|
100
|
+
|
101
|
+
*
|
102
|
+
|
103
|
+
*/
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
App::uses('Model', 'Model');
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
class Amazon extends Model {
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
//メンバ変数
|
118
|
+
|
119
|
+
private $associate_tag = "";
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
private $aws_access_key_id = "";
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
private $aws_secret_key = "";
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
public $params = array();
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
//コンストラクタ
|
136
|
+
|
137
|
+
public function __construct()
|
138
|
+
|
139
|
+
{
|
140
|
+
|
141
|
+
$this->params = array(
|
142
|
+
|
143
|
+
"Service" => "AWSECommerceService",
|
144
|
+
|
145
|
+
"Operation" => "ItemSearch",
|
146
|
+
|
147
|
+
"AWSAccessKeyId" => $this->aws_access_key_id,
|
148
|
+
|
149
|
+
"AssociateTag" => $this->associate_tag,
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
"SearchIndex" => "",
|
154
|
+
|
155
|
+
"ResponseGroup" => "",
|
156
|
+
|
157
|
+
"Sort" => "",
|
158
|
+
|
159
|
+
"Keywords" => ""
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
);
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
public function getUrl()
|
180
|
+
|
181
|
+
{
|
182
|
+
|
183
|
+
$endpoint = "webservices.amazon.co.jp";
|
184
|
+
|
185
|
+
$uri = "/onca/xml";
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
// Set current timestamp if not set
|
190
|
+
|
191
|
+
if (!isset($this->params["Timestamp"])) {
|
192
|
+
|
193
|
+
$this->params["Timestamp"] = gmdate('Y-m-d\TH:i:s\Z');
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
// Sort the parameters by key
|
200
|
+
|
201
|
+
ksort($this->params);
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
$pairs = array();
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
foreach ($this->params as $key => $value) {
|
210
|
+
|
211
|
+
array_push($pairs, rawurlencode($key)."=".rawurlencode($value));
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
// Generate the canonical query
|
218
|
+
|
219
|
+
$canonical_query_string = join("&", $pairs);
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
// Generate the string to be signed
|
224
|
+
|
225
|
+
$string_to_sign = "GET\n".$endpoint."\n".$uri."\n".$canonical_query_string;
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
// Generate the signature required by the Product Advertising API
|
230
|
+
|
231
|
+
$signature = base64_encode(hash_hmac("sha256", $string_to_sign, $this->aws_secret_key, true));
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
// Generate the signed URL
|
236
|
+
|
237
|
+
$request_url = 'http://'.$endpoint.$uri.'?'.$canonical_query_string.'&Signature='.rawurlencode($signature);
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
//echo "Signed URL: \"".$request_url."\"";
|
242
|
+
|
243
|
+
//echo "<a href=\"" . $request_url . "\" target=\"_blank\">結果</a>";
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
return $request_url;
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
// APIリクエスト
|
268
|
+
|
269
|
+
public function request($url){
|
270
|
+
|
271
|
+
$ch = curl_init();
|
272
|
+
|
273
|
+
curl_setopt($ch, CURLOPT_URL, $url);
|
274
|
+
|
275
|
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
276
|
+
|
277
|
+
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
278
|
+
|
279
|
+
$response = curl_exec($ch);
|
280
|
+
|
281
|
+
curl_close($ch);
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
return simplexml_load_string($response);
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
```
|
84
306
|
|
85
307
|
|
86
308
|
|
1
補足
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,9 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
受け取った結果(XML)を、一覧画面(cakePHPのPaginator)に出力しようと思いました。
|
9
|
+
受け取った結果(XMLデータ)を、一覧画面(cakePHPのPaginator)に出力しようと思いました。
|
10
|
+
|
11
|
+
※XMLはファイルではなく、データです。
|
10
12
|
|
11
13
|
|
12
14
|
|