|
@@ -3,6 +3,7 @@ package com.qmth.themis.business.util;
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
+import org.apache.http.Consts;
|
|
import org.apache.http.HttpEntity;
|
|
import org.apache.http.HttpEntity;
|
|
import org.apache.http.HttpResponse;
|
|
import org.apache.http.HttpResponse;
|
|
import org.apache.http.client.HttpClient;
|
|
import org.apache.http.client.HttpClient;
|
|
@@ -130,6 +131,35 @@ public class HttpUtil {
|
|
return getRespString(post);
|
|
return getRespString(post);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * get 请求
|
|
|
|
+ *
|
|
|
|
+ * @param url
|
|
|
|
+ * @param params
|
|
|
|
+ * @param secret
|
|
|
|
+ * @param timestamp
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static String get(String url, Map<String, Object> params, String secret, Long timestamp) throws IOException {
|
|
|
|
+ // 构建请求参数
|
|
|
|
+ List<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();
|
|
|
|
+ if (params != null) {
|
|
|
|
+ for (String key : params.keySet()) {
|
|
|
|
+ pairs.add(new BasicNameValuePair(key, String.valueOf(params.get(key))));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String str = EntityUtils.toString(new UrlEncodedFormEntity(pairs, Consts.UTF_8));//转换为键值对
|
|
|
|
+ HttpGet get = new HttpGet(url + "?" + str);
|
|
|
|
+ if (Objects.nonNull(secret)) {
|
|
|
|
+ get.setHeader(SystemConstant.HEADER_AUTHORIZATION, secret);
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(timestamp)) {
|
|
|
|
+ get.setHeader(SystemConstant.HEADER_TIME, String.valueOf(timestamp));
|
|
|
|
+ }
|
|
|
|
+ // 执行请求,获取响应
|
|
|
|
+ return getRespString(get);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取响应信息
|
|
* 获取响应信息
|
|
*
|
|
*
|