|
|
@@ -9,7 +9,6 @@ import com.ydtech.modules.order.entity.api.huatai.HuaTaiBaseRequest;
|
|
|
import com.ydtech.modules.order.entity.api.huatai.HuaTaiBaseResponse;
|
|
|
import com.ydtech.modules.order.entity.api.huatai.HuaTaiEncryptReq;
|
|
|
import com.ydtech.modules.order.entity.api.huatai.HuaTaiEncryptRes;
|
|
|
-import com.ydtech.modules.order.entity.api.huatai.constants.HuaTaiTransCode;
|
|
|
import com.ydtech.modules.order.entity.api.huatai.request.*;
|
|
|
import com.ydtech.modules.order.entity.api.huatai.response.*;
|
|
|
import com.ydtech.modules.order.utils.AESUtilsWithDataBase;
|
|
|
@@ -19,6 +18,7 @@ import com.ydtech.utils.RSA.RSAUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
|
@@ -28,7 +28,9 @@ import org.springframework.util.ObjectUtils;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.security.SecureRandom;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -47,6 +49,8 @@ public class HuaTaiRequestApiComponents {
|
|
|
|
|
|
private final RestTemplate restTemplate;
|
|
|
|
|
|
+ private final StringRedisTemplate redisTemplate;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 加密请求
|
|
|
@@ -115,6 +119,8 @@ public class HuaTaiRequestApiComponents {
|
|
|
return t;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
String selfPrivateKe = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAME61d/VP+ejXcs67Lm2L7935IAMeezyEC" +
|
|
|
"/f4uOEMWxBFseTe0eGdQ1fsjxvbnnvoBWaCtp59LuOenIHb31" +
|
|
|
@@ -148,6 +154,9 @@ public class HuaTaiRequestApiComponents {
|
|
|
private <Q extends HuaTaiBaseRequest, S extends HuaTaiBaseResponse> S request(Q request, Class<S> tClass, boolean verify,
|
|
|
String domain, String insuredCode) {
|
|
|
String url = domain;
|
|
|
+ //拼接voken的参数
|
|
|
+ url=getAllUrl(url);
|
|
|
+
|
|
|
S response = post(request, url, tClass, insuredCode);
|
|
|
if (verify) {
|
|
|
validationResults(response);
|
|
|
@@ -160,8 +169,7 @@ public class HuaTaiRequestApiComponents {
|
|
|
* @param <S> Response 响应体
|
|
|
* 常规
|
|
|
*/
|
|
|
- private <Q extends HuaTaiBaseRequest, S extends HuaTaiBaseResponse> S routineRequest(Q request, Class<S> tClass, boolean verify,
|
|
|
- String insuredCode) {
|
|
|
+ private <Q extends HuaTaiBaseRequest, S extends HuaTaiBaseResponse> S routineRequest(Q request, Class<S> tClass, boolean verify, String insuredCode) {
|
|
|
return request(request, tClass, verify, properties.getBaseUrl(), insuredCode);
|
|
|
}
|
|
|
|
|
|
@@ -280,4 +288,76 @@ public class HuaTaiRequestApiComponents {
|
|
|
}
|
|
|
return sb.toString();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/6/25 17:29
|
|
|
+ * @Description: 访问车险核心系统API时,需要在请求头或请求参数中传voken。
|
|
|
+ * 添加获取voken的接口 放入到redis中, 2小时,过期后需重新获取。
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public void setVoken(){
|
|
|
+ String url = properties.getTokenUrl();
|
|
|
+ if(StringUtils.isBlank(url)){
|
|
|
+ throw new SystemException("获取voken地址不能为空");
|
|
|
+ }
|
|
|
+ String jkey = properties.getHuaTaiKey();
|
|
|
+ if(StringUtils.isBlank(url)){
|
|
|
+ throw new SystemException("jkey不能为空");
|
|
|
+ }
|
|
|
+ String key = properties.getKey();
|
|
|
+ if(StringUtils.isBlank(url)){
|
|
|
+ throw new SystemException("key不能为空");
|
|
|
+ }
|
|
|
+ //获取voken
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
+ params.put("key", key);
|
|
|
+ params.put("jkey", jkey);
|
|
|
+ try{
|
|
|
+ url=url+"?key={key}&jkey={jkey}";
|
|
|
+ String result = restTemplate.getForObject(url, String.class, params);
|
|
|
+ if(StringUtils.isNotBlank(result)){
|
|
|
+ //放入到redis中 2小时
|
|
|
+ redisTemplate.opsForValue().set("HT_GET_VOKEN_STR", result, 2*60*60);
|
|
|
+ }
|
|
|
+ }catch(Exception e){
|
|
|
+ throw new SystemException("获取voken异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/6/25 17:56
|
|
|
+ * @Description: 获取voken
|
|
|
+ */
|
|
|
+ public String getVotoken(){
|
|
|
+ String voken = redisTemplate.opsForValue().get("HT_GET_VOKEN_STR");
|
|
|
+ /**
|
|
|
+ String unicodeSpace = "\u0000";
|
|
|
+ if(voken!=null && !"".equals(voken) && voken.contains(unicodeSpace)){
|
|
|
+ voken= voken.replaceAll(unicodeSpace, "");
|
|
|
+ if(StringUtils.isBlank(voken)){
|
|
|
+ //重新放入,重新获取
|
|
|
+ setVoken();
|
|
|
+ voken = redisTemplate.opsForValue().get("HT_GET_VOKEN_STR");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ **/
|
|
|
+ if(StringUtils.isBlank(voken)){
|
|
|
+ //重新放入,重新获取
|
|
|
+ setVoken();
|
|
|
+ voken = redisTemplate.opsForValue().get("HT_GET_VOKEN_STR");
|
|
|
+ }
|
|
|
+ return voken;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/6/25 18:01
|
|
|
+ * @Description: 添加voken参数的路径
|
|
|
+ */
|
|
|
+ private String getAllUrl(String url) {
|
|
|
+ return url+"?voken="+getVotoken();
|
|
|
+ }
|
|
|
}
|