Pārlūkot izejas kodu

Merge branch 'srdev' of trick9191/patient-co-management into srdev

trick9191 7 gadi atpakaļ
vecāks
revīzija
f9d44954cd

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 28 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java


+ 47 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/HttpUtil.java

@ -1,5 +1,15 @@
package com.yihu.wlyy.util;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
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.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -10,6 +20,9 @@ import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/*
 * MD5 算法
@ -217,4 +230,38 @@ public class HttpUtil {
	public static String httpPost(String url, Map<String, String> params) throws IOException {
		CloseableHttpClient httpclient = HttpClients.createDefault();
		try {
			RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(30000).setConnectTimeout(5000).build();//设置请求和传输超时时间
			HttpPost httpPost = new HttpPost(url);
			httpPost.setConfig(requestConfig);
			if (params != null && params.size() > 0) {
				List<NameValuePair> valuePairs = new ArrayList<NameValuePair>(params.size());
				for (Map.Entry<String, String> entry : params.entrySet()) {
					NameValuePair nameValuePair = new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue()));
					valuePairs.add(nameValuePair);
				}
				UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(valuePairs, "UTF-8");
				httpPost.setEntity(formEntity);
			}
			CloseableHttpResponse resp = httpclient.execute(httpPost);
			try {
				HttpEntity entity = resp.getEntity();
				String respContent = EntityUtils.toString(entity, "UTF-8").trim();
				return respContent;
			} finally {
				resp.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			httpclient.close();
		}
	}
}

+ 290 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/http/HttpClientUtil.java

@ -0,0 +1,290 @@
//package com.yihu.wlyy.util.http;
//
//import net.minidev.json.JSONObject;
//import org.apache.commons.httpclient.*;
//import org.apache.commons.httpclient.auth.AuthScope;
//import org.apache.commons.httpclient.methods.DeleteMethod;
//import org.apache.commons.httpclient.methods.GetMethod;
//import org.apache.commons.httpclient.methods.PostMethod;
//import org.apache.commons.httpclient.methods.PutMethod;
//import org.apache.commons.httpclient.params.HttpMethodParams;
//import org.apache.http.client.utils.URLEncodedUtils;
//import org.apache.http.message.BasicNameValuePair;
//import org.apache.http.protocol.HTTP;
//import org.apache.log4j.Logger;
//import org.springframework.util.StringUtils;
//
//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.util.*;
//
///**
// * HTTP 请求工具类
// *
// * @author : cwd
// * @version : 1.0.0
// * @date : 2016/1/14
// * @see : TODO
// */
//public class HttpClientUtil {
//    public static Logger logger  = Logger.getLogger(HttpClientUtil.class);
//
//    /**
//     * 发送 GET 请求(HTTP),不带输入数据 不加密
//     *
//     * @param url
//     * @return
//     */
//    public static String doGet(String url) throws Exception {
//        return doGet(url, new HashMap<String, Object>(), "", "");
//    }
//
//    /**
//     * 发送 GET 请求(HTTP),不带输入数据 不加密
//     *
//     * @param url
//     * @return
//     */
//    public static String doGet(String url, Map<String, Object> params) throws Exception {
//        return doGet(url, params, "", "");
//    }
//
//    /**
//     * 发送 GET 请求(HTTP),不带输入数据 加密
//     *
//     * @param url
//     * @return
//     */
//    public static String doGet(String url, String username, String password) throws Exception {
//        return doGet(url, new HashMap<String, Object>(), username, password);
//    }
//
//    /**
//     * httpClient的get请求方式
//     *
//     * @return
//     * @throws Exception
//     */
//    public static String doGet(String url, Map<String, Object> params, String username, String password)
//            throws Exception {
//        String getKey = UUID.randomUUID().toString();
//        logger.info( "用户:" + username+";发起get请求连接:" + url+",请求标示:"+getKey);
//        HttpClient httpClient = new HttpClient();
//        String response = "";
//        List<BasicNameValuePair> jsonParams = new ArrayList<>();
//        GetMethod getMethod = null;
//        StringBuilder param = new StringBuilder();
//        int i = 0;
//        try {
//            if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) {
//                //需要验证
//                UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
//                httpClient.getState().setCredentials(AuthScope.ANY, creds);
//            }
//            //配置参数
//            for (String key : params.keySet()) {
//                jsonParams.add(new BasicNameValuePair(key, String.valueOf(params.get(key))));
//            }
//            getMethod = new GetMethod(url + "?" + URLEncodedUtils.format(jsonParams, HTTP.UTF_8));
//            getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
//            int statusCode = httpClient.executeMethod(getMethod);
//            BufferedReader reader = new BufferedReader(new InputStreamReader(getMethod.getResponseBodyAsStream(), "UTF-8"));
//            StringBuffer stringBuffer = new StringBuffer();
//            String str = "";
//            while((str = reader.readLine()) != null){
//                stringBuffer.append(str);
//            }
//            response = stringBuffer.toString();
//            if (statusCode != HttpStatus.SC_OK) {
//                String jsonObject = JSONObject.toJSONString(params);
//                logger.debug("用户:" + username + "\r\n发起get请求出错:\r\n请求连接" + url + "\r\n请求参数:" + jsonObject + ",状态:" + statusCode + "\r\nresponseBody" + response + ",\r\n请求标示:" + getKey +"\r\n");
//                throw new Exception("请求出错: " + getMethod.getStatusLine());
//            }
//        } catch (HttpException e) {
//            logger.debug("用户:"+username+";发起get请求出错,请求连接:" + url + ",HttpException异常信息:" + e.getLocalizedMessage()+",请求标示:"+getKey);
//            e.printStackTrace();
//        } catch (IOException e) {
//            logger.debug("用户:"+username+";发起get请求出错,请求连接:" + url + ",IOException异常信息:" + e.getLocalizedMessage()+",请求标示:"+getKey);
//            e.printStackTrace();
//        } finally {
//            // getMethod.releaseConnection();
//        }
//        return response;
//    }
//
//    /**
//     * 发送 POST 请求(HTTP),不带输入数据 不加密
//     */
//    public static String doPost(String url, Map<String, Object> params) throws Exception {
//        return doPost(url, params, "", "");
//    }
//
//    /**
//     *  httpClient的post请求方式
//     * @param url
//     * @param params
//     * @param username
//     * @param password
//     * @return
//     * @throws Exception
//     */
//    public static String doPost(String url, Map<String, Object> params, String username, String password) throws Exception {
//         String postKey = UUID.randomUUID().toString();
//        logger.info( "用户:" + username+";发起post请求连接:" + url+",请求标示:"+postKey);
//        HttpClient httpClient = new HttpClient();
//        String response = "";
//        List<NameValuePair> jsonParams=new ArrayList<NameValuePair>();
//        PostMethod postMethod = null;
//        StringBuilder param = new StringBuilder();
//        int i = 0;
//        try {
//            if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) {
//                //需要验证
//                UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
//                httpClient.getState().setCredentials(AuthScope.ANY, creds);
//            }
//            NameValuePair nameValuePair  =null;
//            //配置参数
//            postMethod = new PostMethod(url);
//            for (String key : params.keySet()) {
//                nameValuePair = new NameValuePair(key, String.valueOf(params.get(key)));
//                postMethod.addParameter(nameValuePair);
//            }
//            postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
//            postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"utf-8");
//            int statusCode = httpClient.executeMethod(postMethod);
//            BufferedReader reader = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream(), "UTF-8"));
//            StringBuffer stringBuffer = new StringBuffer();
//            String str = "";
//            while((str = reader.readLine()) != null){
//                stringBuffer.append(str);
//            }
//            response = stringBuffer.toString();
//            if (statusCode != HttpStatus.SC_OK) {
//                String jsonObject = JSONObject.toJSONString(params);
//                logger.debug("用户:" + username + "\r\n发起post请求出错:\r\n请求连接" + url + "\r\n请求参数:" + jsonObject + ",状态:" + statusCode + "\r\nresponseBody"+ response + ",\r\n请求标示:" + postKey + "\r\n");
//                throw new Exception("请求出错: " + postMethod.getStatusLine());
//            }
//        } catch (HttpException e) {
//            logger.debug("用户:" + username + ";发起post请求出错,请求连接:" + url + ",HttpException异常信息:" + e.getLocalizedMessage() + ",请求标示:" + postKey);
//            e.printStackTrace();
//        } catch (IOException e) {
//            logger.debug("用户:" + username + ";发起post请求出错,请求连接:" + url + ",IOException异常信息:" + e.getLocalizedMessage() + ",请求标示:" + postKey);
//            e.printStackTrace();
//        } finally {
//            // getMethod.releaseConnection();
//        }
//        return response;
//    }
//
//    /**
//     *  httpClient的put请求方式
//     * @param url
//     * @param params
//     * @param username
//     * @param password
//     * @return
//     * @throws Exception
//     */
//    public static String doPut(String url, Map<String, Object> params, String username, String password) throws Exception {
//        String putKey = UUID.randomUUID().toString();
//        logger.info( "用户:" + username+";发起put请求连接:" + url+",请求标示:"+putKey);
//        HttpClient httpClient = new HttpClient();
//        String response = "";
//        List<BasicNameValuePair> jsonParams = new ArrayList<>();
//        PutMethod putMethod = null;
//        StringBuilder param = new StringBuilder();
//        int i = 0;
//        try {
//            if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) {
//                //需要验证
//                UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
//                httpClient.getState().setCredentials(AuthScope.ANY, creds);
//            }
//            //配置参数
//            for (String key : params.keySet()) {
//                jsonParams.add(new BasicNameValuePair(key, String.valueOf(params.get(key))));
//            }
//            putMethod = new PutMethod(url + "?" + URLEncodedUtils.format(jsonParams, HTTP.UTF_8));
//            putMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
//            int statusCode = httpClient.executeMethod(putMethod);
//            BufferedReader reader = new BufferedReader(new InputStreamReader(putMethod.getResponseBodyAsStream(), "UTF-8"));
//            StringBuffer stringBuffer = new StringBuffer();
//            String str = "";
//            while((str = reader.readLine()) != null){
//                stringBuffer.append(str);
//            }
//            response = stringBuffer.toString();
//            if (statusCode != HttpStatus.SC_OK) {
//                String jsonObject = JSONObject.toJSONString(params);
//                logger.debug("用户:" + username + "\r\n发起put请求出错:\r\n请求连接" + url + "\r\n请求参数:" + jsonObject + ",状态:" + statusCode + "\r\nresponseBody"+ response + ",\r\n请求标示:" + putKey + "\r\n");
//                throw new Exception("请求出错: " + putMethod.getStatusLine());
//            }
//        } catch (HttpException e) {
//            logger.debug("用户:" + username + ";发起put请求出错,请求连接:" + url + ",HttpException异常信息:" + e.getLocalizedMessage() + ",请求标示:" + putKey);
//            e.printStackTrace();
//        } catch (IOException e) {
//            logger.debug("用户:" + username + ";发起put请求出错,请求连接:" + url + ",IOException异常信息:" + e.getLocalizedMessage() + ",请求标示:" + putKey);
//            e.printStackTrace();
//        } finally {
//            // getMethod.releaseConnection();
//        }
//        return response;
//    }
//
//    /**
//     *  httpClient的delete请求方式
//     * @param url
//     * @param params
//     * @param username
//     * @param password
//     * @return
//     * @throws Exception
//     */
//    public static String doDelete(String url, Map<String, Object> params, String username, String password) throws Exception {
//        String deleteKey = UUID.randomUUID().toString();
//        logger.info( "用户:" + username+";发起delete请求连接:" + url+",请求标示:"+deleteKey);
//        HttpClient httpClient = new HttpClient();
//        String response = "";
//        List<BasicNameValuePair> jsonParams = new ArrayList<>();
//        DeleteMethod deleteMethod = null;
//        StringBuilder param = new StringBuilder();
//        int i = 0;
//        try {
//            if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) {
//                //需要验证
//                UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
//                httpClient.getState().setCredentials(AuthScope.ANY, creds);
//            }
//            //配置参数
//            for (String key : params.keySet()) {
//                jsonParams.add(new BasicNameValuePair(key, String.valueOf(params.get(key))));
//            }
//            deleteMethod = new DeleteMethod(url + "?" + URLEncodedUtils.format(jsonParams, HTTP.UTF_8));
//            deleteMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
//            int statusCode = httpClient.executeMethod(deleteMethod);
//            BufferedReader reader = new BufferedReader(new InputStreamReader(deleteMethod.getResponseBodyAsStream(), "UTF-8"));
//            StringBuffer stringBuffer = new StringBuffer();
//            String str = "";
//            while((str = reader.readLine()) != null){
//                stringBuffer.append(str);
//            }
//            response = stringBuffer.toString();
//            if (statusCode != HttpStatus.SC_OK) {
//                String jsonObject = JSONObject.toJSONString(params);
//                logger.debug("用户:" + username + "\r\n发起delete请求出错:\r\n请求连接" + url + "\r\n请求参数:" + jsonObject + ",状态:" + statusCode + "\r\nresponseBody" + response +",\r\n请求标示:" + deleteKey + "\r\n");
//                throw new Exception("请求出错: " + deleteMethod.getStatusLine());
//            }
//        } catch (HttpException e) {
//            logger.debug("用户:" + username + ";发起delete请求出错,请求连接:" + url + ",HttpException异常信息:" + e.getLocalizedMessage() + ",请求标示:" + deleteKey);
//            e.printStackTrace();
//        } catch (IOException e) {
//            logger.debug("用户:" + username + ";发起delete请求出错,请求连接:" + url + ",IOException异常信息:" + e.getLocalizedMessage() + ",请求标示:" + deleteKey);
//            e.printStackTrace();
//        } finally {
//            // getMethod.releaseConnection();
//        }
//        return response;
//    }
//}

