7.1
15832144755
2021-07-01 ba21fcf8482029f7634b62d60daf171538001769
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
package com.hxzkoa.util;
 
import java.io.IOException;
 
import javax.servlet.http.HttpServletRequest;
 
import net.sf.json.JSONObject;
 
public class RequestUtils {
 
    public static String getRequestJsonString(HttpServletRequest request,
            String charset) throws IOException {
        String submitMehtod = request.getMethod();
        if (submitMehtod.equals("GET")) {
            return new String(request.getQueryString().getBytes("UTF-8"), charset)
                    .replaceAll("%22", "\"");
        } else {
            byte buffer[] = getRequestPostBytes(request);
            return new String(buffer, charset);
        }
    }
 
    public static byte[] getRequestPostBytes(HttpServletRequest request)
            throws IOException {
        int contentLength = request.getContentLength();
        if (contentLength < 0) {
            return null;
        }
        byte buffer[] = new byte[contentLength];
        for (int i = 0; i < contentLength;) {
 
            int readlen = request.getInputStream().read(buffer, i,
                    contentLength - i);
            if (readlen == -1) {
                break;
            }
            i += readlen;
        }
        return buffer;
    }
 
    /**
     * 使用统一的返回结果
     * 
     * @param Status
     *            返回结果状态 1.成功 0. 失败
     * @param Message
     *            返回结果描述信息
     * @param ErrorCode
     *            返回结果错误代码
     * @param Data
     *            数据结果,无返回则为null
     * @return
     */
    public static JSONObject returnJson(String status, String message,
            String errorCode, String data) {
        JSONObject reJson = new JSONObject();
        reJson.put("Status", status);
        reJson.put("Message", message);
        reJson.put("ErrorCode", errorCode);
        reJson.put("Describe", data);
        return reJson;
    }
}