Selaa lähdekoodia

add xinlu api

GITZYY 7 kuukautta sitten
vanhempi
commit
8892a5110a

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

@@ -1,9 +1,12 @@
 package com.hrsk.cloud.eg.domain.api.func;
 
 
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
 import com.hrsk.cloud.eg.domain.api.FunctionParam;
 
 import java.security.MessageDigest;
+import java.util.List;
 import java.util.Objects;
 
 /**
@@ -46,4 +49,22 @@ public class EncryptionFunction {
             return null;
         }
     }
+    public static String outPrint(FunctionParam input) {
+        JSONObject.toJSONString(input);
+        System.out.println(input.getInput());
+        return "";
+    }
+
+
+
+    public static String md5Sign(FunctionParam functionParam) {
+        functionParam.setInput(JSON.toJSONString(functionParam));
+
+        List<Object> extArg = functionParam.getExtArg();
+        StringBuilder builder = new StringBuilder();
+        for (Object o : extArg) {
+            builder.append(o.toString());
+        }
+        return null;
+    }
 }

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

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

+ 6 - 1
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/api/resolver/vo/ValueObjectResolver.java

@@ -21,7 +21,12 @@ public interface ValueObjectResolver {
      */
     Object resolve(ValueObject valueObject, ApiContext context);
 
-
+    /**
+     * 解析
+     * @param valueObject 解析对象
+     * @param context 上下文
+     * @return 解析结果
+     */
     Object resolve(ValueObject valueObject, Map<String,Object> context);
 }
 

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

@@ -1,10 +1,10 @@
 package com.hrsk.cloud.eg.infrastructure.business;
 
+import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.google.common.collect.Lists;
 import com.hrsk.cloud.eg.constant.BusinessPrefixEnum;
-import com.hrsk.cloud.eg.domain.api.HttpApiConfig;
-import com.hrsk.cloud.eg.domain.api.KeyValueObject;
+import com.hrsk.cloud.eg.domain.api.*;
 import com.hrsk.cloud.eg.domain.api.common.ApiPayloadTypeEnum;
 import com.hrsk.cloud.eg.domain.api.common.ValueObjectTypeEnum;
 import com.hrsk.cloud.eg.infrastructure.config.client.HessianUtils;
