Pārlūkot izejas kodu

删除多余httpUtil

lyhzzz 3 gadi atpakaļ
vecāks
revīzija
cdac2e0d6a

+ 1 - 0
platform-api/src/main/java/com/platform/api/ApiGoodsController.java

@@ -3,6 +3,7 @@ package com.platform.api;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.fdage.micro.commom.utils.HttpClientUtil;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.platform.annotation.IgnoreAuth;

+ 0 - 221
platform-common/src/main/java/com/platform/utils/HttpClientUtil.java

@@ -1,221 +0,0 @@
-package com.platform.utils;
-
-import lombok.extern.slf4j.Slf4j;
-import org.apache.http.HttpEntity;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.utils.URIBuilder;
-import org.apache.http.entity.ContentType;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.entity.mime.HttpMultipartMode;
-import org.apache.http.entity.mime.MultipartEntityBuilder;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.message.BasicNameValuePair;
-import org.apache.http.util.EntityUtils;
-import org.springframework.util.CollectionUtils;
-import org.springframework.web.multipart.MultipartFile;
-
-import java.io.IOException;
-import java.net.URI;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-
-/**
- * @author abnerhou
- * @date 2020/5/11 17:48
- * @desciption
- */
-@Slf4j
-public class HttpClientUtil {
-
-    public static String doGet(String url, Map<String, String> param) {
-
-        // 创建Httpclient对象
-        CloseableHttpClient httpclient = HttpClients.createDefault();
-
-        String resultString = "";
-        CloseableHttpResponse response = null;
-        try {
-            // 创建uri
-            URIBuilder builder = new URIBuilder(url);
-            if (param != null) {
-                for (String key : param.keySet()) {
-                    builder.addParameter(key, param.get(key));
-                }
-            }
-            URI uri = builder.build();
-
-            // 创建http GET请求
-            HttpGet httpGet = new HttpGet(uri);
-
-            // 执行请求
-            response = httpclient.execute(httpGet);
-            // 判断返回状态是否为200
-            if (response.getStatusLine().getStatusCode() == 200) {
-                resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
-            }
-        } catch (Exception e) {
-            log.error("http调用执行get出错:{}" , e);
-        } finally {
-            try {
-                if (response != null) {
-                    response.close();
-                }
-                httpclient.close();
-            } catch (IOException e) {
-               log.error("http调用执行get关闭资源出错:{}" , e);
-            }
-        }
-        return resultString;
-    }
-
-    public static String doGet(String url) {
-        return doGet(url, null);
-    }
-
-    public static String doPost(String url, Map<String, String> param) {
-        // 创建Httpclient对象
-        CloseableHttpClient httpClient = HttpClients.createDefault();
-        CloseableHttpResponse response = null;
-        String resultString = "";
-        try {
-            // 创建Http Post请求
-            HttpPost httpPost = new HttpPost(url);
-            // 创建参数列表
-            if (param != null) {
-                List<NameValuePair> paramList = new ArrayList<>();
-                for (String key : param.keySet()) {
-                    paramList.add(new BasicNameValuePair(key, param.get(key)));
-                }
-                // 模拟表单
-                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList);
-                httpPost.setEntity(entity);
-            }
-            // 执行http请求
-            response = httpClient.execute(httpPost);
-            resultString = EntityUtils.toString(response.getEntity(), "utf-8");
-        } catch (Exception e) {
-            log.error("http执行post调用出错:{}" , e);
-        } finally {
-            try {
-                if(null != response){
-                    response.close();
-                }
-            } catch (IOException e) {
-                log.error("http执行post调用关闭资源出错:{}" , e);
-            }
-        }
-
-        return resultString;
-    }
-
-    public static String doPost(String url) {
-        return doPost(url, null);
-    }
-
-    public static String doPostMultipartFileWithForm(String url, MultipartFile file){
-        // 创建Httpclient对象
-        CloseableHttpClient httpClient = HttpClients.createDefault();
-        CloseableHttpResponse response = null;
-        String resultString = "";
-        try {
-            // 创建Http Post请求
-            HttpPost httpPost = new HttpPost(url);
-
-            //处理文件 后面的setMode是用来解决文件名称乱码的问题:以浏览器兼容模式运行,防止文件名乱码。
-            MultipartEntityBuilder builder = MultipartEntityBuilder.create().setMode(HttpMultipartMode.STRICT);
-            builder.setCharset(Charset.forName("UTF-8")).addBinaryBody("media", file.getBytes(), ContentType.MULTIPART_FORM_DATA, file.getOriginalFilename());
-            // 创建请求内容
-            HttpEntity httpEntity = builder.build();
-            httpPost.setEntity(httpEntity);
-            // 执行http请求
-            response = httpClient.execute(httpPost);
-            resultString = EntityUtils.toString(response.getEntity(), "utf-8");
-        } catch (Exception e) {
-            log.error("http执行post调用出错:{}" , e);
-        } finally {
-            try {
-                if(null != response){
-                    response.close();
-                }
-            } catch (IOException e) {
-                log.error("http执行post调用关闭资源出错:{}" , e);
-            }
-        }
-
-        return resultString;
-
-    }
-
-    public static String doPostJson(String url, String json) {
-        // 创建Httpclient对象
-        CloseableHttpClient httpClient = HttpClients.createDefault();
-        CloseableHttpResponse response = null;
-        String resultString = "";
-        try {
-            // 创建Http Post请求
-            HttpPost httpPost = new HttpPost(url);
-            // 创建请求内容
-            StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
-            httpPost.setEntity(entity);
-            // 执行http请求
-            response = httpClient.execute(httpPost);
-            resultString = EntityUtils.toString(response.getEntity(), "utf-8");
-        } catch (Exception e) {
-            log.error("http执行post调用出错:{}" , e);
-        } finally {
-            try {
-                if(null != response){
-                    response.close();
-                }
-            } catch (IOException e) {
-                log.error("http执行post调用关闭资源出错:{}" , e);
-            }
-        }
-
-        return resultString;
-    }
-
-    public static String doPostJsonWithHeader(String url, String json ,Map<String, Object> headers) {
-        // 创建Httpclient对象
-        CloseableHttpClient httpClient = HttpClients.createDefault();
-        CloseableHttpResponse response = null;
-        String resultString = "";
-        try {
-            // 创建Http Post请求
-            HttpPost httpPost = new HttpPost(url);
-            // 创建请求内容
-            StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
-            httpPost.setEntity(entity);
-
-            if(!CollectionUtils.isEmpty(headers)){
-                for (Map.Entry<String,Object> entry : headers.entrySet()){
-                    httpPost.addHeader(entry.getKey() , (String) entry.getValue());
-                }
-            }
-            // 执行http请求
-            response = httpClient.execute(httpPost);
-            resultString = EntityUtils.toString(response.getEntity(), "utf-8");
-        } catch (Exception e) {
-            log.error("http执行post调用出错:{}" , e);
-        } finally {
-            try {
-                if(null != response){
-                    response.close();
-                }
-            } catch (IOException e) {
-                log.error("http执行post调用关闭资源出错:{}" , e);
-            }
-        }
-
-        return resultString;
-    }
-
-}

