Explorar el Código

新增福州测试环境配置

chenweida hace 7 años
padre
commit
152575dfcf

+ 37 - 14
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/HttpClientUtil.java

@ -13,11 +13,16 @@ 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;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
@ -27,6 +32,16 @@ import java.util.Map;
@Component
public class HttpClientUtil {
    private Logger logger= LoggerFactory.getLogger(HttpClientUtil.class);
    private HttpComponentsClientHttpRequestFactory requestFactory;
    @PostConstruct
    private void init() {
        requestFactory = new HttpComponentsClientHttpRequestFactory ();
        requestFactory.setConnectionRequestTimeout(60*1000);
        requestFactory.setConnectTimeout(60*1000);
        requestFactory.setReadTimeout(60*1000);
    }
    /**
     * 发送post请求
     *
@ -35,7 +50,7 @@ public class HttpClientUtil {
     * @param chatSet 编码格式
     * @return
     */
    public  String post(String url, List<NameValuePair> params, String chatSet) {
    public String post(String url, List<NameValuePair> params, String chatSet) {
        // 创建默认的httpClient实例.
        CloseableHttpClient httpclient = HttpClients.createDefault();
        // 创建httppost
@ -78,7 +93,7 @@ public class HttpClientUtil {
     * @param chatSet 编码格式
     * @return
     */
    public  String get(String url, String chatSet) {
    public String get(String url, String chatSet) {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        try {
            // 创建httpget.
@ -119,7 +134,7 @@ public class HttpClientUtil {
     * @return
     * @throws Exception
     */
    public  String httpPost(String url, Map<String, String> params) throws Exception {
    public String httpPost(String url, Map<String, String> params) throws Exception {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        try {
            HttpPost httpPost = new HttpPost(url);
@ -154,7 +169,7 @@ public class HttpClientUtil {
     * @param params
     * @return
     */
    public  Map<String, String> getSecretParams(Map<String, String> params, String appId, String secret) {
    public Map<String, String> getSecretParams(Map<String, String> params, String appId, String secret) {
        String timestamp = Long.toString(System.currentTimeMillis());
        params.put("timestamp", timestamp);
        StringBuilder stringBuilder = new StringBuilder();
@ -177,10 +192,12 @@ public class HttpClientUtil {
    }
    public  String postBody(String url, JSONObject params) {
        RestTemplate restTemplate = new RestTemplate();
    public String postBody(String url, JSONObject params) {
        logger.info("url:"+url);
        logger.info("params:"+params);
        RestTemplate restTemplate = new RestTemplate(requestFactory);
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        MediaType type = MediaType.parseMediaType("application/json");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        org.springframework.http.HttpEntity<String> formEntity = new org.springframework.http.HttpEntity<String>(params.toString(), headers);
@ -188,10 +205,13 @@ public class HttpClientUtil {
        return ret;
    }
    public  void putBody(String url, JSONObject params) {
        RestTemplate restTemplate = new RestTemplate();
    public void putBody(String url, JSONObject params) {
        logger.info("url:"+url);
        logger.info("params:"+params);
        RestTemplate restTemplate = new RestTemplate(requestFactory);
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        MediaType type = MediaType.parseMediaType("application/json");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        org.springframework.http.HttpEntity<String> formEntity = new org.springframework.http.HttpEntity<String>(params.toString(), headers);
@ -202,17 +222,20 @@ public class HttpClientUtil {
    /**
     * 发送post请求
     *
     * @param url     请求地址
     * @param params  请求参数
     * @param url    请求地址
     * @param params 请求参数
     * @return
     */
    public String iotPostBody(String url, String params) {
        RestTemplate restTemplate = new RestTemplate();
        logger.info("url:"+url);
        logger.info("params:"+params);
        RestTemplate restTemplate = new RestTemplate(requestFactory);
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        MediaType type = MediaType.parseMediaType("application/json");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        org.springframework.http.HttpEntity<String> formEntity = new org.springframework.http.HttpEntity<String>(params, headers);
        String ret = restTemplate.postForObject(url, formEntity, String.class);
        return ret;
    }

+ 5 - 0
patient-co/patient-co-wlyy/src/main/resources/application-prod.yml

@ -138,3 +138,8 @@ Riva:
jkzl:
  zongbu:
    resturl: http://service.yihu.com:8080/WSGW/rest
    clientid: 9000424
    api:
      sms: ##短信接口
        api: MsgGW.Sms.send
        handlerId: 50641

+ 5 - 0
patient-co/patient-co-wlyy/src/main/resources/application-test-fz.yml

@ -138,3 +138,8 @@ Riva:
jkzl:
  zongbu:
    resturl: http://service.yihu.com:8080/WSGW/rest
    clientid: 9000424
    api:
      sms: ##短信接口
        api: MsgGW.Sms.send
        handlerId: 50778

+ 0 - 8
patient-co/patient-co-wlyy/src/main/resources/application.yml

@ -95,11 +95,3 @@ putMesType:
  #推送到redis消息类型
  wechat: wechat
##福州健康之路总部的接口
jkzl:
  zongbu:
    clientid: 9000424
    api:
      sms: ##短信接口
        api: MsgGW.Sms.send
        handlerId: 50778