@@ -16,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -98,7 +99,7 @@ public class GenerateCheckIntoHttpApiConfigService {
     }
 
     /** 
-     * @description: 庆鱼api转化
+     * @description: 庆鱼api转化 !!!暂时不支持
      * @param:
      * @return:  
      * @author zhangyy
@@ -119,15 +120,72 @@ public class GenerateCheckIntoHttpApiConfigService {
     }
 
     /**
-     * @description: 庆鱼创建api
+     * @description: 鑫鹿api对接方式
+     * @author zhangyy
+     * @date 2024/9/5 11:06
+     * @version 1.0
+     */
+    public void generateXinLuConfig(String openApiConfig) {
+        EgApiDo egApiDo=new EgApiDo();
+        egApiDo.setApiCode("EG:"+BusinessPrefixEnum.CHECK_INTO_PREFIX.getCode()+":CRM_XL:7");
+        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(createXinLuApiCheckIntoBean(openApiConfig)));
+        egApiEndpointService.save(egApiEndpointDo);
+    }
+
+    /**
+     * @description: 鑫鹿api转化
+     * @author zhangyy
+     * @date 2024/9/5 11:07
+     * @version 1.0
+     */
+    private HttpApiConfig createXinLuApiCheckIntoBean(String openApiConfig) {
+        JSONObject jsonObject=JSONObject.parseObject(openApiConfig);
+        HttpApiConfig httpApiConfig = new HttpApiConfig();
+        httpApiConfig.setUrl(jsonObject.getString("checkUrl"));
+        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("phone","#"+JSONObject.toJSONString(attackPhone));
+        body.put("type",2);
+        body.put("tenantId",jsonObject.getString("tenantId"));
+        //主体
+        httpApiConfig.setContent(JSONObject.toJSONString(body));
+        JSONObject resultObj=new  JSONObject();
+        KeyValueObject status=new KeyValueObject();
+        status.setType("spel");
+        status.setValue("#root[code]");
+        resultObj.put("status","#"+JSONObject.toJSONString(status));
+        httpApiConfig.setResult(JSONObject.toJSONString(resultObj));
+        String jsonString = JSONObject.toJSONString(httpApiConfig);
+        log.info("xinLu api  {}",jsonString);
+        return httpApiConfig;
+    }
+
+    /**
+     * @description: 庆鱼创建api !!! 暂时不支持
      * @param:
      * @return:
      * @author zhangyy
      * @date: 2024/9/4 14:58
      */
     private HttpApiConfig createQinYuCheckIntoBean(String openApiConfig) {
-       // todo
-//        {"url":"https://king.cdsxlc.cn/saasbg","key":"fluxZhudai*_key","tenantId":"1637995763721633794","trafficPlatformId":"1636573781981466625"}
         JSONObject jsonObject=JSONObject.parseObject(openApiConfig);
         HttpApiConfig httpApiConfig = new HttpApiConfig();
         httpApiConfig.setUrl(jsonObject.getString("url")+"/openapi/interface/query/phones");
@@ -142,17 +200,36 @@ public class GenerateCheckIntoHttpApiConfigService {
         httpApiConfig.setHeader(headers);
         JSONObject body=new  JSONObject();
 
-        KeyValueObject attackPhone=new KeyValueObject();
-        attackPhone.setType("spel");
-        attackPhone.setValue("#param.user.phoneMd5");
-        KeyValueObject merchantNo=new KeyValueObject();
-
-        merchantNo.setType("spel");
-        merchantNo.setValue("#param.user.companyCity");
-
-        body.put("data","#"+JSONObject.toJSONString(attackPhone));
-        body.put("sign","#"+JSONObject.toJSONString(merchantNo));
-        body.put("trafficPlatformId","#"+JSONObject.toJSONString(merchantNo));
+        KeyValueObject data=new KeyValueObject();
+        data.setType("spel");
+        JSONObject dataJson=new JSONObject();
+        List<JSONObject> attackPhone=new ArrayList<>();
+        JSONObject phoneJson=new JSONObject();
+        phoneJson.put("phone","#param.user.phoneMd5");
+        attackPhone.add(phoneJson);
+        dataJson.put("customers",attackPhone);
+        dataJson.put("tenantId",jsonObject.getString("tenantId"));
+        data.setValue("#"+JSONObject.toJSONString(dataJson));
+        FunctionObject functionObject=new FunctionObject();
+        functionObject.setCode("outPrint");
+        data.setFunctions(Lists.newArrayList(functionObject));
+//        log.info("qin yu input {}", JSONObject.toJSONString(data));
+        body.put("trafficPlatformId",jsonObject.getString("trafficPlatformId"));
+        body.put("data","#"+JSONObject.toJSONString(data));
+        List<ValueObject> args=Lists.newArrayList();
+        ValueObject valueObject=new ValueObject();
+        valueObject.setValue("#param.content.data");
+        args.add(valueObject);
+        ValueObject valueObject1=new ValueObject();
+        valueObject1.setValue("#param.content.trafficPlatformId");
+        args.add(valueObject1);
+        ValueObject valueObject2=new ValueObject();
+        valueObject1.setValue(jsonObject.getString("key"));
+        args.add(valueObject2);
+        FunctionObject functionObject1=new FunctionObject();
+        functionObject1.setCode("md5Sign");
+        functionObject1.setArgs(args);
+        body.put("sign","#"+JSONObject.toJSONString(functionObject1));
         //主体
         httpApiConfig.setContent(JSONObject.toJSONString(body));
         JSONObject resultObj=new  JSONObject();

+ 1 - 0
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/exception/ExceptionAdvice.java

@@ -1,6 +1,7 @@
 package com.hrsk.cloud.eg.infrastructure.exception;
 
 import com.hrsk.cloud.eg.domain.common.constant.ResultCode;
+import com.hrsk.cloud.eg.vo.response.DefaultResponseVo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.context.properties.bind.BindException;
 import org.springframework.http.HttpStatus;

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

@@ -1,6 +1,8 @@
 import com.alibaba.fastjson2.JSONObject;
 import com.hrsk.cloud.eg.Application;
 import com.hrsk.cloud.eg.domain.api.ApiGateway;
+import com.hrsk.cloud.eg.domain.api.KeyValueObject;
+import com.hrsk.cloud.eg.domain.api.resolver.vo.SpelValueObjectResolver;
 import com.hrsk.cloud.eg.dto.data.CheckIntoParamDto;
 import com.hrsk.cloud.eg.dto.data.egPlan.PlanDto;
 import com.hrsk.cloud.eg.dto.data.user.UserInBaseInfoDto;
@@ -58,6 +60,13 @@ public class StartTest {
     }
 
 
+    @Test
+    public void createQinYuApiTest(){
+        List<ProductBusinessApiInfoDo> productBusinessApiInfoDos = productBusinessApiInfoService.selectByJointCodeForList("4");
+//        String jsonString = JSONObject.toJSONString(productBusinessApiInfoDos.get(0).getThreeSystemConfig());
+        generateCHeckIntoHttpApiConfigService.generateQinYuConfig(productBusinessApiInfoDos.get(0).getThreeSystemConfig());
+    }
+
 
     @Test
     public void apiHuiRonTest(){
@@ -89,6 +98,28 @@ public class StartTest {
         apiGateway.checkIntoRequest(checkin);
     }
 
+    /** 
+     * @description: 庆鱼暂时不支持解析 !!!
+     * @param:  
+     * @return:  
+     * @author zhangyy
+     * @date: 2024/9/5 11:03
+     */ 
+    @Test
+    public void qinYuApiRsaTest(){
+        Long apiId= 441333216126016L;
+        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(){