1 | <?php |
---|
2 | /* |
---|
3 | * APIの動作確認・検証用プログラム |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved. |
---|
6 | * |
---|
7 | * http://www.lockon.co.jp/ |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or |
---|
10 | * modify it under the terms of the GNU General Public License |
---|
11 | * as published by the Free Software Foundation; either version 2 |
---|
12 | * of the License, or (at your option) any later version. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this program; if not, write to the Free Software |
---|
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | /** |
---|
25 | * APIの動作確認・検証用プログラム |
---|
26 | * MEMO:本プログラム自体は、EC-CUBE側には一切依存しませんので、クリアな環境でテスト出来る簡易プログラムです。 |
---|
27 | * 初期化や入力チェックを省いている為、display_errorsを強制的にOffにしています。 |
---|
28 | * |
---|
29 | * @package Test |
---|
30 | * @author Spirit of Co.,Ltd. |
---|
31 | * @version $Id$ |
---|
32 | */ |
---|
33 | ini_set('display_errors', 'Off'); |
---|
34 | if($_REQUEST['EndPoint'] && $_REQUEST['Service'] && $_REQUEST['Operation']) { |
---|
35 | $url = "{$_REQUEST['EndPoint']}{$_REQUEST['type']}?Service={$_REQUEST['Service']}&Operation={$_REQUEST['Operation']}"; |
---|
36 | for($i =0; $i <10; $i++) { |
---|
37 | if($_REQUEST['arg_key' . $i] != "") { |
---|
38 | $url .= '&' . $_REQUEST['arg_key' . $i] . '=' . $_REQUEST['arg_val' . $i]; |
---|
39 | } |
---|
40 | } |
---|
41 | if($_REQUEST['mode'] == 'signature') { |
---|
42 | $arrParam = array(); |
---|
43 | if($_REQUEST['Timestamp'] == '') { |
---|
44 | $arrParam['Timestamp'] = date('Y-m-d') . 'T' . date('h:i:s') .'Z'; |
---|
45 | }else{ |
---|
46 | $arrParam['Timestamp'] = $_REQUEST['Timestamp']; |
---|
47 | } |
---|
48 | $arrParam['AccessKeyId'] = $_REQUEST['AccessKeyId']; |
---|
49 | |
---|
50 | $arrParam['Service'] = $_REQUEST['Service']; |
---|
51 | $arrParam['Operation'] = $_REQUEST['Operation']; |
---|
52 | for($i =0; $i <10; $i++) { |
---|
53 | if($_REQUEST['arg_key' . $i] != "") { |
---|
54 | $arrParam[ $_REQUEST['arg_key' . $i] ] = $_REQUEST['arg_val' . $i]; |
---|
55 | } |
---|
56 | } |
---|
57 | ksort($arrParam); |
---|
58 | $check_str = ''; |
---|
59 | foreach($arrParam as $key => $val) { |
---|
60 | if($val != "") { |
---|
61 | $check_str .= '&' . str_replace('%7E', '~', rawurlencode($key)) . '=' . str_replace('%7E', '~', rawurlencode($val)); |
---|
62 | } |
---|
63 | } |
---|
64 | $check_str = substr($check_str,1); |
---|
65 | $arrParseUrl = parse_url($_REQUEST['EndPoint'] . $_REQUEST['type']); |
---|
66 | $check_str = "GET\n" . $arrParseUrl['host'] . "\n" . $arrParseUrl['path'] . "\n" . $check_str; |
---|
67 | $_REQUEST['Signature'] = base64_encode(hash_hmac('sha256', $check_str, $_REQUEST['SecretKey'], true)); |
---|
68 | } |
---|
69 | if($_REQUEST['mode'] != 'signature') { |
---|
70 | if($_REQUEST['Signature'] != "") { |
---|
71 | $signature = urlencode($_REQUEST['Signature']); |
---|
72 | $url .= "&AccessKeyId={$_REQUEST['AccessKeyId']}&Timestamp={$_REQUEST['Timestamp']}&Signature={$signature}"; |
---|
73 | } |
---|
74 | $response = file_get_contents($url); |
---|
75 | } |
---|
76 | } |
---|
77 | $type = $_REQUEST['type']; |
---|
78 | ?> |
---|
79 | <html> |
---|
80 | <head> |
---|
81 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
---|
82 | <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> |
---|
83 | <script type="text/javascript"> |
---|
84 | function var_dump(obj) { |
---|
85 | var str = ''; |
---|
86 | $.each(obj, function (key, value) { |
---|
87 | if(typeof value == "object" && value != null) { |
---|
88 | str += " Key: \"" + key + "\" {\n" + var_dump(value) + "}\n"; |
---|
89 | }else{ |
---|
90 | str += " Key: \"" + key + "\" Type: " + typeof(value) + " Value: \"" + value + "\""; |
---|
91 | } |
---|
92 | }); |
---|
93 | return str; |
---|
94 | } |
---|
95 | |
---|
96 | function makeSignature() { |
---|
97 | $('#mode').val("signature"); |
---|
98 | $('#form').submit(); |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | </script> |
---|
103 | </head> |
---|
104 | <body> |
---|
105 | EC-CUBE API TEST<br /> |
---|
106 | ※このプログラムにはセキュリティ考慮が一切されていませんので取り扱いには注意をして下さい。 |
---|
107 | <hr /> |
---|
108 | <form action="?" method="POST" id="form"> |
---|
109 | <input type="hidden" name="mode" id="mode" value="" /> |
---|
110 | EndPoint:<input type="text" name="EndPoint" style="width:400px;" value="<?php echo htmlspecialchars($_REQUEST['EndPoint']); ?>" /><select name="type"> |
---|
111 | <option value="json.php" <?php if($type =='json.php'){ echo 'selected';} ?>>json.php</option> |
---|
112 | <option value="xml.php" <?php if($type =='xml.php'){ echo 'selected';} ?>>xml.php</option> |
---|
113 | <option value="php.php" <?php if($type =='php.php'){ echo 'selected';} ?>>php.php</option> |
---|
114 | <option value="index.php" <?php if($type =='index.php'){ echo 'selected';} ?>>index.php</option> |
---|
115 | </select><br /> |
---|
116 | Service:<input type="text" name="Service" value="<?php echo htmlspecialchars($_REQUEST['Service']); ?>" /><br /> |
---|
117 | Operation:<input type="text" name="Operation" value="<?php echo htmlspecialchars($_REQUEST['Operation']); ?>" /><br /> |
---|
118 | <?php |
---|
119 | for ($i = 0; $i < 10; $i++) { |
---|
120 | echo 'ExtArg[' . $i . ']:<input type="text" name="arg_key' . $i . '" value="' . htmlspecialchars($_REQUEST['arg_key' . $i]) . '" />:' |
---|
121 | . '<input type="text" name="arg_val' . $i . '" value="' . htmlspecialchars($_REQUEST['arg_val' . $i]) . '" /><br />'; |
---|
122 | } |
---|
123 | ?> |
---|
124 | AccessKeyId: <input type="text" name="AccessKeyId" value="<?php echo htmlspecialchars($_REQUEST['AccessKeyId']); ?>" /> |
---|
125 | SecretKey: <input type="text" name="SecretKey" value="<?php echo htmlspecialchars($_REQUEST['SecretKey']); ?>" /> <br /> |
---|
126 | <input type="button" value="Signature生成⇒" onclick="makeSignature();" /> |
---|
127 | Timestamp: <input type="text" name="Timestamp" value="<?php echo htmlspecialchars($_REQUEST['Timestamp']); ?>" /> Signature: <input type="text" name="Signature" id="Signature" value="<?php echo htmlspecialchars($_REQUEST['Signature']); ?>" readonly /><br /> |
---|
128 | <?php if($check_str != "") { |
---|
129 | echo "<pre>{$check_str}</pre><br />"; |
---|
130 | } ?> |
---|
131 | <input type="submit" /> |
---|
132 | </form> |
---|
133 | <hr /> |
---|
134 | REST URI: <a href="<?php echo $url;?>">Link</a><br /> |
---|
135 | <textarea rows="1" cols="60"><?php echo htmlspecialchars($url);?></textarea> |
---|
136 | <hr /> |
---|
137 | Response:<br /> |
---|
138 | <textarea rows="5" cols="100"> |
---|
139 | <?php echo htmlspecialchars($response);?> |
---|
140 | </textarea> |
---|
141 | </pre> |
---|
142 | <hr /> |
---|
143 | Response decode:<br /> |
---|
144 | <pre> |
---|
145 | <?php |
---|
146 | if($type =="json.php") { |
---|
147 | var_dump(json_decode($response)); |
---|
148 | }else if($type=="xml.php") { |
---|
149 | $xml = simplexml_load_string($response); |
---|
150 | var_dump($xml); |
---|
151 | var_dump(libxml_get_errors () ); |
---|
152 | }else if($type=="php.php") { |
---|
153 | var_dump(unserialize($response)); |
---|
154 | } |
---|
155 | ?> |
---|
156 | </pre> |
---|
157 | <hr /> |
---|
158 | <?php if($type=="json.php" && $_REQUEST['Signature'] == "") {?> |
---|
159 | JavaScript:<div id="res"></div> |
---|
160 | <hr /> |
---|
161 | <pre id="dump"></pre> |
---|
162 | <hr /> |
---|
163 | |
---|
164 | <script type="text/javascript">//<![CDATA[ |
---|
165 | var query_params = { |
---|
166 | Service: '<?php echo $_REQUEST['Service'];?>', |
---|
167 | Operation: '<?php echo $_REQUEST['Operation'];?>' |
---|
168 | <?php |
---|
169 | for($i =0; $i <10; $i++) { |
---|
170 | if($_REQUEST['arg_key' . $i] != "") { |
---|
171 | echo ',' . $_REQUEST['arg_key' . $i] . ': \'' . $_REQUEST['arg_val' . $i] . '\'' . "\n"; |
---|
172 | } |
---|
173 | } |
---|
174 | ?> |
---|
175 | }; |
---|
176 | $(function(){ |
---|
177 | var recvdata = function(data,textstatus) { |
---|
178 | $('#res').text(textstatus); |
---|
179 | var str = var_dump(data); |
---|
180 | $('#dump').text(str); |
---|
181 | } |
---|
182 | var recverror = function (result, textstatus, errorThrown) { |
---|
183 | $('#res').text(textstatus); |
---|
184 | } |
---|
185 | $.ajax({ |
---|
186 | type: "GET", |
---|
187 | url: "<?php echo $_REQUEST['EndPoint'];?>json.php", |
---|
188 | dataType: 'json', |
---|
189 | data: query_params, |
---|
190 | success: recvdata, |
---|
191 | error: recverror |
---|
192 | }); |
---|
193 | }); |
---|
194 | //]]></script> |
---|
195 | <?php } ?> |
---|
196 | |
---|
197 | </body> |
---|
198 | </html> |
---|