ChenJiaHe
2020-12-12 8bc3c99b8afeb76573bafa7a7ec51b551f500662
src/main/java/com/hx/util/HttpUtil.java
@@ -6,6 +6,8 @@
import org.springframework.web.multipart.MultipartFile;
import javax.activation.MimetypesFileTypeMap;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
@@ -23,6 +25,27 @@
    /**回车换行,用于一行的结尾*/
    private static final String LINE_END = "\r\n";
    public static String getInputStream(HttpServletRequest request) throws Exception {
        ServletInputStream stream = null;
        BufferedReader reader = null;
        StringBuffer sb = new StringBuffer();
        try {
            stream = request.getInputStream();
            // 获取响应
            reader = new BufferedReader(new InputStreamReader(stream));
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
        } catch (IOException e) {
            //logger.error(e);
            throw new RuntimeException("读取返回支付接口数据流出现异常!");
        } finally {
            reader.close();
        }
        //logger.info("输入流返回的内容:" + sb.toString());
        return sb.toString();
    }
    public static String post(String requestUrl, String accessToken, String params)
            throws Exception {
@@ -162,13 +185,6 @@
            // //System.out.println("HttpURLUtil:"+wxMsgXml);
        } catch (Exception e) {
            e.printStackTrace();
            obj = new JSONObject();
            try {
                obj.put("status", 1);
                obj.put("errMsg", e.getMessage());
            } catch (JSONException e1) {
                e1.printStackTrace();
            }
        } finally {
            if (con != null) {
                con.disconnect();