|
@@ -4,19 +4,21 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.zksy.common.domain.response.BaseResponse;
|
|
import com.zksy.common.domain.response.BaseResponse;
|
|
|
|
|
+import com.zksy.common.exception.CommonException;
|
|
|
import com.zksy.common.utils.BeanUtils;
|
|
import com.zksy.common.utils.BeanUtils;
|
|
|
import com.zksy.data.config.XhConfigProperty;
|
|
import com.zksy.data.config.XhConfigProperty;
|
|
|
|
|
+import com.zksy.data.constant.RedisKeyConstant;
|
|
|
import com.zksy.data.domain.po.BasePo;
|
|
import com.zksy.data.domain.po.BasePo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import okhttp3.HttpUrl;
|
|
|
|
|
-import okhttp3.OkHttpClient;
|
|
|
|
|
-import okhttp3.Request;
|
|
|
|
|
-import okhttp3.Response;
|
|
|
|
|
|
|
+import okhttp3.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
@Component
|
|
@Component
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -27,10 +29,13 @@ public class XhRequestUtil {
|
|
|
private OkHttpClient okHttpClient;
|
|
private OkHttpClient okHttpClient;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ObjectMapper objectMapper;
|
|
private ObjectMapper objectMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RedisTemplate<String,String> redisTemplate;
|
|
|
|
|
|
|
|
public <T extends BaseResponse,K extends BasePo> List<K> httpRequestByUniCode(String uniCode, String address,
|
|
public <T extends BaseResponse,K extends BasePo> List<K> httpRequestByUniCode(String uniCode, String address,
|
|
|
Class<T> responseClass,
|
|
Class<T> responseClass,
|
|
|
Class<K> entityClass) {
|
|
Class<K> entityClass) {
|
|
|
|
|
+ log.info("正在同步:{}下的:{}",address,uniCode);
|
|
|
ArrayList<K> resList = new ArrayList<>();
|
|
ArrayList<K> resList = new ArrayList<>();
|
|
|
if (StrUtil.isEmpty(uniCode)) {
|
|
if (StrUtil.isEmpty(uniCode)) {
|
|
|
log.warn("统一社会信用代码为空");
|
|
log.warn("统一社会信用代码为空");
|
|
@@ -76,7 +81,7 @@ public class XhRequestUtil {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
private Boolean isEnd = false;
|
|
private Boolean isEnd = false;
|
|
|
- public String testHttpRequest(String uniCode,String address) {
|
|
|
|
|
|
|
+ public String testHttpRequest(String uniCode,String address,String paramsValue) {
|
|
|
if (isEnd) {
|
|
if (isEnd) {
|
|
|
isEnd = false;
|
|
isEnd = false;
|
|
|
throw new RuntimeException("已经找到请求结构,不用继续了");
|
|
throw new RuntimeException("已经找到请求结构,不用继续了");
|
|
@@ -90,7 +95,7 @@ public class XhRequestUtil {
|
|
|
.host(xhConfigProperty.getHost())
|
|
.host(xhConfigProperty.getHost())
|
|
|
.port(Integer.valueOf(xhConfigProperty.getPort()))
|
|
.port(Integer.valueOf(xhConfigProperty.getPort()))
|
|
|
.addPathSegment(address)
|
|
.addPathSegment(address)
|
|
|
- .addQueryParameter("UNISCID", uniCode)
|
|
|
|
|
|
|
+ .addQueryParameter(paramsValue, uniCode)
|
|
|
.build();
|
|
.build();
|
|
|
Request request = new Request.Builder()
|
|
Request request = new Request.Builder()
|
|
|
.url(url)
|
|
.url(url)
|
|
@@ -117,4 +122,77 @@ public class XhRequestUtil {
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public void requestXinyonghuanhuai(){
|
|
|
|
|
+ refreshToken();
|
|
|
|
|
+ HttpUrl url = new HttpUrl.Builder()
|
|
|
|
|
+ .scheme("http")
|
|
|
|
|
+ .host("59.231.127.12")
|
|
|
|
|
+ .addPathSegment("interface/v1/doublePublic/findLicensingList")
|
|
|
|
|
+ .build();
|
|
|
|
|
+ Map<String, Object> requestBodyMap = new HashMap<>();
|
|
|
|
|
+ requestBodyMap.put("entityCode", "91431227MA4QPUTX06");
|
|
|
|
|
+// requestBodyMap.put("entityName", "滴滴");
|
|
|
|
|
+// requestBodyMap.put("entityCodeAdd", "12345");
|
|
|
|
|
+// requestBodyMap.put("wsh", "");
|
|
|
|
|
+// requestBodyMap.put("upDateBegin", "2023-01-01 00:00:00");
|
|
|
|
|
+// requestBodyMap.put("upDateEnd", "2023-12-01 00:00:00");
|
|
|
|
|
+// requestBodyMap.put("size", 10);
|
|
|
|
|
+// requestBodyMap.put("page", 1);
|
|
|
|
|
+ try {
|
|
|
|
|
+ var json = objectMapper.writeValueAsString(requestBodyMap);
|
|
|
|
|
+ RequestBody requestBody = RequestBody.create(json, MediaType.parse("application/json; charset=utf-8"));
|
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
|
+ .url(url)
|
|
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
|
|
+ .header("Token", redisTemplate.opsForValue().get(RedisKeyConstant.HUAIHUA_TOKEN_KEY))
|
|
|
|
|
+ .post(requestBody)
|
|
|
|
|
+ .build();
|
|
|
|
|
+ Response response = okHttpClient.newCall(request).execute();
|
|
|
|
|
+ if (!response.isSuccessful()) {
|
|
|
|
|
+ throw new CommonException("当前接口请求失败",5000);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ObjectUtil.isEmpty(response.body())) {
|
|
|
|
|
+ throw new CommonException("当前接口请求失败",5000);
|
|
|
|
|
+ }
|
|
|
|
|
+ String s = response.body().string();
|
|
|
|
|
+ log.info(s);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void refreshToken() {
|
|
|
|
|
+ HttpUrl url = new HttpUrl.Builder()
|
|
|
|
|
+ .scheme("http")
|
|
|
|
|
+ .host("59.231.127.12")
|
|
|
|
|
+ .addPathSegment("interface/v1/auth/getToken")
|
|
|
|
|
+ .addQueryParameter("refreshToken", "sV7l0nLP2Ui157VRd1TvIkSpfixf22ij")
|
|
|
|
|
+ .build();
|
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
|
+ .url(url)
|
|
|
|
|
+ .get()
|
|
|
|
|
+ .build();
|
|
|
|
|
+ try {
|
|
|
|
|
+ Response response = okHttpClient.newCall(request).execute();
|
|
|
|
|
+ if (!response.isSuccessful()) {
|
|
|
|
|
+ throw new CommonException("刷新token的接口请求失败",5000);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ObjectUtil.isEmpty(response.body())) {
|
|
|
|
|
+ throw new CommonException("刷新token的接口出现问题",5000);
|
|
|
|
|
+ }
|
|
|
|
|
+ String s = response.body().string();
|
|
|
|
|
+ Map map = objectMapper.readValue(s, Map.class);
|
|
|
|
|
+ if((Integer) map.get("status") != 0){
|
|
|
|
|
+ throw new CommonException("刷新token的接口返回异常",5000);
|
|
|
|
|
+ }
|
|
|
|
|
+ String token = (String) map.get("data");
|
|
|
|
|
+ if(StrUtil.isEmpty(token)){
|
|
|
|
|
+ throw new CommonException("刷新token的接口返回异常",5000);
|
|
|
|
|
+ }
|
|
|
|
|
+ redisTemplate.opsForValue().set(RedisKeyConstant.HUAIHUA_TOKEN_KEY,token);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|