|
@@ -1,29 +1,11 @@
|
|
|
package com.jpsoft.smart.modules.common.utils;
|
|
|
|
|
|
-import cn.hutool.core.date.DatePattern;
|
|
|
-import cn.hutool.core.date.DateTime;
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.aliyun.oss.common.utils.HttpUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.http.HttpEntity;
|
|
|
-import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
-import org.apache.http.client.methods.HttpDelete;
|
|
|
-import org.apache.http.entity.StringEntity;
|
|
|
-import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
-import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
-import org.apache.http.impl.client.HttpClients;
|
|
|
-import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.math.BigInteger;
|
|
|
-import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
/**
|
|
@@ -33,51 +15,52 @@ import java.util.HashMap;
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
public class LApiUtil {
|
|
|
-
|
|
|
+ private final static int TIMEOUT = 10*1000;
|
|
|
|
|
|
public static JSONObject PostRequest(String url,HashMap map){
|
|
|
-
|
|
|
-
|
|
|
- String body = HttpRequest.post(url).body(new JSONObject(map).toJSONString()).execute().body();
|
|
|
+ String body = HttpRequest.post(url)
|
|
|
+ .timeout(TIMEOUT)
|
|
|
+ .body(new JSONObject(map).toJSONString()).execute().body();
|
|
|
JSONObject jsonbody = JSONObject.parseObject(body);
|
|
|
return jsonbody;
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public static JSONObject GetRequest(String url) throws Exception{
|
|
|
+ String body = HttpRequest.get(url)
|
|
|
+ .timeout(TIMEOUT)
|
|
|
+ .execute().body();
|
|
|
|
|
|
- String body = HttpRequest.get(url).execute().body();
|
|
|
JSONObject jsonbody = JSONObject.parseObject(body);
|
|
|
return jsonbody;
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
- public static JSONObject DeletRequest(String url) {
|
|
|
- String body = HttpRequest.delete(url).execute().body();
|
|
|
+
|
|
|
+ public static JSONObject DeleteRequest(String url) {
|
|
|
+ String body = HttpRequest.delete(url)
|
|
|
+ .timeout(TIMEOUT)
|
|
|
+ .execute().body();
|
|
|
JSONObject jsonbody = JSONObject.parseObject(body);
|
|
|
return jsonbody;
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public static JSONObject putRequest(String url){
|
|
|
- String body = HttpRequest.put(url).execute().body();
|
|
|
+ String body = HttpRequest.put(url)
|
|
|
+ .timeout(TIMEOUT)
|
|
|
+ .execute().body();
|
|
|
+
|
|
|
JSONObject jsonbody = JSONObject.parseObject(body);
|
|
|
return jsonbody;
|
|
|
}
|
|
|
|
|
|
public static JSONObject putRequest(String url,HashMap map){
|
|
|
- String body = HttpRequest.put(url).body(new JSONObject(map).toJSONString()).execute().body();
|
|
|
+ String body = HttpRequest.put(url)
|
|
|
+ .timeout(TIMEOUT)
|
|
|
+ .body(new JSONObject(map).toJSONString()).execute().body();
|
|
|
+
|
|
|
JSONObject jsonbody = JSONObject.parseObject(body);
|
|
|
return jsonbody;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
public static JSONObject getResponse(JSONObject dataJson) throws Exception{
|
|
|
-
|
|
|
if (dataJson.getInteger("ResponseCode") == 1){
|
|
|
throw new Exception("通用错误");
|
|
|
}
|