Commit 2d03d8233e9bc59a1a27312bde4b508f0d47a425
1 parent
98f247f183
Exists in
master
and in
6 other branches
儿童保健查看页面修改
Showing 5 changed files with 147 additions and 5 deletions
- platform-common/src/main/java/com/lyms/platform/common/utils/HttpClientUtil.java
- platform-common/src/main/java/com/lyms/platform/common/utils/SSLClient.java
- platform-data-api/src/main/java/com/lyms/platform/data/util/AmsMessageService.java
- platform-data-api/src/main/resources/config.properties
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/AreaCountFacade.java
platform-common/src/main/java/com/lyms/platform/common/utils/HttpClientUtil.java
View file @
2d03d82
1 | +package com.lyms.platform.common.utils; | |
2 | + | |
3 | +/** | |
4 | + * Created by Administrator on 2017-01-18. | |
5 | + */ | |
6 | + | |
7 | +import org.apache.http.HttpEntity; | |
8 | +import org.apache.http.HttpResponse; | |
9 | +import org.apache.http.NameValuePair; | |
10 | +import org.apache.http.client.HttpClient; | |
11 | +import org.apache.http.client.entity.UrlEncodedFormEntity; | |
12 | +import org.apache.http.client.methods.HttpGet; | |
13 | +import org.apache.http.client.methods.HttpPost; | |
14 | +import org.apache.http.message.BasicNameValuePair; | |
15 | +import org.apache.http.util.EntityUtils; | |
16 | + | |
17 | +import java.util.*; | |
18 | +import java.util.Map.Entry; | |
19 | + | |
20 | +/** | |
21 | + * 利用HttpClient进行post请求的工具类 | |
22 | + */ | |
23 | +public class HttpClientUtil { | |
24 | + | |
25 | + public static String doPost(String url,Map<String,String> map,String charset){ | |
26 | + HttpClient httpClient = null; | |
27 | + HttpPost httpPost = null; | |
28 | + String result = null; | |
29 | + try{ | |
30 | + httpClient = new SSLClient(); | |
31 | + httpPost = new HttpPost(url); | |
32 | + //设置参数 | |
33 | + List<NameValuePair> list = new ArrayList<NameValuePair>(); | |
34 | + Iterator iterator = map.entrySet().iterator(); | |
35 | + while(iterator.hasNext()){ | |
36 | + Entry<String,String> elem = (Entry<String, String>) iterator.next(); | |
37 | + list.add(new BasicNameValuePair(elem.getKey(),elem.getValue())); | |
38 | + } | |
39 | + if(list.size() > 0){ | |
40 | + UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list,charset); | |
41 | + httpPost.setEntity(entity); | |
42 | + } | |
43 | + HttpResponse response = httpClient.execute(httpPost); | |
44 | + if(response != null){ | |
45 | + HttpEntity resEntity = response.getEntity(); | |
46 | + if(resEntity != null){ | |
47 | + result = EntityUtils.toString(resEntity,charset); | |
48 | + } | |
49 | + } | |
50 | + }catch(Exception ex){ | |
51 | + ex.printStackTrace(); | |
52 | + } | |
53 | + return result; | |
54 | + } | |
55 | + | |
56 | + | |
57 | + public static String doGet(String url,Map<String,String> params,String charset,String authorization){ | |
58 | + | |
59 | + StringBuffer sb = new StringBuffer(); | |
60 | + if(params!=null && !params.isEmpty()) { | |
61 | + Iterator<String> keys = params.keySet().iterator(); | |
62 | + while(keys.hasNext()){ | |
63 | + String key = keys.next(); | |
64 | + String value = params.get(key); | |
65 | + if(sb.length()==0)sb.append("?"); | |
66 | + else sb.append("&"); | |
67 | + sb.append(key+"="+value); | |
68 | + } | |
69 | + } | |
70 | + | |
71 | + HttpClient httpClient = null; | |
72 | + HttpGet httpGet = null; | |
73 | + String result = null; | |
74 | + try{ | |
75 | + httpClient = new SSLClient(); | |
76 | + httpGet = new HttpGet(url+sb.toString()); | |
77 | + httpGet.addHeader("Authorization", authorization); | |
78 | + HttpResponse response = httpClient.execute(httpGet); | |
79 | + if(response != null){ | |
80 | + HttpEntity resEntity = response.getEntity(); | |
81 | + if(resEntity != null){ | |
82 | + result = EntityUtils.toString(resEntity,charset); | |
83 | + } | |
84 | + } | |
85 | + }catch(Exception ex){ | |
86 | + ex.printStackTrace(); | |
87 | + } | |
88 | + return result; | |
89 | + } | |
90 | + | |
91 | + public static void main(String[] args) throws Exception { | |
92 | + | |
93 | + long start = System.currentTimeMillis(); | |
94 | + String s = doPost("https://area-qhd-api.healthbaby.com.cn:18019/findSyncData", new HashMap<String, String>(), "utf-8"); | |
95 | + long end = System.currentTimeMillis(); | |
96 | + System.out.print(end -start); | |
97 | + System.out.println(s); | |
98 | + } | |
99 | +} |
platform-common/src/main/java/com/lyms/platform/common/utils/SSLClient.java
View file @
2d03d82
1 | +package com.lyms.platform.common.utils; | |
2 | + | |
3 | +import org.apache.http.conn.ClientConnectionManager; | |
4 | +import org.apache.http.conn.scheme.Scheme; | |
5 | +import org.apache.http.conn.scheme.SchemeRegistry; | |
6 | +import org.apache.http.conn.ssl.SSLSocketFactory; | |
7 | +import org.apache.http.impl.client.DefaultHttpClient; | |
8 | + | |
9 | +import javax.net.ssl.SSLContext; | |
10 | +import javax.net.ssl.TrustManager; | |
11 | +import javax.net.ssl.X509TrustManager; | |
12 | +import java.security.cert.CertificateException; | |
13 | +import java.security.cert.X509Certificate; | |
14 | + | |
15 | +//用于进行Https请求的HttpClient | |
16 | +public class SSLClient extends DefaultHttpClient{ | |
17 | + | |
18 | + public SSLClient() throws Exception{ | |
19 | + super(); | |
20 | + SSLContext ctx = SSLContext.getInstance("TLS"); | |
21 | + X509TrustManager tm = new X509TrustManager() { | |
22 | + @Override | |
23 | + public void checkClientTrusted(X509Certificate[] chain, | |
24 | + String authType) throws CertificateException { | |
25 | + } | |
26 | + @Override | |
27 | + public void checkServerTrusted(X509Certificate[] chain, | |
28 | + String authType) throws CertificateException { | |
29 | + } | |
30 | + @Override | |
31 | + public X509Certificate[] getAcceptedIssuers() { | |
32 | + return null; | |
33 | + } | |
34 | + }; | |
35 | + ctx.init(null, new TrustManager[]{tm}, null); | |
36 | + SSLSocketFactory ssf = new SSLSocketFactory(ctx,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); | |
37 | + ClientConnectionManager ccm = this.getConnectionManager(); | |
38 | + SchemeRegistry sr = ccm.getSchemeRegistry(); | |
39 | + sr.register(new Scheme("https", 443, ssf)); | |
40 | + } | |
41 | +} |
platform-data-api/src/main/java/com/lyms/platform/data/util/AmsMessageService.java
View file @
2d03d82
1 | 1 | package com.lyms.platform.data.util; |
2 | 2 | |
3 | 3 | import com.lyms.platform.common.enums.AmsServiceTypeEnum; |
4 | +import com.lyms.platform.common.utils.HttpClientUtil; | |
4 | 5 | import com.lyms.platform.common.utils.HttpRequest; |
5 | 6 | import com.lyms.platform.common.utils.PropertiesUtils; |
6 | 7 | import com.lyms.platform.common.utils.StringUtils; |
... | ... | @@ -86,7 +87,7 @@ |
86 | 87 | params, headers); |
87 | 88 | |
88 | 89 | //调用https用这个 |
89 | - //String str = HttpClientUtil.doGet(AMS_URL,params,"utf-8",AUTHORIZATION); | |
90 | +// String str = HttpClientUtil.doGet(AMS_URL, params, "utf-8", AUTHORIZATION); | |
90 | 91 | // System.out.println(str); |
91 | 92 | ObjectMapper om = new ObjectMapper(); |
92 | 93 | MessageResponseEntity mre = null; |
... | ... | @@ -188,7 +189,7 @@ |
188 | 189 | |
189 | 190 | |
190 | 191 | public static void main(String[] args) { |
191 | - Map<String,List<MessageContent>> list = getMessageTemplateMap("248", | |
192 | + Map<String,List<MessageContent>> list = getMessageTemplateMap("1000000014", | |
192 | 193 | AmsServiceTypeEnum.CHILD_GUIDE); |
193 | 194 | |
194 | 195 | List<MessageContent> msgs = list.get("高血压"); |
platform-data-api/src/main/resources/config.properties
View file @
2d03d82
... | ... | @@ -6,8 +6,8 @@ |
6 | 6 | center_token=e0c56363-00d6-42ee-bbe0-23c553583062 |
7 | 7 | |
8 | 8 | #AMS地址 线上:http://data.api.healthbaby.com.cn/v1/messages 测试:http://data.api.stage.healthbaby.com.cn/v1/messages |
9 | -#演示地址 https://stage-rp-ams-api.healthbaby.com.cn/v1/messages | |
10 | -ams_sms=http://data.api.healthbaby.com.cn/v1/messages | |
9 | +#演示地址 https://stage-rp-data-api.healthbaby.com.cn/v1/messages | |
10 | +ams_sms=http://data.api.stage.healthbaby.com.cn/v1/messages | |
11 | 11 | |
12 | 12 | #短信当天发送时间 如16:00 |
13 | 13 | send_time=16:00 |