10 | */
11 | public class Tmt extends Base {
12 | public Tmt() {
13 | serverHost = "tmt.api.qcloud.com";
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/qcloud/Module/Trade.java:
--------------------------------------------------------------------------------
1 | package com.qcloud.Module;
2 |
3 | public class Trade extends Base {
4 | public Trade(){
5 | serverHost = "trade.api.qcloud.com";
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/qcloud/Module/Vod.java:
--------------------------------------------------------------------------------
1 | package com.qcloud.Module;
2 |
3 | public class Vod extends Base {
4 | public Vod(){
5 | serverHost = "vod.api.qcloud.com";
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/qcloud/Module/Vpc.java:
--------------------------------------------------------------------------------
1 | package com.qcloud.Module;
2 |
3 | public class Vpc extends Base {
4 | public Vpc(){
5 | serverHost = "vpc.api.qcloud.com";
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/qcloud/Module/Wenzhi.java:
--------------------------------------------------------------------------------
1 | package com.qcloud.Module;
2 |
3 | public class Wenzhi extends Base {
4 | public Wenzhi(){
5 | serverHost = "wenzhi.api.qcloud.com";
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/qcloud/Module/Yunsou.java:
--------------------------------------------------------------------------------
1 | package com.qcloud.Module;
2 |
3 | public class Yunsou extends Base {
4 | public Yunsou(){
5 | serverHost = "yunsou.api.qcloud.com";
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/qcloud/QcloudApiModuleCenter.java:
--------------------------------------------------------------------------------
1 | package com.qcloud;
2 |
3 | import java.lang.reflect.Method;
4 | import java.util.TreeMap;
5 |
6 | import com.qcloud.Module.Base;
7 |
8 | /**
9 | * 模块调用类
10 | * @author robinslsun
11 | *
12 | */
13 | public class QcloudApiModuleCenter {
14 |
15 | private Base module;
16 |
17 | /**
18 | * 构造模块调用类
19 | * @param module 实际模块实例
20 | * @param config 模块配置参数
21 | */
22 | public QcloudApiModuleCenter(Base module, TreeMap config){
23 | this.module = module;
24 | this.module.setConfig(config);
25 | }
26 |
27 | /**
28 | * 生成Api调用地址。
29 | * 仅支持GET方法,POST方法仅返回host+path信息,不支持utf8编码的机器上仅返回host+path信息。
30 | * @param actionName 模块动作名称
31 | * @param params 模块请求参数
32 | * @return Api调用地址
33 | */
34 | public String generateUrl(String actionName, TreeMap params){
35 | return module.generateUrl(actionName, params);
36 | }
37 |
38 | /**
39 | * Api调用
40 | * @param actionName 模块动作名称
41 | * @param params 模块请求参数
42 | * @return json字符串
43 | * @throws Exception
44 | */
45 | public String call(String actionName, TreeMap params) throws Exception
46 | {
47 | for(Method method : module.getClass().getMethods()){
48 | if(method.getName().equals(actionName)){
49 | try {
50 | return (String) method.invoke(module, params);
51 | } catch (Exception e) {
52 | throw e;
53 | }
54 | }
55 | }
56 | return module.call(actionName, params);
57 | }
58 |
59 | public void setConfigSecretId(String secretId) {
60 | module.setConfigSecretId(secretId);
61 | }
62 |
63 | public void setConfigSecretKey(String secretKey) {
64 | module.setConfigSecretKey(secretKey);
65 | }
66 |
67 | public void setConfigDefaultRegion(String region) {
68 | module.setConfigDefaultRegion(region);
69 | }
70 |
71 | public void setConfigRequestMethod(String method) {
72 | module.setConfigRequestMethod(method);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/com/qcloud/Utilities/Base64.java:
--------------------------------------------------------------------------------
1 | package com.qcloud.Utilities;
2 |
3 | import java.io.UnsupportedEncodingException;
4 |
5 | public class Base64 {
6 | private static char[] base64EncodeChars = new char[] { 'A', 'B', 'C', 'D',
7 | 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
8 | 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
9 | 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
10 | 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
11 | '4', '5', '6', '7', '8', '9', '+', '/' };
12 |
13 | private static byte[] base64DecodeChars = new byte[] { -1, -1, -1, -1, -1,
14 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
15 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
16 | -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59,
17 | 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
18 | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1,
19 | -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
20 | 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1,
21 | -1, -1 };
22 |
23 | public static String encode(byte[] data) {
24 | StringBuffer sb = new StringBuffer();
25 | int len = data.length;
26 | int i = 0;
27 | int b1, b2, b3;
28 | while (i < len) {
29 | b1 = data[i++] & 0xff;
30 | if (i == len) {
31 | sb.append(base64EncodeChars[b1 >>> 2]);
32 | sb.append(base64EncodeChars[(b1 & 0x3) << 4]);
33 | sb.append("==");
34 | break;
35 | }
36 | b2 = data[i++] & 0xff;
37 | if (i == len) {
38 | sb.append(base64EncodeChars[b1 >>> 2]);
39 | sb.append(base64EncodeChars[((b1 & 0x03) << 4)
40 | | ((b2 & 0xf0) >>> 4)]);
41 | sb.append(base64EncodeChars[(b2 & 0x0f) << 2]);
42 | sb.append("=");
43 | break;
44 | }
45 | b3 = data[i++] & 0xff;
46 | sb.append(base64EncodeChars[b1 >>> 2]);
47 | sb.append(base64EncodeChars[((b1 & 0x03) << 4)
48 | | ((b2 & 0xf0) >>> 4)]);
49 | sb.append(base64EncodeChars[((b2 & 0x0f) << 2)
50 | | ((b3 & 0xc0) >>> 6)]);
51 | sb.append(base64EncodeChars[b3 & 0x3f]);
52 | }
53 | return sb.toString();
54 | }
55 |
56 | public static byte[] decode(String str) throws UnsupportedEncodingException {
57 | StringBuffer sb = new StringBuffer();
58 | byte[] data = str.getBytes("US-ASCII");
59 | int len = data.length;
60 | int i = 0;
61 | int b1, b2, b3, b4;
62 | while (i < len) {
63 | /* b1 */
64 | do {
65 | b1 = base64DecodeChars[data[i++]];
66 | } while (i < len && b1 == -1);
67 | if (b1 == -1)
68 | break;
69 | /* b2 */
70 | do {
71 | b2 = base64DecodeChars[data[i++]];
72 | } while (i < len && b2 == -1);
73 | if (b2 == -1)
74 | break;
75 | sb.append((char) ((b1 << 2) | ((b2 & 0x30) >>> 4)));
76 | /* b3 */
77 | do {
78 | b3 = data[i++];
79 | if (b3 == 61)
80 | return sb.toString().getBytes("ISO-8859-1");
81 | b3 = base64DecodeChars[b3];
82 | } while (i < len && b3 == -1);
83 | if (b3 == -1)
84 | break;
85 | sb.append((char) (((b2 & 0x0f) << 4) | ((b3 & 0x3c) >>> 2)));
86 | /* b4 */
87 | do {
88 | b4 = data[i++];
89 | if (b4 == 61)
90 | return sb.toString().getBytes("ISO-8859-1");
91 | b4 = base64DecodeChars[b4];
92 | } while (i < len && b4 == -1);
93 | if (b4 == -1)
94 | break;
95 | sb.append((char) (((b3 & 0x03) << 6) | b4));
96 | }
97 | return sb.toString().getBytes("ISO-8859-1");
98 | }
99 | }
--------------------------------------------------------------------------------
/src/main/java/com/qcloud/Utilities/Json/JSONArray.java:
--------------------------------------------------------------------------------
1 | package com.qcloud.Utilities.Json;
2 |
3 | /*
4 | Copyright (c) 2002 JSON.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | The Software shall be used for Good, not Evil.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | SOFTWARE.
25 | */
26 |
27 | import java.io.IOException;
28 | import java.io.StringWriter;
29 | import java.io.Writer;
30 | import java.lang.reflect.Array;
31 | import java.util.ArrayList;
32 | import java.util.Collection;
33 | import java.util.Iterator;
34 | import java.util.Map;
35 |
36 | /**
37 | * A JSONArray is an ordered sequence of values. Its external text form is a
38 | * string wrapped in square brackets with commas separating the values. The
39 | * internal form is an object having get and opt
40 | * methods for accessing the values by index, and put methods for
41 | * adding or replacing values. The values can be any of these types:
42 | * Boolean, JSONArray, JSONObject,
43 | * Number, String, or the
44 | * JSONObject.NULL object.
45 | *
46 | * The constructor can convert a JSON text into a Java object. The
47 | * toString method converts to JSON text.
48 | *
49 | * A get method returns a value if one can be found, and throws an
50 | * exception if one cannot be found. An opt method returns a
51 | * default value instead of throwing an exception, and so is useful for
52 | * obtaining optional values.
53 | *
54 | * The generic get() and opt() methods return an
55 | * object which you can cast or query for type. There are also typed
56 | * get and opt methods that do type checking and type
57 | * coercion for you.
58 | *
59 | * The texts produced by the toString methods strictly conform to
60 | * JSON syntax rules. The constructors are more forgiving in the texts they will
61 | * accept:
62 | *
63 | *
An extra , (comma) may appear just
64 | * before the closing bracket.
65 | *
The null value will be inserted when there is ,
66 | * (comma) elision.
67 | *
Strings may be quoted with ' (single
68 | * quote).
69 | *
Strings do not need to be quoted at all if they do not begin with a quote
70 | * or single quote, and if they do not contain leading or trailing spaces, and
71 | * if they do not contain any of these characters:
72 | * { } [ ] / \ : , # and if they do not look like numbers and
73 | * if they are not the reserved words true, false, or
74 | * null.
75 | *
76 | *
77 | * @author JSON.org
78 | * @version 2014-05-03
79 | */
80 | public class JSONArray {
81 |
82 | /**
83 | * The arrayList where the JSONArray's properties are kept.
84 | */
85 | private final ArrayList