Prechádzať zdrojové kódy

add 对接格鑫金服

GITZYY 9 mesiacov pred
rodič
commit
9cf0adee5f

+ 3 - 1
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/api/HttpApi.java

@@ -142,7 +142,9 @@ public class HttpApi implements Api {
      * @param context 上下文
      */
     private void loadBody(ApiContext context){
-        if(StringUtils.equals(httpApiConfig.getContentType(), ApiPayloadTypeEnum.APPLICATION_JSON.getCode())){
+        if(StringUtils.equals(httpApiConfig.getContentType(), ApiPayloadTypeEnum.APPLICATION_JSON.getCode())
+        ||StringUtils.equals(httpApiConfig.getContentType(),ApiPayloadTypeEnum.APPLICATION_X_WWW_FORM_URLENCODED.getCode())
+        ){
             payload = Objects.toString(ApiPayloadResolverManage.getInstance().resolve(httpApiConfig.getContentType(),httpApiConfig.getContent(),context),"");
         }else{
             throw new BizException("不支持的请求体类型!");

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

@@ -9,7 +9,8 @@ import lombok.Getter;
  **/
 @Getter
 public enum ApiPayloadTypeEnum {
-    APPLICATION_JSON("application/json");
+    APPLICATION_JSON("application/json"),
+    APPLICATION_X_WWW_FORM_URLENCODED("application/x-www-form-urlencoded; charset=UTF-8");
 
     /**
      * 编码

+ 3 - 0
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/api/resolver/payload/ApiJsonPayloadResolver.java

@@ -30,6 +30,9 @@ public class ApiJsonPayloadResolver implements ApiPayloadResolver {
 
     @Override
     public Object resolve(String jsonTemplate, ApiContext context) {
+        if (StringUtils.isBlank(jsonTemplate)) {
+            return new Object();
+        }
         JsonElement jsonElement = GsonUtils.fromJson(jsonTemplate, JsonElement.class);
         traverseJson(jsonElement,jsonElement,null,context,0);
         return jsonElement.toString();

+ 2 - 0
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/api/resolver/payload/ApiPayloadResolverManage.java

@@ -54,6 +54,8 @@ public class ApiPayloadResolverManage {
     private static void regist(){
         log.info("开始注册Payload解析器!");
         RESOLVER_MAP.put(ApiPayloadTypeEnum.APPLICATION_JSON.getCode(),new ApiJsonPayloadResolver());
+        RESOLVER_MAP.put(ApiPayloadTypeEnum.APPLICATION_X_WWW_FORM_URLENCODED.getCode(),new ApiJsonPayloadResolver());
+
 
     }
 }

+ 1 - 0
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/api/resolver/result/ApiResultResolverManage.java

@@ -56,6 +56,7 @@ public class ApiResultResolverManage {
     private static void regist(){
         log.info("开始注册Payload解析器!");
         RESOLVER_MAP.put(ApiPayloadTypeEnum.APPLICATION_JSON.getCode(),new ApiJsonResultResolver());
+        RESOLVER_MAP.put(ApiPayloadTypeEnum.APPLICATION_X_WWW_FORM_URLENCODED.getCode(),new ApiJsonResultResolver());
 
     }
 }

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

@@ -1,9 +1,7 @@
 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.google.gson.JsonObject;
 import com.hrsk.cloud.eg.constant.BusinessPrefixEnum;
 import com.hrsk.cloud.eg.domain.api.*;
 import com.hrsk.cloud.eg.domain.api.common.ApiPayloadTypeEnum;
@@ -1128,9 +1126,9 @@ public class GenerateCheckIntoHttpApiConfigService {
         body.put("mobile_md5","#"+JSONObject.toJSONString(attackPhone));
 
         KeyValueObject city=new KeyValueObject();
-        attackPhone.setType("spel");
-        attackPhone.setValue("#param.user.companyCity");
-        body.put("city","#"+JSONObject.toJSONString(attackPhone));
+        city.setType("spel");
+        city.setValue("#param.user.companyCity");
+        body.put("city","#"+JSONObject.toJSONString(city));
 
         //主体
         httpApiConfig.setContent(JSONObject.toJSONString(body));
@@ -1149,4 +1147,66 @@ public class GenerateCheckIntoHttpApiConfigService {
         log.info("Hamigua api {}",jsonString);
         return httpApiConfig;
     }
+    
+    /**
+     * @description:  灏瀚无崟
+     * @author zhangyy
+     * @date 2024/9/9 16:22 
+     * @version 1.0 
+     */
+    public void generateHaohanwuyinConfig(String openApiConfig) {
+        EgApiDo egApiDo=new EgApiDo();
+        egApiDo.setApiCode("EG:"+BusinessPrefixEnum.CHECK_INTO_PREFIX.getCode()+":Haohanwuyin");
+        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(createHaohanwuyinCheckIntoBean(openApiConfig)));
+        egApiEndpointService.save(egApiEndpointDo);
+    }
+
+    private HttpApiConfig createHaohanwuyinCheckIntoBean(String openApiConfig) {
+        JSONObject jsonObject=JSONObject.parseObject(openApiConfig);
+        HttpApiConfig httpApiConfig = new HttpApiConfig();
+        httpApiConfig.setUrl(jsonObject.getString("url")+"/api/customer/collisionLibrary");
+        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();
+
+//        body.put("channelSource",jsonObject.getString("channelSource"));
+//        body.put("channelCode",jsonObject.getString("channelCode"));
+        KeyValueObject attackPhone=new KeyValueObject();
+        attackPhone.setType("spel");
+        attackPhone.setValue("#param.user.phoneMd5");
+        body.put("md5_phone","#"+JSONObject.toJSONString(attackPhone));
+        body.put("channel_code",jsonObject.getString("channelCode"));
+        body.put("channel_secret_key",jsonObject.getString("channelSecretKey"));
+        //主体
+        httpApiConfig.setContent(JSONObject.toJSONString(body));
+        JSONObject resultObj=new  JSONObject();
+        KeyValueObject status=new KeyValueObject();
+        status.setType("spel");
+        status.setValue("#root[code]==0?0:1");
+//        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("Haohanwuyin api {}",jsonString);
+        return httpApiConfig;
+    }
 }

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

@@ -0,0 +1,103 @@
+package com.hrsk.cloud.eg.infrastructure.business;
+
+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.common.ApiPayloadTypeEnum;
+import com.hrsk.cloud.eg.domain.api.common.ValueObjectTypeEnum;
+import com.hrsk.cloud.eg.infrastructure.config.client.HessianUtils;
+import com.hrsk.cloud.eg.infrastructure.repository.database.entity.EgApiDo;
+import com.hrsk.cloud.eg.infrastructure.repository.database.entity.EgApiEndpointDo;
+import com.hrsk.cloud.eg.infrastructure.service.EgApiEndpointService;
+import com.hrsk.cloud.eg.infrastructure.service.EgApiService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * @author zhangyy
+ * @version 1.0
+ * @description: GenerateCheckIntoHttpApiConfigV2Service
+ * @date 2024/9/9 16:35
+ */
+@Slf4j
+@Service
+public class GenerateCheckIntoHttpApiConfigV2Service {
+    @Resource
+    private EgApiService egApiService;
+
+    @Resource
+    private EgApiEndpointService egApiEndpointService;
+    /**
+     * @description:  灏瀚无崟
+     * @author zhangyy
+     * @date 2024/9/9 16:22
+     * @version 1.0
+     */
+    public void generateGexinjinfuConfig(String openApiConfig) {
+        EgApiDo egApiDo=new EgApiDo();
+        egApiDo.setApiCode("EG:"+ BusinessPrefixEnum.CHECK_INTO_PREFIX.getCode()+":Gexinjinfu");
+        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(createGexinjinfuCheckIntoBean(openApiConfig)));
+        egApiEndpointService.save(egApiEndpointDo);
+    }
+
+    private HttpApiConfig createGexinjinfuCheckIntoBean(String openApiConfig) {
+        JSONObject jsonObject=JSONObject.parseObject(openApiConfig);
+        HttpApiConfig httpApiConfig = new HttpApiConfig();
+        httpApiConfig.setUrl(jsonObject.getString("url")+"/api/rsatg/checkmobile");
+        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/x-www-form-urlencoded; charset=UTF-8");
+        headers.add(head);
+        httpApiConfig.setHeader(headers);
+        List<KeyValueObject> search = Lists.newArrayList();
+        KeyValueObject searchKey=new KeyValueObject();
+        searchKey.setType(ValueObjectTypeEnum.SPEL.getType());
+        searchKey.setKey("mobnum_md5");
+        searchKey.setValue("#param.user.phoneMd5");
+        search.add(searchKey);
+        httpApiConfig.setSearch(search);
+//        JSONObject body=new  JSONObject();
+//        body.put("channelSource",jsonObject.getString("channelSource"));
+//        body.put("channelCode",jsonObject.getString("channelCode"));
+//        KeyValueObject attackPhone=new KeyValueObject();
+//        attackPhone.setType("spel");
+//        attackPhone.setValue("#param.user.phoneMd5");
+//        body.put("md5_phone","#"+JSONObject.toJSONString(attackPhone));
+//        body.put("channel_code",jsonObject.getString("channelCode"));
+//        body.put("channel_secret_key",jsonObject.getString("channelSecretKey"));
+//        //主体
+//        httpApiConfig.setContent(JSONObject.toJSONString(body));
+        httpApiConfig.setContent("");
+        JSONObject resultObj=new  JSONObject();
+        KeyValueObject status=new KeyValueObject();
+        status.setType("spel");
+        status.setValue("#root[status]==200?0:1");
+//        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("Gexinjinfu api {}",jsonString);
+        return httpApiConfig;
+    }
+
+}

+ 6 - 5
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/business/HttpRequestCheckIntoService.java

@@ -13,6 +13,7 @@ import com.hrsk.cloud.eg.infrastructure.service.EgApiEndpointService;
 import com.hrsk.cloud.eg.infrastructure.service.EgApiService;
 import com.hrsk.cloud.eg.vo.response.DataVo;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.http.conn.ConnectTimeoutException;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -51,21 +52,21 @@ public class HttpRequestCheckIntoService {
         EgApiEndpointDo eg = egApiEndpointService.getById(paramDto.getPlan().getApiId());
         try {
             HttpApiConfig httpApiConfig = (HttpApiConfig) HessianUtils.deserialize(eg.getApiConfig());
-            String type = httpApiConfig.getUrl().substring(0,httpApiConfig.getUrl().indexOf("://"));
-             httpApiConfig.setType(type);
-            Api api = apiFactory.createApi(httpApiConfig,paramDto);
+            String type = httpApiConfig.getUrl().substring(0, httpApiConfig.getUrl().indexOf("://"));
+            httpApiConfig.setType(type);
+            Api api = apiFactory.createApi(httpApiConfig, paramDto);
             Object result = httpTemPlateClient.request((HttpApi) api);
             if (Objects.isNull(result)) {
                 return DataVo.fail();
             }
             Object output = apiFactory.createResult(httpApiConfig, result);
             JSONObject res = JSONObject.parseObject(output.toString());
-            DataVo dataVo=new DataVo();
+            DataVo dataVo = new DataVo();
             dataVo.setStatus(res.getInteger("status"));
             return dataVo;
         } catch (Exception e) {
             log.error("check into error ",e);
+            return DataVo.fail();
         }
-        return DataVo.fail();
     }
 }

+ 17 - 0
start/src/test/java/GenerateConfigTest.java

@@ -1,6 +1,7 @@
 import com.alibaba.fastjson2.JSONObject;
 import com.hrsk.cloud.eg.Application;
 import com.hrsk.cloud.eg.infrastructure.business.GenerateCheckIntoHttpApiConfigService;
+import com.hrsk.cloud.eg.infrastructure.business.GenerateCheckIntoHttpApiConfigV2Service;
 import com.hrsk.cloud.eg.infrastructure.repository.database.entity.ProductBusinessApiInfoDo;
 import com.hrsk.cloud.eg.infrastructure.service.ProductBusinessApiInfoService;
 import org.junit.Test;
@@ -27,6 +28,9 @@ public class GenerateConfigTest {
     @Resource
     private ProductBusinessApiInfoService productBusinessApiInfoService;
 
+    @Resource
+    private GenerateCheckIntoHttpApiConfigV2Service generateCheckIntoHttpApiConfigV2Service;
+
     @Test
     public void createHuiRonApiTest(){
         List<ProductBusinessApiInfoDo> productBusinessApiInfoDos = productBusinessApiInfoService.selectByJointCodeForList("9");
@@ -121,4 +125,17 @@ public class GenerateConfigTest {
         generateCHeckIntoHttpApiConfigService.generateHamiguaConfig(productBusinessApiInfoDos.get(0).getThreeSystemConfig());
     }
 
+    @Test
+    public void createHaohanwuyinApiTest(){
+        List<ProductBusinessApiInfoDo> productBusinessApiInfoDos = productBusinessApiInfoService.selectByJointJonintTypeForList("Haohanwuyin");
+        generateCHeckIntoHttpApiConfigService.generateHaohanwuyinConfig(productBusinessApiInfoDos.get(0).getThreeSystemConfig());
+    }
+
+    @Test
+    public void createGexinjinfuApiTest(){
+        List<ProductBusinessApiInfoDo> productBusinessApiInfoDos = productBusinessApiInfoService.selectByJointJonintTypeForList("Gexinjinfu");
+        generateCheckIntoHttpApiConfigV2Service.generateGexinjinfuConfig(productBusinessApiInfoDos.get(0).getThreeSystemConfig());
+    }
+
+
 }

+ 30 - 0
start/src/test/java/StartApiTest.java

@@ -318,6 +318,36 @@ public class StartApiTest {
         apiGateway.checkIntoRequest(checkin);
     }
 
+    @Test
+    public void haohanwuyinApiTest(){
+        Long apiId= 441427018106688L;
+        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 gexinjinfuApiTest(){
+        Long apiId= 441427703907136L;
+        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<>();