瀏覽代碼

update http请求

GITZYY 7 月之前
父節點
當前提交
1826f28c61

+ 43 - 0
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/api/common/ThreeplatfromResultStringEnum.java

@@ -0,0 +1,43 @@
+package com.hrsk.cloud.eg.domain.api.common;
+
+import com.google.common.collect.Lists;
+import lombok.Getter;
+
+import java.util.List;
+
+/**
+ * @author zhangyy
+ * @version 1.0
+ * @description: ThreeplatfromResultCodeEnum 对接api或者平台 成功的返回值用来
+ * @date 2024/9/5 13:52
+ */
+@Getter
+public enum ThreeplatfromResultStringEnum {
+    ONE("0000",""),
+
+;
+    private String code;
+    private String msg;
+
+    ThreeplatfromResultStringEnum(String code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+    public static ThreeplatfromResultStringEnum getByCode(String code) {
+        for (ThreeplatfromResultStringEnum result : ThreeplatfromResultStringEnum.values()) {
+            if (result.getCode().equals(code)) {
+                return result;
+            }
+        }
+        return null;
+    }
+
+    public static List<String> getList() {
+        List<String> result = Lists.newArrayList();
+        for (ThreeplatfromResultStringEnum code : ThreeplatfromResultStringEnum.values()) {
+            result.add(code.getCode());
+        }
+        return result;
+    }
+}

+ 18 - 1
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/api/func/EncryptionFunction.java

@@ -62,7 +62,24 @@ public class EncryptionFunction {
      * @author zhangyy
      * @date: 2024/9/5 14:00
      */
-    public static Integer resultCodeConvertStatus(FunctionParam functionParam) {
+    public static Integer resultCodeConvertStatusInteger(FunctionParam functionParam) {
+        String value = functionParam.getInput().toString();
+        Integer result = Integer.valueOf(value);
+        if (ThreeplatfromResultCodeEnum.getList().contains(result)) {
+            return DataVoStatusEnum.SUCCESS.getCode();
+        }else  {
+            return DataVoStatusEnum.FAIL.getCode();
+        }
+    }
+
+    /**
+     * @description:  第三方返回值进行配置
+     * @param:
+     * @return: Integer
+     * @author zhangyy
+     * @date: 2024/9/5 14:00
+     */
+    public static Integer resultCodeConvertStatusString(FunctionParam functionParam) {
         String value = functionParam.getInput().toString();
         Integer result = Integer.valueOf(value);
         if (ThreeplatfromResultCodeEnum.getList().contains(result)) {

+ 2 - 1
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/api/func/ValueObjectFunctionManager.java

@@ -47,7 +47,8 @@ public class ValueObjectFunctionManager {
     private static void regist(){
         log.info("开始注册值对象函数!");
         FUNCTIONS.put("md5", EncryptionFunction::md5);
-        FUNCTIONS.put("resultCodeConvertStatus", EncryptionFunction::resultCodeConvertStatus);
+        FUNCTIONS.put("resultCodeConvertStatusInteger", EncryptionFunction::resultCodeConvertStatusInteger);
+        FUNCTIONS.put("resultCodeConvertStatusString", EncryptionFunction::resultCodeConvertStatusString);
         FUNCTIONS.put("combinationCodeSuccessIsExit",EncryptionFunction::combinationCodeSuccessIsExit);
         log.info("函数已注册!");
     }

+ 124 - 0
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/business/GenerateCheckIntoHttpApiConfigService.java

@@ -636,5 +636,129 @@ public class GenerateCheckIntoHttpApiConfigService {
          return httpApiConfig;
     }
 
+    /** 
+     * @description:  惠众api对接方式
+     * @param:  
+     * @return:  
+     * @author zhangyy
+     * @date: 2024/9/9 10:07
+     */ 
+    public void generateHuiZhongConfig(String openApiConfig){
+        EgApiDo egApiDo=new EgApiDo();
+        egApiDo.setApiCode("EG:"+BusinessPrefixEnum.CHECK_INTO_PREFIX.getCode()+":Huizhong");
+        egApiDo.setApiName(BusinessPrefixEnum.CHECK_INTO_PREFIX.getMsg());
+        egApiService.save(egApiDo);
+        JSONObject jsonObject = JSONObject.parseObject(openApiConfig);
+        EgApiEndpointDo egApiEndpointDo=new EgApiEndpointDo();
+        egApiEndpointDo.setApiCode(egApiDo.getApiCode());
+        egApiEndpointDo.setApiId(egApiDo.getId());
+        egApiEndpointDo.setApiName(jsonObject.getString("name"));
+        egApiEndpointDo.setApiConfig(HessianUtils.serialize(createHuiZhongCheckIntoBean(openApiConfig)));
+        egApiEndpointService.save(egApiEndpointDo);
+    }
+
+    /**
+     * @description:
+     * @param:
+     * @return:
+     * @author zhangyy
+     * @date: 2024/9/9 10:08
+     */
+    private HttpApiConfig createHuiZhongCheckIntoBean(String openApiConfig) {
+        JSONObject jsonObject=JSONObject.parseObject(openApiConfig);
+        HttpApiConfig httpApiConfig = new HttpApiConfig();
+        httpApiConfig.setUrl(jsonObject.getString("url")+"/api/user/check");
+        httpApiConfig.setMethod("POST");
+        httpApiConfig.setContentType(ApiPayloadTypeEnum.APPLICATION_JSON.getCode());
+        List<KeyValueObject> headers = Lists.newArrayList();
+        KeyValueObject head=new KeyValueObject();
+        head.setType(ValueObjectTypeEnum.BASIC.getType());
+        head.setKey("Content-Type");
+        head.setValue("application/json");
+        headers.add(head);
+        httpApiConfig.setHeader(headers);
+        JSONObject body=new  JSONObject();
+        KeyValueObject attackPhone=new KeyValueObject();
+        attackPhone.setType("spel");
+        attackPhone.setValue("#param.user.phoneMd5");
+        body.put("channelSource",jsonObject.getString("channelSource"));
+        body.put("phoneNo","#"+JSONObject.toJSONString(attackPhone));
+        //主体
+        httpApiConfig.setContent(JSONObject.toJSONString(body));
+
+        JSONObject resultObj=new  JSONObject();
+        KeyValueObject status=new KeyValueObject();
+        status.setType("spel");
+        status.setValue("#root[code]");
+        List<FunctionObject> functionObjects = Lists.newArrayList();
+        FunctionObject functionObject = new FunctionObject();
+        functionObject.setCode("resultCodeConvertStatusInteger");
+        functionObjects.add(functionObject);
+        status.setFunctions(functionObjects);
+        resultObj.put("status","#"+JSONObject.toJSONString(status));
+        httpApiConfig.setResult(JSONObject.toJSONString(resultObj));
+        String jsonString = JSONObject.toJSONString(httpApiConfig);
+        log.info("huizhong api {}",jsonString);
+        return httpApiConfig;
+    }
+
+    /**
+     * @description:  银华api对接方式
+     * @param:
+     * @return:
+     * @author zhangyy
+     * @date: 2024/9/9 10:07
+     */
+    public void generateYinHuaConfig(String openApiConfig){
+        EgApiDo egApiDo=new EgApiDo();
+        egApiDo.setApiCode("EG:"+BusinessPrefixEnum.CHECK_INTO_PREFIX.getCode()+":YinHua");
+        egApiDo.setApiName(BusinessPrefixEnum.CHECK_INTO_PREFIX.getMsg());
+        egApiService.save(egApiDo);
+        JSONObject jsonObject = JSONObject.parseObject(openApiConfig);
+        EgApiEndpointDo egApiEndpointDo=new EgApiEndpointDo();
+        egApiEndpointDo.setApiCode(egApiDo.getApiCode());
+        egApiEndpointDo.setApiId(egApiDo.getId());
+        egApiEndpointDo.setApiName(jsonObject.getString("name"));
+        egApiEndpointDo.setApiConfig(HessianUtils.serialize(createYinHuaCheckIntoBean(openApiConfig)));
+        egApiEndpointService.save(egApiEndpointDo);
+    }
+
+    private HttpApiConfig createYinHuaCheckIntoBean(String openApiConfig) {
+        JSONObject jsonObject=JSONObject.parseObject(openApiConfig);
+        HttpApiConfig httpApiConfig = new HttpApiConfig();
+        httpApiConfig.setUrl(jsonObject.getString("url")+"api/channel/clue/md5/_check");
+        httpApiConfig.setMethod("POST");
+        httpApiConfig.setContentType(ApiPayloadTypeEnum.APPLICATION_JSON.getCode());
+        List<KeyValueObject> headers = Lists.newArrayList();
+        KeyValueObject head=new KeyValueObject();
+        head.setType(ValueObjectTypeEnum.BASIC.getType());
+        head.setKey("Content-Type");
+        head.setValue("application/json");
+        headers.add(head);
+        httpApiConfig.setHeader(headers);
+        JSONObject body=new  JSONObject();
+        KeyValueObject attackPhone=new KeyValueObject();
+        attackPhone.setType("spel");
+        attackPhone.setValue("#param.user.phoneMd5");
+        body.put("channelSource",jsonObject.getString("channelSource"));
+        body.put("phoneNo","#"+JSONObject.toJSONString(attackPhone));
+        //主体
+        httpApiConfig.setContent(JSONObject.toJSONString(body));
+
+        JSONObject resultObj=new  JSONObject();
+        KeyValueObject status=new KeyValueObject();
+        status.setType("spel");
+        status.setValue("#root[code]");
+        List<FunctionObject> functionObjects = Lists.newArrayList();
+        FunctionObject functionObject = new FunctionObject();
+        functionObject.setCode("resultCodeConvertStatusCode");
+        functionObjects.add(functionObject);
+        status.setFunctions(functionObjects);
+        resultObj.put("status","#"+JSONObject.toJSONString(status));
+        httpApiConfig.setResult(JSONObject.toJSONString(resultObj));
+        String jsonString = JSONObject.toJSONString(httpApiConfig);
+        log.info("yinhua api {}",jsonString);
+        return httpApiConfig;
+    }
 
 }

+ 3 - 3
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/config/client/HttpTemPlateClient.java

@@ -1,6 +1,7 @@
 package com.hrsk.cloud.eg.infrastructure.config.client;
 
 import com.hrsk.cloud.eg.domain.api.HttpApi;
+import com.hrsk.cloud.eg.infrastructure.config.client.config.RetryRestTemplate;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
@@ -9,7 +10,6 @@ import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Component;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
-import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
 import java.util.Map;
@@ -23,7 +23,7 @@ import java.util.Objects;
 @Component
 public class HttpTemPlateClient {
     @Resource
-    private RestTemplate httpRestTemplate;
+    private RetryRestTemplate httpRestTemplate;
     /**
      * 请求
      * @param httpApi http api对象
@@ -40,7 +40,7 @@ public class HttpTemPlateClient {
             }
         }
         try {
-            responseEntity = httpRestTemplate.exchange(httpApi.getUrl(),
+            responseEntity = httpRestTemplate.restTemplate().exchange(httpApi.getUrl(),
                     Objects.requireNonNull(HttpMethod.resolve(httpApi.getMethod())),
                     new HttpEntity<>(httpApi.getPayload(),new HttpHeaders(headers))
                     ,

+ 6 - 6
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/config/client/config/RetryRequestConfig.java

@@ -7,17 +7,17 @@ package com.hrsk.cloud.eg.infrastructure.config.client.config;
  */
 public class RetryRequestConfig {
     //http请求timeout时的重试次数
-    int retryCount = 3;
+    int retryCount = 0;
     //http请求timeout,重试间隔时间,重试间隔时间=次数*100 ms.
-    long retryIntervalTime = 100;
+    long retryIntervalTime = 0;
     //连接池连接数量
-    int connectMaxTotal = 200;
+    int connectMaxTotal = 75;
     //连接超时时间
-    int connectTimeout = 30000;
+    int connectTimeout = 3000;
     // 数据读取超时时间,即SocketTimeout
-    int readTimeout = 30000;
+    int readTimeout = 3000;
     // 连接不够用的等待时间,不宜过长,必须设置,比如连接不够用时,时间过长将是灾难性的
-    int ConnectionRequestTimeout = 10000;
+    int ConnectionRequestTimeout = 2000;
 
     public int getRetryCount() {
         return retryCount;

+ 0 - 9
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/config/client/config/RetryRestTemplate.java

@@ -67,15 +67,6 @@ public class RetryRestTemplate {
         HttpRequestRetryHandler handler = new HttpRequestRetryHandler() {
             @Override
             public boolean retryRequest(IOException exception, int curRetryCount, HttpContext context) {
-                try {
-                    //重试延迟
-                    TimeUnit.SECONDS.sleep(curRetryCount*requestConfig.getRetryIntervalTime());
-                } catch (InterruptedException e) {
-
-                }
-                if (curRetryCount > requestConfig.getRetryCount()) {
-                    return false;
-                }
                 if (exception instanceof ConnectTimeoutException
                         || exception instanceof NoHttpResponseException || exception instanceof ConnectException) {
                     return true;

+ 9 - 0
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/service/ProductBusinessApiInfoService.java

@@ -20,4 +20,13 @@ public interface ProductBusinessApiInfoService extends IService<ProductBusinessA
      * @return
      */
   List<ProductBusinessApiInfoDo>  selectByJointCodeForList(String apiCode);
+
+    /**
+     * @description:  根据对接方式来查询
+     * @author zhangyy
+     * @date 2024/9/9 10:39
+     * @version 1.0
+     */
+    List<ProductBusinessApiInfoDo> selectByJointJonintTypeForList(String huizhong);
 }
+

+ 12 - 0
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/service/impl/ProductBusinessApiInfoServiceImpl.java

@@ -35,4 +35,16 @@ public class ProductBusinessApiInfoServiceImpl extends ServiceImpl<ProductBusine
         }
         return productBusinessApiInfoDos;
     }
+
+    @Override
+    public List<ProductBusinessApiInfoDo> selectByJointJonintTypeForList(String apiCode) {
+        LambdaQueryWrapper<ProductBusinessApiInfoDo> queryChainWrapper=new LambdaQueryWrapper<>();
+        queryChainWrapper.eq(ProductBusinessApiInfoDo::getJointType,apiCode);
+        queryChainWrapper.orderByDesc(ProductBusinessApiInfoDo::getCreateTime);
+        List<ProductBusinessApiInfoDo> productBusinessApiInfoDos = baseMapper.selectList(queryChainWrapper);
+        if (CollectionUtils.isEmpty(productBusinessApiInfoDos)) {
+            return Collections.emptyList();
+        }
+        return productBusinessApiInfoDos;
+    }
 }

+ 62 - 0
start/src/test/java/StartTest.java

@@ -87,6 +87,20 @@ public class StartTest {
         generateCHeckIntoHttpApiConfigService.generateRxkConfig(productBusinessApiInfoDos.get(0).getThreeSystemConfig());
     }
 
+    @Test
+    public void createHuiZhonApiTest(){
+        List<ProductBusinessApiInfoDo> productBusinessApiInfoDos = productBusinessApiInfoService.selectByJointJonintTypeForList("Huizhong");
+        generateCHeckIntoHttpApiConfigService.generateHuiZhongConfig(productBusinessApiInfoDos.get(0).getThreeSystemConfig());
+    }
+
+    @Test
+    public void createYinHuaApiTest(){
+        List<ProductBusinessApiInfoDo> productBusinessApiInfoDos = productBusinessApiInfoService.selectByJointJonintTypeForList("YinHua");
+        generateCHeckIntoHttpApiConfigService.generateRxkConfig(productBusinessApiInfoDos.get(0).getThreeSystemConfig());
+    }
+
+
+
     @Test
     public void apiHuiRonTest(){
       Long apiId= 441293753667392L;
@@ -227,6 +241,54 @@ public class StartTest {
         checkin.setUser(user);
         apiGateway.checkIntoRequest(checkin);
     }
+
+
+    /**
+     * @description:  惠众 api 测试
+     * @param:
+     * @return:
+     * @author zhangyy
+     * @date: 2024/9/5 14:34
+     */
+    @Test
+    public void huiZhonApiTest(){
+        Long apiId= 441421777748032L;
+        UserInBaseInfoDto user =new UserInBaseInfoDto();
+        user.setPhoneMd5("b5500dfab55f42b340d31326561e16cb");
+        user.setCompanyCity("重庆");
+        PlanDto  plan =new PlanDto();
+        plan.setApiId(apiId);
+        plan.setBid("aff1c7b30d8b240826030235business");
+        CheckIntoParamDto checkin =new CheckIntoParamDto();
+        checkin.setPlan(plan);
+        checkin.setUser(user);
+        apiGateway.checkIntoRequest(checkin);
+    }
+
+    /**
+     * @description:  银华咨询 api 测试
+     * @param:
+     * @return:
+     * @author zhangyy
+     * @date: 2024/9/5 14:34
+     */
+    @Test
+    public void yinHuaApiTest(){
+        Long apiId= 441338278858304L;
+        UserInBaseInfoDto user =new UserInBaseInfoDto();
+        user.setPhoneMd5("b5500dfab55f42b340d31326561e16cb");
+        user.setCompanyCity("重庆");
+        PlanDto  plan =new PlanDto();
+        plan.setApiId(apiId);
+        plan.setBid("aff1c7b30d8b240826030235business");
+        CheckIntoParamDto checkin =new CheckIntoParamDto();
+        checkin.setPlan(plan);
+        checkin.setUser(user);
+        apiGateway.checkIntoRequest(checkin);
+    }
+
+
+
     @Test
     public void spel(){
         Map<String,Object> map =new HashMap<>();