+ 41 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/http/HttpResponse.java

@ -0,0 +1,41 @@
package com.yihu.wlyy.util.http;
/**
 * Utils - Http请求辅助类,简化页面页面判断逻辑
 * Created by progr1mmer on 2018/1/16.
 */
public class HttpResponse {
    private int status;
    private String content;
    public HttpResponse(int status, String content) {
        this.status = status;
        this.content = content;
    }
    public int getStatus() {
        return status;
    }
    public void setStatus(int status) {
        this.status = status;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public boolean isSuccessFlg() {
        return status == 200;
    }
    public String getErrorMsg() {
        return content;
    }
}

+ 449 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/http/HttpUtils.java

@ -0,0 +1,449 @@
package com.yihu.wlyy.util.http;
import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.*;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.BasicCredentialsProvider;
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.StringUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * Utils - HTTP请求辅助工具类
 * Created by progr1mmer on 2017/9/27.
 */
public class HttpUtils {
    public static HttpResponse doGet(String url, Map<String, Object> params) throws Exception {
        return doGet(url, params, null);
    }
    public static HttpResponse doGet(String url, Map<String, Object> params, Map<String, String> headers) throws Exception {
        return doGet(url, params, headers, null, null);
    }
    public static HttpResponse doGet(String url, Map<String, Object> params, Map<String, String> headers, String username, String password) throws Exception {
        String response;
        int status;
        CloseableHttpClient httpClient = null;
        CloseableHttpResponse closeableHttpResponse = null;
        List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
        if (params != null) {
            for (String key : params.keySet()) {
                Object value = params.get(key);
                if (value != null) {
                    nameValuePairList.add(new BasicNameValuePair(key, String.valueOf(params.get(key))));
                }
            }
        }
        String paramStr = EntityUtils.toString(new UrlEncodedFormEntity(nameValuePairList, "UTF-8"));
        HttpGet httpGet = new HttpGet(url + "?" + paramStr);
        if (headers != null) {
            for (String key : headers.keySet()) {
                httpGet.addHeader(key, headers.get(key));
            }
        }
        try {
            if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) {
                UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials(username, password);
                CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
                credentialsProvider.setCredentials(AuthScope.ANY, usernamePasswordCredentials);
                httpClient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
            } else {
                httpClient = HttpClients.createDefault();
            }
            closeableHttpResponse = httpClient.execute(httpGet);
            HttpEntity resEntity = closeableHttpResponse.getEntity();
            status = closeableHttpResponse.getStatusLine().getStatusCode();
            response = getRespString(resEntity);
        } finally {
            try {
                if (closeableHttpResponse != null) {
                    closeableHttpResponse.close();
                }
                if (httpClient != null) {
                    httpClient.close();
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (status != HttpStatus.SC_OK) {
//            LogService.getLogger().error(" GET: " + url + " " + status);
        }
        HttpResponse httpResponse = new HttpResponse(status, response);
        return httpResponse;
    }
    public static HttpResponse doPost(String url, Map<String, Object> params) throws Exception {
        return doPost(url, params, null);
    }
    public static HttpResponse doPost(String url, Map<String, Object> params, Map<String, String> headers) throws Exception{
        return doPost(url, params, headers, null, null);
    }
    public static HttpResponse doPost(String url, Map<String, Object> params, Map<String, String> headers, String username, String password) throws Exception{
        String response;
        int status;
        CloseableHttpClient httpClient = null;
        CloseableHttpResponse closeableHttpResponse = null;
        HttpPost httpPost = new HttpPost(url);
        List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
        if (params != null) {
            for (String key : params.keySet()) {
                Object value = params.get(key);
                if (value != null) {
                    nameValuePairList.add(new BasicNameValuePair(key, String.valueOf(params.get(key))));
                }
            }
        }
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairList, "UTF-8"));
        if (headers != null) {
            for (String key : headers.keySet()) {
                httpPost.addHeader(key, headers.get(key));
            }
        }
        try {
            if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) {
                UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials(username, password);
                CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
                credentialsProvider.setCredentials(AuthScope.ANY, usernamePasswordCredentials);
                httpClient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
            } else {
                httpClient = HttpClients.createDefault();
            }
            closeableHttpResponse = httpClient.execute(httpPost);
            HttpEntity resEntity = closeableHttpResponse.getEntity();
            status = closeableHttpResponse.getStatusLine().getStatusCode();
            response = getRespString(resEntity);
        } finally {
            try {
                if (closeableHttpResponse != null) {
                    closeableHttpResponse.close();
                }
                if (httpClient != null) {
                    httpClient.close();
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
        }
        if(status != HttpStatus.SC_OK) {
//            LogService.getLogger().error(" POST: " + url + " " + status);
        }
        HttpResponse httpResponse = new HttpResponse(status, response);
        return httpResponse;
    }
    public static HttpResponse doJsonPost(String url, String jsonData, Map<String, String> headers, String username, String password) throws Exception{
        String response;
        int status;
        CloseableHttpClient httpClient = null;
        CloseableHttpResponse closeableHttpResponse = null;
        HttpPost httpPost = new HttpPost(url);
        httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
        httpPost.setEntity(new StringEntity(jsonData, "UTF-8"));
        if (headers != null) {
            for (String key : headers.keySet()) {
                httpPost.addHeader(key, headers.get(key));
            }
        }
        try {
            if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) {
                UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials(username, password);
                CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
                credentialsProvider.setCredentials(AuthScope.ANY, usernamePasswordCredentials);
                httpClient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
            } else {
                httpClient = HttpClients.createDefault();
            }
            closeableHttpResponse = httpClient.execute(httpPost);
            HttpEntity resEntity = closeableHttpResponse.getEntity();
            status = closeableHttpResponse.getStatusLine().getStatusCode();
            response = getRespString(resEntity);
        } finally {
            try {
                if (closeableHttpResponse != null) {
                    closeableHttpResponse.close();
                }
                if (httpClient != null) {
                    httpClient.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if(status != HttpStatus.SC_OK) {
//            LogService.getLogger().error(" POST: " + url + " " + status);
        }
        HttpResponse httpResponse = new HttpResponse(status, response);
        return httpResponse;
    }
    public static HttpResponse doPut(String url, Map<String, Object> params) throws Exception {
        return doPut(url, params, null);
    }
    public static HttpResponse doPut(String url, Map<String, Object> params, Map<String, String> headers) throws Exception {
        return doPut(url, params, headers, null, null);
    }
    public static HttpResponse doPut(String url, Map<String, Object> params, Map<String, String> headers, String username, String password) throws Exception {
        String response;
        int status;
        CloseableHttpClient httpClient = null;
        CloseableHttpResponse closeableHttpResponse = null;
        HttpPut httpPut = new HttpPut(url);
        List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
        if (params != null) {
            for (String key : params.keySet()) {
                Object value = params.get(key);
                if (value != null) {
                    nameValuePairList.add(new BasicNameValuePair(key, String.valueOf(params.get(key))));
                }
            }
        }
        httpPut.setEntity(new UrlEncodedFormEntity(nameValuePairList, "UTF-8"));
        if (headers != null) {
            for (String key : headers.keySet()) {
                httpPut.addHeader(key, headers.get(key));
            }
        }
        try {
            if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) {
                UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials(username, password);
                CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
                credentialsProvider.setCredentials(AuthScope.ANY, usernamePasswordCredentials);
                httpClient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
            } else {
                httpClient = HttpClients.createDefault();
            }
            closeableHttpResponse = httpClient.execute(httpPut);
            HttpEntity resEntity = closeableHttpResponse.getEntity();
            status = closeableHttpResponse.getStatusLine().getStatusCode();
            response = getRespString(resEntity);
        } finally {
            try {
                if (closeableHttpResponse != null) {
                    closeableHttpResponse.close();
                }
                if (httpClient != null) {
                    httpClient.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (status != HttpStatus.SC_OK) {
//            LogService.getLogger().error(" PUT: " + url + " " + status);
        }
        HttpResponse httpResponse = new HttpResponse(status, response);
        return httpResponse;
    }
    public static HttpResponse doJsonPut(String url, String jsonData, Map<String, String> headers, String username, String password) throws Exception {
        String response;
        int status;
        CloseableHttpClient httpClient = null;
        CloseableHttpResponse closeableHttpResponse = null;
        HttpPut httpPut = new HttpPut(url);
        httpPut.setHeader("Content-Type", "application/json;charset=UTF-8");
        httpPut.setEntity(new StringEntity(jsonData, "UTF-8"));
        if (headers != null) {
            for (String key : headers.keySet()) {
                httpPut.addHeader(key, headers.get(key));
            }
        }
        try {
            if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) {
                UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials(username, password);
                CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
                credentialsProvider.setCredentials(AuthScope.ANY, usernamePasswordCredentials);
                httpClient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
            } else {
                httpClient = HttpClients.createDefault();
            }
            closeableHttpResponse = httpClient.execute(httpPut);
            HttpEntity resEntity = closeableHttpResponse.getEntity();
            status = closeableHttpResponse.getStatusLine().getStatusCode();
            response = getRespString(resEntity);
        } finally {
            try {
                if (closeableHttpResponse != null) {
                    closeableHttpResponse.close();
                }
                if (httpClient != null) {
                    httpClient.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (status != HttpStatus.SC_OK) {
//            LogService.getLogger().error(" PUT: " + url + " " + status);
        }
        HttpResponse httpResponse = new HttpResponse(status, response);
        return httpResponse;
    }
    public static HttpResponse doDelete(String url, Map<String, Object> params) throws Exception {
        return doDelete(url, params, null);
    }
    public static HttpResponse doDelete(String url, Map<String, Object> params, Map<String, String> headers) throws Exception {
        return doDelete(url, params, headers, null, null);
    }
    public static HttpResponse doDelete(String url, Map<String, Object> params, Map<String, String> headers, String username, String password) throws Exception {
        String response;
        int status;
        CloseableHttpClient httpClient = null;
        CloseableHttpResponse closeableHttpResponse = null;
        List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
        if (params != null) {
            for (String key : params.keySet()) {
                Object value = params.get(key);
                if (value != null) {
                    nameValuePairList.add(new BasicNameValuePair(key, String.valueOf(params.get(key))));
                }
            }
        }
        String paramStr = EntityUtils.toString(new UrlEncodedFormEntity(nameValuePairList, "UTF-8"));
        HttpDelete httpDelete = new HttpDelete(url + "?" + paramStr);
        if (headers != null) {
            for (String key : headers.keySet()) {
                httpDelete.addHeader(key, headers.get(key));
            }
        }
        try {
            if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) {
                UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials(username, password);
                CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
                credentialsProvider.setCredentials(AuthScope.ANY, usernamePasswordCredentials);
                httpClient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
            } else {
                httpClient = HttpClients.createDefault();
            }
            closeableHttpResponse = httpClient.execute(httpDelete);
            HttpEntity resEntity = closeableHttpResponse.getEntity();
            status = closeableHttpResponse.getStatusLine().getStatusCode();
            response = getRespString(resEntity);
        } finally {
            try {
                if (closeableHttpResponse != null) {
                    closeableHttpResponse.close();
                }
                if (httpClient != null) {
                    httpClient.close();
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (status != HttpStatus.SC_OK) {
//            LogService.getLogger().error(" DELETE: " + url + " " + status);
        }
        HttpResponse httpResponse = new HttpResponse(status, response);
        return httpResponse;
    }
    public static HttpResponse doUpload(String url, Map<String, Object> params, File file) throws Exception {
        return doUpload(url, params, null, file, null, null);
    }
    public static HttpResponse doUpload(String url, Map<String, Object> params, Map<String, String> headers, File file) throws Exception {
        return doUpload(url, params, headers, file, null, null);
    }
    public static HttpResponse doUpload(String url, Map<String, Object> params, Map<String, String> headers, File file, String username, String password) throws Exception {
        String response;
        int status;
        CloseableHttpClient httpClient = null;
        CloseableHttpResponse closeableHttpResponse = null;
        HttpPost httpPost = new HttpPost(url);
        MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
        FileBody fileBody = new FileBody(file);
        multipartEntityBuilder.addPart("file", fileBody);
        if (params != null) {
            for (String key : params.keySet()) {
                Object value = params.get(key);
                if (value != null) {
                    multipartEntityBuilder.addTextBody(key, String.valueOf(params.get(key)), ContentType.TEXT_PLAIN);
                }
            }
        }
        if (headers != null) {
            for (String key : headers.keySet()) {
                httpPost.addHeader(key, headers.get(key));
            }
        }
        HttpEntity reqEntity = multipartEntityBuilder.build();
        httpPost.setEntity(reqEntity);
        try {
            if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) {
                UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials(username, password);
                CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
                credentialsProvider.setCredentials(AuthScope.ANY, usernamePasswordCredentials);
                httpClient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
            } else {
                httpClient = HttpClients.createDefault();
            }
            closeableHttpResponse = httpClient.execute(httpPost);
            HttpEntity resEntity = closeableHttpResponse.getEntity();
            status = closeableHttpResponse.getStatusLine().getStatusCode();
            response = getRespString(resEntity);
        } finally {
            try {
                if (closeableHttpResponse != null) {
                    closeableHttpResponse.close();
                }
                if (httpClient != null) {
                    httpClient.close();
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (status != HttpStatus.SC_OK) {
//            LogService.getLogger().error(" POST UPLOAD: " + url + " " + status);
        }
        HttpResponse httpResponse = new HttpResponse(status, response);
        return httpResponse;
    }
    private static String getRespString(HttpEntity entity) throws Exception {
        if (entity == null) {
            return null;
        }
        InputStream is = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        StringBuilder stringBuilder = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            stringBuilder.append(line);
        }
        return stringBuilder.toString();
    }
}

+ 54 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/http/IPInfoUtils.java

@ -0,0 +1,54 @@
package com.yihu.wlyy.util.http;
import javax.servlet.http.HttpServletRequest;
/**
 * Utils - ip信息辅助工具类
 * Created by progr1mmer on 2018/1/18.
 */
public class IPInfoUtils {
    private static final long A1 = getIpNum("10.0.0.0");
    private static final long A2 = getIpNum("10.255.255.255");
    private static final long B1 = getIpNum("172.16.0.0");
    private static final long B2 = getIpNum("172.31.255.255");
    private static final long C1 = getIpNum("192.168.0.0");
    private static final long C2 = getIpNum("192.168.255.255");
    private static final long D1 = getIpNum("10.44.0.0");
    private static final long D2 = getIpNum("10.69.0.255");
    private static long getIpNum(String ipAddress) {
        String [] ip = ipAddress.split("\\.");
        long a = Integer.parseInt(ip[0]);
        long b = Integer.parseInt(ip[1]);
        long c = Integer.parseInt(ip[2]);
        long d = Integer.parseInt(ip[3]);
        return a * 256 * 256 * 256 + b * 256 * 256 + c * 256 + d;
    }
    public static boolean isInnerIP(String ip){
        long n = getIpNum(ip);
        return (n >= A1 && n <= A2) || (n >= B1 && n <= B2) || (n >= C1 && n <= C2) || (n >= D1 && n <= D2);
    }
    public static String getIPAddress(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_CLIENT_IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_X_FORWARDED_FOR");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }
}

+ 9 - 9
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/wechat/process/WeiXinEventProcess.java

@ -390,8 +390,8 @@ public class WeiXinEventProcess {
            picUrl = picUrl.replace("{server}", serverUrl);
            article.put("Url", url);
            article.put("Title", "欢迎关注厦门i健康,快来签约家庭医生吧~");
            article.put("Description", "请点击查看家庭签约");
            article.put("Title", "欢迎关注上饶i健康,快来关注家庭医生吧~");
            article.put("Description", "请点击查看关注医生详情");
            article.put("PicUrl", picUrl);
            articles.add(article);
@ -432,8 +432,8 @@ public class WeiXinEventProcess {
            picUrl = picUrl.replace("{server}", serverUrl);
            article.put("Url", url);
            article.put("Title", "欢迎关注厦门i健康,快来签约家庭医生吧~");
            article.put("Description", "请点击查看家庭签约");
            article.put("Title", "欢迎关注上饶i健康,快来关注家庭医生吧~");
            article.put("Description", "请点击查看关注医生详情");
            article.put("PicUrl", picUrl);
            articles.add(article);
@ -637,8 +637,8 @@ public class WeiXinEventProcess {
            picUrl = picUrl.replace("{server}", serverUrl);
            article.put("Url", url);
            article.put("Title", keys[1] + "医生签约");
            article.put("Description", "请点击查看医生详情并申请签约");
            article.put("Title", keys[1] + "医生关注");
            article.put("Description", "请点击查看医生详情并关注家庭医生");
            article.put("PicUrl", picUrl);
            articles.add(article);
@ -752,8 +752,8 @@ public class WeiXinEventProcess {
            picUrl = picUrl.replace("{server}", serverUrl);
            article.put("Url", url);
            article.put("Title", "欢迎关注厦门i健康,快来签约家庭医生吧~");
            article.put("Description", "请点击查看家庭签约");
            article.put("Title", "欢迎关注上饶i健康,快来关注家庭医生吧~");
            article.put("Description", "请点击查看关注医生详情");
            article.put("PicUrl", picUrl);
            articles.add(article);
@ -827,7 +827,7 @@ public class WeiXinEventProcess {
        String description1 = "为了能给您提供健康服务,诚邀您签签约家庭医生。";
        // 图文信息
        List<Map<String, String>> articles = new ArrayList<>();
        Map videoText = getNews("doctor_subscribe_url", "doctor_qrcode_pic_url", "欢迎关注厦门i健康,快来签约家庭医生吧~", null);
        Map videoText = getNews("doctor_subscribe_url", "doctor_qrcode_pic_url", "欢迎关注上饶i健康,快来关注家庭医生吧~", null);
        Map videoText1 = getNews("patient_sign_again_url", "patient_sign_again_pic_url", "家庭医生续签提醒", null);
        articles.add(videoText);
        articles.add(videoText1);

+ 1 - 1
patient-co/patient-co-wlyy/src/main/resources/application-dev.yml

@ -42,7 +42,7 @@ wechat:
  appId: wxe627ffaee2d05a40
  appSecret: 7c29f6b28be7e54b742883a47ff39767
  wechat_token: 27eb3bb24f149a7760cf1bb154b08040
  wechat_base_url: http%3a%2f%2fweixin.xmtyw.cn%2fwlyy-dev
  wechat_base_url: http://srijk.yihu.com/wlyy/
  accId: gh_733f975e0bed
  message:
   #咨询回复