source: branches/version-2_12-dev/test/api_test.php @ 21864

Revision 21864, 4.0 KB checked in by h_yoshimoto, 12 years ago (diff)

#1831 Copyrightを更新

Line 
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 */
33ini_set('display_errors', 'Off');
34if($_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">
84function 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
96function makeSignature() {
97    $('#mode').val("signature");
98    $('#form').submit();
99}
100
101
102</script>
103</head>
104<body>
105EC-CUBE API TEST<br />
106※このプログラムに
Note: See TracBrowser for help on using the repository browser.