-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPIResponse.java
More file actions
88 lines (67 loc) · 2.02 KB
/
APIResponse.java
File metadata and controls
88 lines (67 loc) · 2.02 KB
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
81
82
83
84
85
86
87
88
package com.edward.http;
import java.util.HashMap;
import java.util.Map;
public class APIResponse {
private int code;
private String message;
private Object result;
public APIResponse(){}
public APIResponse(int code, Object result, String appPrivateKey){
this.code = code;
this.result = result;
}
public APIResponse(int code, Object result){
this.code = code;
this.result = result;
}
public APIResponse(int code){
this.code = code;
this.result = null;
}
public Object getResult(){
return this.result;
}
public void setResult(Object result){
this.result = result;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
/** 操作成功 */
public static final int RC_SUCCESS = 0;
public static final int RC_OK = RC_SUCCESS;
/** 程序内部错误 */
public static final int RC_INTERNAL_ERROR = 10099;
/**参数不为数字 */
public static final int RC_NOT_NUMBER = 10012;
public static final int RC_REQUEST_FAIL = 10022;
/**
* 请求参数不合法或者有问题
*/
public static final int RC_BAD_REQUEST = 10100;
///messages
private static Map<Integer, String> messages = null;
public static String getMessage(int code){
if(messages == null){
messages = new HashMap<Integer, String>();
messages.put(RC_USER_NOT_EXSIST, "用户不存在");
messages.put(RC_ORDER_EXPIRED, "订单已过期");
messages.put(RC_INTERNAL_ERROR, "程序错误");
messages.put(RC_NOT_NUMBER, "参数值不能转为数字");
messages.put(RC_BAD_REQUEST , "请求不合法");
messages.put(RC_SUCCESS, "成功");
messages.put(RC_REQUEST_FAIL, "很抱歉,您的访问出错了");
}
String message = messages.get(code);
return message == null ? "指定的错误码不存在" : message;
}
}