+ 0 - 339
platform-common/src/main/java/com/platform/utils/HttpUtil.java

@@ -1,339 +0,0 @@
-package com.platform.utils;
-
-import org.apache.commons.httpclient.*;
-import org.apache.commons.httpclient.cookie.CookiePolicy;
-import org.apache.commons.httpclient.cookie.CookieSpec;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.log4j.Logger;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URLEncoder;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * 作者: @author Harmon <br>
- * 时间: 2016-09-01 09:18<br>
- * 描述: Http请求通用工具 <br>
- */
-public class HttpUtil {
-
-    // 日志
-    private static final Logger logger = Logger.getLogger(HttpUtil.class);
-    /**
-     * 定义编码格式 UTF-8
-     */
-    public static final String URL_PARAM_DECODECHARSET_UTF8 = "UTF-8";
-
-    /**
-     * 定义编码格式 GBK
-     */
-    public static final String URL_PARAM_DECODECHARSET_GBK = "GBK";
-
-    private static final String URL_PARAM_CONNECT_FLAG = "&";
-
-    private static final String EMPTY = "";
-
-    private static MultiThreadedHttpConnectionManager connectionManager = null;
-
-    private static int connectionTimeOut = 25000;
-
-    private static int socketTimeOut = 25000;
-
-    private static int maxConnectionPerHost = 20;
-
-    private static int maxTotalConnections = 20;
-
-    private static HttpClient client;
-    // 当前登录的人
-    static Cookie[] cookies = null;
-    // 登录URL
-    static String loginURL = "/admin/login.do";
-    // 登录账户
-    static String loginUserName = "admin";
-    static String loginPassword = "admin";
-
-    static {
-        connectionManager = new MultiThreadedHttpConnectionManager();
-        connectionManager.getParams().setConnectionTimeout(connectionTimeOut);
-        connectionManager.getParams().setSoTimeout(socketTimeOut);
-        connectionManager.getParams().setDefaultMaxConnectionsPerHost(maxConnectionPerHost);
-        connectionManager.getParams().setMaxTotalConnections(maxTotalConnections);
-        client = new HttpClient(connectionManager);
-    }
-
-    /**
-     * POST方式提交数据
-     *
-     * @param url    待请求的URL
-     * @param params 要提交的数据
-     * @param enc    编码
-     * @return 响应结果
-     * @throws IOException IO异常
-     */
-    public static String URLPost(String url, Map<String, Object> params, String enc) {
-
-        String response = EMPTY;
-        PostMethod postMethod = null;
-        try {
-            postMethod = new PostMethod(url);
-            postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=" + enc);
-            //将表单的值放入postMethod中
-            Set<String> keySet = params.keySet();
-            for (String key : keySet) {
-                Object value = params.get(key);
-                postMethod.addParameter(key, String.valueOf(value));
-            }
-            //执行postMethod
-            int statusCode = client.executeMethod(postMethod);
-            if (statusCode == HttpStatus.SC_OK) {
-                response = postMethod.getResponseBodyAsString();
-            } else {
-                logger.error("响应状态码 = " + postMethod.getStatusCode());
-            }
-        } catch (HttpException e) {
-            logger.error("发生致命的异常,可能是协议不对或者返回的内容有问题", e);
-            e.printStackTrace();
-        } catch (IOException e) {
-            logger.error("发生网络异常", e);
-            e.printStackTrace();
-        } finally {
-            if (postMethod != null) {
-                postMethod.releaseConnection();
-                postMethod = null;
-            }
-        }
-
-        return response;
-    }
-
-    /**
-     * GET方式提交数据
-     *
-     * @param url    待请求的URL
-     * @param params 要提交的数据
-     * @param enc    编码
-     * @return 响应结果
-     * @throws IOException IO异常
-     */
-    public static String URLGet(String url, Map<String, String> params, String enc) {
-
-        String response = EMPTY;
-        GetMethod getMethod = null;
-        StringBuffer strtTotalURL = new StringBuffer(EMPTY);
-
-        if (strtTotalURL.indexOf("?") == -1) {
-            strtTotalURL.append(url).append("?").append(getUrl(params, enc));
-        } else {
-            strtTotalURL.append(url).append("&").append(getUrl(params, enc));
-        }
-        logger.info("GET请求URL = \n" + strtTotalURL.toString());
-
-        try {
-            getMethod = new GetMethod(strtTotalURL.toString());
-            getMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=" + enc);
-            //执行getMethod
-            int statusCode = client.executeMethod(getMethod);
-            if (statusCode == HttpStatus.SC_OK) {
-                response = getMethod.getResponseBodyAsString();
-            } else {
-                logger.debug("响应状态码 = " + getMethod.getStatusCode());
-            }
-        } catch (HttpException e) {
-            logger.error("发生致命的异常,可能是协议不对或者返回的内容有问题", e);
-            e.printStackTrace();
-        } catch (IOException e) {
-            logger.error("发生网络异常", e);
-            e.printStackTrace();
-        } finally {
-            if (getMethod != null) {
-                getMethod.releaseConnection();
-                getMethod = null;
-            }
-        }
-
-        return response;
-    }
-
-    /**
-     * 据Map生成URL字符串
-     *
-     * @param map      Map
-     * @param valueEnc URL编码
-     * @return URL
-     */
-    private static String getUrl(Map<String, String> map, String valueEnc) {
-
-        if (null == map || map.keySet().size() == 0) {
-            return (EMPTY);
-        }
-        StringBuffer url = new StringBuffer();
-        Set<String> keys = map.keySet();
-        for (Iterator<String> it = keys.iterator(); it.hasNext(); ) {
-            String key = it.next();
-            if (map.containsKey(key)) {
-                String val = map.get(key);
-                String str = val != null ? val : EMPTY;
-                try {
-                    str = URLEncoder.encode(str, valueEnc);
-                } catch (UnsupportedEncodingException e) {
-                    e.printStackTrace();
-                }
-                url.append(key).append("=").append(str).append(URL_PARAM_CONNECT_FLAG);
-            }
-        }
-        String strURL = EMPTY;
-        strURL = url.toString();
-        if (URL_PARAM_CONNECT_FLAG.equals(EMPTY + strURL.charAt(strURL.length() - 1))) {
-            strURL = strURL.substring(0, strURL.length() - 1);
-        }
-
-        return (strURL);
-    }
-
-    /**
-     * POST方式提交数据
-     *
-     * @param url     待请求的URL
-     * @param params  要提交的数据
-     * @param enc     编码
-     * @param session 带session
-     * @return 响应结果
-     * @throws IOException IO异常
-     */
-    public static String URLPost(String url, Map<String, Object> params, String enc, boolean session) {
-
-        String response = EMPTY;
-        PostMethod postMethod = null;
-        if (!session) {
-            return URLPost(url, params, enc);
-        }
-        try {
-            postMethod = new PostMethod(url);
-            postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=" + enc);
-            //将表单的值放入postMethod中
-            Set<String> keySet = params.keySet();
-            for (String key : keySet) {
-                Object value = params.get(key);
-                postMethod.addParameter(key, String.valueOf(value));
-            }
-            if (null != cookies) {
-                client.getState().addCookies(cookies);
-            } else {
-                getAuthCookie(url, enc);
-                client.getState().addCookies(cookies);
-            }
-            //执行postMethod
-            int statusCode = client.executeMethod(postMethod);
-            if (statusCode == HttpStatus.SC_OK) {
-                response = postMethod.getResponseBodyAsString();
-            } else {
-                logger.error("响应状态码 = " + postMethod.getStatusCode());
-            }
-        } catch (HttpException e) {
-            logger.error("发生致命的异常,可能是协议不对或者返回的内容有问题", e);
-            e.printStackTrace();
-        } catch (IOException e) {
-            logger.error("发生网络异常", e);
-            e.printStackTrace();
-        } finally {
-            if (postMethod != null) {
-                postMethod.releaseConnection();
-                postMethod = null;
-            }
-        }
-
-        return response;
-    }
-
-    /**
-     * 获取session
-     *
-     * @param url 待请求的URL
-     * @param enc 编码
-     * @return 响应结果
-     * @throws IOException IO异常
-     */
-    public static void getAuthCookie(String url, String enc) {
-
-        PostMethod postMethod = null;
-        try {
-            Object[] ipPort = getIpPortFormURL(url);
-            String ip = (String) ipPort[0];
-            int port = (Integer) ipPort[1];
-            String logUrl = "http://" + ip + ":" + port + loginURL;
-            postMethod = new PostMethod(logUrl);
-            postMethod.addParameter("username", loginUserName);
-            postMethod.addParameter("password", loginPassword);
-            postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=" + enc);
-            //执行postMethod
-            int statusCode = client.executeMethod(postMethod);
-            // 查看 cookie 信息
-            CookieSpec cookiespec = CookiePolicy.getDefaultSpec();
-            cookies = cookiespec.match(ip, port, "/", false, client.getState().getCookies());
-            logger.error("响应状态码 = " + postMethod.getStatusCode());
-        } catch (HttpException e) {
-            logger.error("发生致命的异常,可能是协议不对或者返回的内容有问题", e);
-            e.printStackTrace();
-        } catch (IOException e) {
-            logger.error("发生网络异常", e);
-            e.printStackTrace();
-        } finally {
-            if (postMethod != null) {
-                postMethod.releaseConnection();
-                postMethod = null;
-            }
-        }
-    }
-
-    /**
-     * 解析URL的端口和ip
-     *
-     * @param URL
-     * @return
-     */
-    public static Object[] getIpPortFormURL(String URL) {
-        Object[] ip_port = new Object[2];
-        try {
-            java.net.URL url = new java.net.URL(URL);
-            ip_port[0] = url.getHost();
-            ip_port[1] = url.getPort() != -1 ? url.getPort() : 80;
-        } catch (MalformedURLException e) {
-            e.printStackTrace();
-        }
-        return ip_port;
-    }
-
-    public static void setLoginPassword(String loginPassword) {
-        HttpUtil.loginPassword = loginPassword;
-    }
-
-    public static void setLoginUserName(String loginUserName) {
-        HttpUtil.loginUserName = loginUserName;
-    }
-
-    public static void setLoginURL(String loginURL) {
-        HttpUtil.loginURL = loginURL;
-    }
-
-    public static void main(String[] args) throws MalformedURLException {
-        try{
-
-//        java.net.URL url = new java.net.URL("http://blog.csdn.net/zhujianlin1990");
-//        System.out.println(url.getHost());
-//        System.out.println(url.getPort());
-            Map<String, Object> params = new HashMap<>();
-            String result = URLPost("https://4dkk.4dage.com/data/datagu6HmTLKp/hot.json", params, null);
-            result = new String(result.getBytes(),"GBK");
-            System.out.println("返回结果:" + result);
-
-        }catch (Exception e){
-            e.printStackTrace();
-        }
-    }
-}

+ 0 - 320
platform-common/src/main/java/com/platform/utils/HttpUtils.java

@@ -1,320 +0,0 @@
-package com.platform.utils;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.http.HttpResponse;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.ssl.SSLSocketFactory;
-import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.message.BasicNameValuePair;
-
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-public class HttpUtils {
-	
-	/**
-	 * get
-	 * 
-	 * @param host
-	 * @param path
-	 * @param method
-	 * @param headers
-	 * @param querys
-	 * @return
-	 * @throws Exception
-	 */
-	public static HttpResponse doGet(String host, String path, String method, 
-			Map<String, String> headers, 
-			Map<String, String> querys)
-            throws Exception {    	
-    	HttpClient httpClient = wrapClient(host);
-
-    	HttpGet request = new HttpGet(buildUrl(host, path, querys));
-        for (Map.Entry<String, String> e : headers.entrySet()) {
-        	request.addHeader(e.getKey(), e.getValue());
-        }
-        
-        return httpClient.execute(request);
-    }
-	
-	/**
-	 * post form
-	 * 
-	 * @param host
-	 * @param path
-	 * @param method
-	 * @param headers
-	 * @param querys
-	 * @param bodys
-	 * @return
-	 * @throws Exception
-	 */
-	public static HttpResponse doPost(String host, String path, String method, 
-			Map<String, String> headers, 
-			Map<String, String> querys, 
-			Map<String, String> bodys)
-            throws Exception {    	
-    	HttpClient httpClient = wrapClient(host);
-
-    	HttpPost request = new HttpPost(buildUrl(host, path, querys));
-        for (Map.Entry<String, String> e : headers.entrySet()) {
-        	request.addHeader(e.getKey(), e.getValue());
-        }
-
-        if (bodys != null) {
-            List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
-
-            for (String key : bodys.keySet()) {
-                nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
-            }
-            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
-            formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
-            request.setEntity(formEntity);
-        }
-
-        return httpClient.execute(request);
-    }	
-	
-	/**
-	 * Post String
-	 * 
-	 * @param host
-	 * @param path
-	 * @param method
-	 * @param headers
-	 * @param querys
-	 * @param body
-	 * @return
-	 * @throws Exception
-	 */
-	public static HttpResponse doPost(String host, String path, String method, 
-			Map<String, String> headers, 
-			Map<String, String> querys, 
-			String body)
-            throws Exception {    	
-    	HttpClient httpClient = wrapClient(host);
-
-    	HttpPost request = new HttpPost(buildUrl(host, path, querys));
-        for (Map.Entry<String, String> e : headers.entrySet()) {
-        	request.addHeader(e.getKey(), e.getValue());
-        }
-
-        if (StringUtils.isNotBlank(body)) {
-        	request.setEntity(new StringEntity(body, "utf-8"));
-        }
-
-        return httpClient.execute(request);
-    }
-	
-	/**
-	 * Post stream
-	 * 
-	 * @param host
-	 * @param path
-	 * @param method
-	 * @param headers
-	 * @param querys
-	 * @param body
-	 * @return
-	 * @throws Exception
-	 */
-	public static HttpResponse doPost(String host, String path, String method, 
-			Map<String, String> headers, 
-			Map<String, String> querys, 
-			byte[] body)
-            throws Exception {    	
-    	HttpClient httpClient = wrapClient(host);
-
-    	HttpPost request = new HttpPost(buildUrl(host, path, querys));
-        for (Map.Entry<String, String> e : headers.entrySet()) {
-        	request.addHeader(e.getKey(), e.getValue());
-        }
-
-        if (body != null) {
-        	request.setEntity(new ByteArrayEntity(body));
-        }
-
-        return httpClient.execute(request);
-    }
-	
-	/**
-	 * Put String
-	 * @param host
-	 * @param path
-	 * @param method
-	 * @param headers
-	 * @param querys
-	 * @param body
-	 * @return
-	 * @throws Exception
-	 */
-	public static HttpResponse doPut(String host, String path, String method, 
-			Map<String, String> headers, 
-			Map<String, String> querys, 
-			String body)
-            throws Exception {    	
-    	HttpClient httpClient = wrapClient(host);
-
-    	HttpPut request = new HttpPut(buildUrl(host, path, querys));
-        for (Map.Entry<String, String> e : headers.entrySet()) {
-        	request.addHeader(e.getKey(), e.getValue());
-        }
-
-        if (StringUtils.isNotBlank(body)) {
-        	request.setEntity(new StringEntity(body, "utf-8"));
-        }
-
-        return httpClient.execute(request);
-    }
-	
-	/**
-	 * Put stream
-	 * @param host
-	 * @param path
-	 * @param method
-	 * @param headers
-	 * @param querys
-	 * @param body
-	 * @return
-	 * @throws Exception
-	 */
-	public static HttpResponse doPut(String host, String path, String method, 
-			Map<String, String> headers, 
-			Map<String, String> querys, 
-			byte[] body)
-            throws Exception {    	
-    	HttpClient httpClient = wrapClient(host);
-
-    	HttpPut request = new HttpPut(buildUrl(host, path, querys));
-        for (Map.Entry<String, String> e : headers.entrySet()) {
-        	request.addHeader(e.getKey(), e.getValue());
-        }
-
-        if (body != null) {
-        	request.setEntity(new ByteArrayEntity(body));
-        }
-
-        return httpClient.execute(request);
-    }
-	
-	/**
-	 * Delete
-	 *  
-	 * @param host
-	 * @param path
-	 * @param method
-	 * @param headers
-	 * @param querys
-	 * @return
-	 * @throws Exception
-	 */
-	public static HttpResponse doDelete(String host, String path, String method, 
-			Map<String, String> headers, 
-			Map<String, String> querys)
-            throws Exception {    	
-    	HttpClient httpClient = wrapClient(host);
-
-    	HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
-        for (Map.Entry<String, String> e : headers.entrySet()) {
-        	request.addHeader(e.getKey(), e.getValue());
-        }
-        
-        return httpClient.execute(request);
-    }
-	
-	private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
-    	StringBuilder sbUrl = new StringBuilder();
-    	sbUrl.append(host);
-    	if (!StringUtils.isBlank(path)) {
-    		sbUrl.append(path);
-        }
-    	if (null != querys) {
-    		StringBuilder sbQuery = new StringBuilder();
-        	for (Map.Entry<String, String> query : querys.entrySet()) {
-        		if (0 < sbQuery.length()) {
-        			sbQuery.append("&");
-        		}
-        		if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
-        			sbQuery.append(query.getValue());
-                }
-        		if (!StringUtils.isBlank(query.getKey())) {
-        			sbQuery.append(query.getKey());
-        			if (!StringUtils.isBlank(query.getValue())) {
-        				sbQuery.append("=");
-        				sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
-        			}        			
-                }
-        	}
-        	if (0 < sbQuery.length()) {
-        		sbUrl.append("?").append(sbQuery);
-        	}
-        }
-    	
-    	return sbUrl.toString();
-    }
-	
-	private static HttpClient wrapClient(String host) {
-		HttpClient httpClient = new DefaultHttpClient();
-		if (host.startsWith("https://")) {
-			sslClient(httpClient);
-		}
-		
-		return httpClient;
-	}
-	
-	private static void sslClient(HttpClient httpClient) {
-        try {
-            SSLContext ctx = SSLContext.getInstance("TLS");
-            X509TrustManager tm = new X509TrustManager() {
-                public X509Certificate[] getAcceptedIssuers() {
-                    return null;
-                }
-                public void checkClientTrusted(X509Certificate[] xcs, String str) {
-                	
-                }
-                public void checkServerTrusted(X509Certificate[] xcs, String str) {
-                	
-                }
-            };
-            ctx.init(null, new TrustManager[] { tm }, null);
-            SSLSocketFactory ssf = new SSLSocketFactory(ctx);
-            ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
-            ClientConnectionManager ccm = httpClient.getConnectionManager();
-            SchemeRegistry registry = ccm.getSchemeRegistry();
-            registry.register(new Scheme("https", 443, ssf));
-        } catch (KeyManagementException ex) {
-            throw new RuntimeException(ex);
-        } catch (NoSuchAlgorithmException ex) {
-        	throw new RuntimeException(ex);
-        }
-    }
-
-	public static void main(String[] args) {
-		try{
-			HttpResponse response = doGet("https://4dkk.4dage.com/data/datagu6HmTLKp/hot.json", null, null, null, null);
-			System.out.println("1");
-		}catch (Exception e){
-			e.printStackTrace();
-		}
-	}
-}

+ 2 - 1
platform-common/src/main/java/com/platform/utils/LogisticsUtil.java

@@ -1,6 +1,7 @@
 package com.platform.utils;
 
 import com.alibaba.fastjson.JSONObject;
+import com.fdage.micro.commom.utils.HttpClientUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.HttpResponse;
 import org.apache.http.util.EntityUtils;
@@ -48,7 +49,7 @@ public class LogisticsUtil {
              * 相关jar包(非pom)直接下载:
              * http://code.fegine.com/aliyun-jar.zip
              */
-            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
+            HttpResponse response = HttpClientUtil.doGet(host, path, method, headers, querys);
             //System.out.println(response.toString());如不输出json, 请打开这行代码,打印调试头部状态码。
             //状态码: 200 正常;400 URL无效;401 appCode错误; 403 次数用完; 500 API网管错误
             //获取response的body