Эх сурвалжийг харах

修改埃文数据宝返回格式

longhu 12 цаг өмнө
parent
commit
9783e7542e

+ 9 - 30
src/main/java/com/hr/externelSystem/AiwenIpService.java

@@ -33,16 +33,16 @@ import java.util.Map;
  */
 @Service
 @Slf4j
-public class AiwenIpService implements BizHandler<AiwenParam,AiwenParseIpInfoVO>{
+public class AiwenIpService implements BizHandler<AiwenParam,JSONObject>{
 
     @Autowired
     private RedisService redisService;
 
     @Autowired
     private AiwenAlertConfig aiwenAlertConfig;
-
     private Long callExceptionCount=0L;
 
+
     @Autowired
     private FeishuMsgSendService feishuMsgSendService;
     @Autowired
@@ -67,7 +67,7 @@ public class AiwenIpService implements BizHandler<AiwenParam,AiwenParseIpInfoVO>
     }
 
     @Override
-    public AiwenParseIpInfoVO handle(AiwenParam aiwenIpParam, IpInterfacePO ipInterfacePO, ApiLogDto logDto) {
+    public JSONObject handle(AiwenParam aiwenIpParam, IpInterfacePO ipInterfacePO, ApiLogDto logDto) {
         {
             String interfaceConfig = ipInterfacePO.getInterfaceConfig();
             AiwenDto aiwenDto = JSON.parseObject(interfaceConfig, AiwenDto.class);
@@ -109,6 +109,7 @@ public class AiwenIpService implements BizHandler<AiwenParam,AiwenParseIpInfoVO>
             String yesterday=getYesterday();
             String yesternetkey=AiwenCallRedisKeyNetWork+":"+yesterday;
             String curnetkey=AiwenCallRedisKeyNetWork+":"+curday;
+            JSONObject ipParseJson = new JSONObject();
             try {
 
                 ValueOperations<String, Object> valueOps = redisService.redisTemplate.opsForValue();
@@ -171,33 +172,10 @@ public class AiwenIpService implements BizHandler<AiwenParam,AiwenParseIpInfoVO>
                 // 调用接口解析ip地址信息
                 String response = HttpClientUtils.get(url, new HashMap());
                 logDto.setResponseParam(response);
-                JSONObject ipParseJson = JSONObject.parseObject(response);
+                ipParseJson = JSONObject.parseObject(response);
                 logDto.setHttpStatus(ipParseJson.getString("code"));
                 // 解析ip地址解析后的数据
-                if ("Success".equals(ipParseJson.getString("code"))) {
-                    JSONObject data = ipParseJson.getJSONObject("data");
-
-                    String province = data.getString("prov");
-                    String city = data.getString("city");
-                    if (province != null) {
-                        ipInfoDTO.setProvince(province.replace("省",""));
-                    }
-                    if(city != null){
-                        ipInfoDTO.setCity(city);
-                    } else {
-                        // city字段为空时, 默认采用省份填充
-                        ipInfoDTO.setCity(province);
-                    }
-
-                    ipInfoDTO.setCountry(data.getString("country"));
-                    ipInfoDTO.setIp(ipParseJson.getString("ip"));
-                    ipInfoDTO.setSub(data.getString("isp"));
-                    ipInfoDTO.setInfo("");
-                    ipInfoDTO.setCityCode(data.getString("adcode"));
-                    ipInfoDTO.setLat(data.getString("lat"));
-                    ipInfoDTO.setLng(data.getString("lng"));
-                    log.info("埃文科技解析isp:{}", ipInfoDTO.getSub());
-                }else{
+                if (!"Success".equals(ipParseJson.getString("code"))) {
                     if ("DailyLimited".equals(ipParseJson.getString("code")) ){
                         log.error("埃文科技解析ip调用超量了");
                         logDto.setErrorMessage("埃文科技解析ip调用超量了");
@@ -207,8 +185,9 @@ public class AiwenIpService implements BizHandler<AiwenParam,AiwenParseIpInfoVO>
                                 feishuMsgSendService.dealFeishuMsgSendIpGroup("[异常]" + curday + ",埃文IP调用返回值为已超量,现已达到了redis值["+count.toString()+"]次,"+formattedTime);
                             }
                         }
+                    }else{
+                        logDto.setErrorMessage(ipParseJson.getString("code"));
                     }
-                    log.error("埃文ip地址请求失败:{},接口返回数据格式不正确", aiwenIpParam.getIp());
                 }
             } catch (Exception e) {
                 log.error("埃文ip地址解析异常, {},{}", aiwenIpParam.getIp(),e.getMessage());
@@ -220,7 +199,7 @@ public class AiwenIpService implements BizHandler<AiwenParam,AiwenParseIpInfoVO>
                 callExceptionCount++;
             }
 
-            return ipInfoDTO;
+            return ipParseJson;
         }
     }
 

+ 9 - 8
src/main/java/com/hr/externelSystem/ShujubaoMobileNameService.java

@@ -22,36 +22,37 @@ import java.util.Map;
  */
 @Service
 @Slf4j
-public class ShujubaoMobileNameService implements BizHandler<ShujubaoMobileNameParam,Boolean>{
+public class ShujubaoMobileNameService implements BizHandler<ShujubaoMobileNameParam,JSONObject>{
     @Override
     public ServiceTypeVO getType() {
         return new ServiceTypeVO("shujubaoMobileName","数据宝手机号姓名二要素");
     }
 
     @Override
-    public Boolean handle(ShujubaoMobileNameParam shujubaoMobileNameParam, IpInterfacePO ipInterfacePO, ApiLogDto logDto) {
+    public JSONObject handle(ShujubaoMobileNameParam shujubaoMobileNameParam, IpInterfacePO ipInterfacePO, ApiLogDto logDto) {
         String interfaceConfig = ipInterfacePO.getInterfaceConfig();
         ShujubaoMobileNameDto paramDto = JSON.parseObject(interfaceConfig, ShujubaoMobileNameDto.class);
         Map<String, String> requestMap = new HashMap<>();
         requestMap.put("key", paramDto.getKey());
         requestMap.put("name", shujubaoMobileNameParam.getName());
         requestMap.put("mobile", shujubaoMobileNameParam.getMobile());
-        Boolean result = true;
+        JSONObject resultObj = new JSONObject();
         try {
             logDto.setUrl(paramDto.getUrl());
             logDto.setRequestParam(JSON.toJSONString(requestMap));
             String checkResult = HttpClientUtils.post(paramDto.getUrl(), requestMap);
-            JSONObject resultObj = JSON.parseObject(checkResult);
+            resultObj = JSON.parseObject(checkResult);
             logDto.setResponseParam(checkResult);
             logDto.setHttpStatus(resultObj.getString("code"));
-            if (null != resultObj && "10000".equals(resultObj.getString("code")) && null != resultObj.getJSONObject("data") && "2".equals(resultObj.getJSONObject("data").getString("state"))){
-                return false;
+            if (null != resultObj.getString("code") && !"10000".equals(resultObj.getString("code"))){
+                logDto.setErrorMessage(resultObj.getString("message"));
             }
-            logDto.setErrorMessage(resultObj.getString("message"));
+            return resultObj;
+
         } catch (Exception e){
             log.info("phone name check error data:{}  exception:{}", shujubaoMobileNameParam, e.getMessage());
         }
-        return  result;
+        return  resultObj;
     }
 
     @Override

+ 7 - 20
src/main/java/com/hr/externelSystem/ShujubaoMobileOwnerService.java

@@ -26,7 +26,7 @@ import java.util.Map;
  */
 @Service
 @Slf4j
-public class ShujubaoMobileOwnerService implements BizHandler<ShujubaoMobileOwnerParam,ShujubaoMobileOwnerVO>{
+public class ShujubaoMobileOwnerService implements BizHandler<ShujubaoMobileOwnerParam,JSONObject>{
 
     private static final List<String> MOBILE_TOP_THREE_OPERATOR = Arrays.asList("移动","联通","电信");
     @Override
@@ -35,7 +35,7 @@ public class ShujubaoMobileOwnerService implements BizHandler<ShujubaoMobileOwne
     }
 
     @Override
-    public ShujubaoMobileOwnerVO handle(ShujubaoMobileOwnerParam shujubaoMobileNameParam, IpInterfacePO ipInterfacePO, ApiLogDto logDto) {
+    public JSONObject handle(ShujubaoMobileOwnerParam shujubaoMobileNameParam, IpInterfacePO ipInterfacePO, ApiLogDto logDto) {
 
         String interfaceConfig = ipInterfacePO.getInterfaceConfig();
         ShujubaoMobileNameDto paramDto = JSON.parseObject(interfaceConfig, ShujubaoMobileNameDto.class);
@@ -44,7 +44,7 @@ public class ShujubaoMobileOwnerService implements BizHandler<ShujubaoMobileOwne
         Map<String, String> requestMap = new HashMap<>();
         requestMap.put("key", paramDto.getKey());
         requestMap.put("mobile", shujubaoMobileNameParam.getMobile());
-
+        JSONObject resultObj = new JSONObject();
         try {
             logDto.setUrl(paramDto.getUrl());
             logDto.setRequestParam(JSON.toJSONString(requestMap));
@@ -53,29 +53,16 @@ public class ShujubaoMobileOwnerService implements BizHandler<ShujubaoMobileOwne
             log.info("第三方接口解析手机号归属地返回信息: {}", checkResult);
 
             // 解析数据
-            JSONObject resultObj = JSON.parseObject(checkResult);
+            resultObj = JSON.parseObject(checkResult);
             logDto.setResponseParam(checkResult);
             logDto.setHttpStatus(resultObj.getString("code"));
-            if (null != resultObj && "10000".equals(resultObj.getString("code")) && null != resultObj.getJSONObject("data")){
-                JSONObject dataJson = resultObj.getJSONObject("data");
-                ShujubaoMobileOwnerVO result = JSON.toJavaObject(dataJson, ShujubaoMobileOwnerVO.class);
-                result.setIsVirtual(false);
-
-
-                // 判断当前手机号是否是虚拟号(判断逻辑: 非三大运营商(移动,电信,联通)的统一标记为虚拟号)
-                String isp = dataJson.getString("isp");
-                if(MOBILE_TOP_THREE_OPERATOR.stream().noneMatch(isp::contains)){
-                    result.setIsVirtual(true);
-                }
-
-                return result;
+            if (null != resultObj.getString("code") && !"10000".equals(resultObj.getString("code")) ){
+                logDto.setErrorMessage(resultObj.getString("message"));
             }
-            logDto.setErrorMessage(resultObj.getString("message"));
         } catch (Exception e){
             log.info("手机号归属地解析失败, 手机号: {}, exception:{}", shujubaoMobileNameParam.getMobile(), e.getMessage());
-            return null;
         }
-        return new ShujubaoMobileOwnerVO();
+        return resultObj;
     }
 
     @Override

+ 7 - 11
src/main/java/com/hr/externelSystem/ShujubaoMobileStateService.java

@@ -25,38 +25,34 @@ import java.util.Map;
  */
 @Service
 @Slf4j
-public class ShujubaoMobileStateService implements BizHandler<ShujubaoMobileOwnerParam,Boolean>{
+public class ShujubaoMobileStateService implements BizHandler<ShujubaoMobileOwnerParam,JSONObject>{
     @Override
     public ServiceTypeVO getType() {
         return new ServiceTypeVO("shujubaoMobileState","数据宝手机号空号检测");
     }
 
     @Override
-    public Boolean handle(ShujubaoMobileOwnerParam shujubaoMobileNameParam, IpInterfacePO ipInterfacePO, ApiLogDto logDto) {
+    public JSONObject handle(ShujubaoMobileOwnerParam shujubaoMobileNameParam, IpInterfacePO ipInterfacePO, ApiLogDto logDto) {
         String interfaceConfig = ipInterfacePO.getInterfaceConfig();
         ShujubaoMobileNameDto paramDto = JSON.parseObject(interfaceConfig, ShujubaoMobileNameDto.class);
         Map<String, String> requestMap = new HashMap<>();
         requestMap.put("key", paramDto.getKey());
         requestMap.put("mobile", shujubaoMobileNameParam.getMobile());
-        Boolean result = true;
+        JSONObject resultObj = new JSONObject();
         try {
             logDto.setUrl(paramDto.getUrl());
             logDto.setRequestParam(JSON.toJSONString(requestMap));
             String checkResult = HttpClientUtils.post(paramDto.getUrl(), requestMap);
-            JSONObject resultObj = JSON.parseObject(checkResult);
+            resultObj = JSON.parseObject(checkResult);
             logDto.setResponseParam(checkResult);
             logDto.setHttpStatus(resultObj.getString("code"));
-            if (null != resultObj && "10000".equals(resultObj.getString("code")) && null != resultObj.getJSONObject("data")){
-                String state = resultObj.getJSONObject("data").getString("state");
-                if (StringUtils.isNotBlank(state) && ("2".equals(state) || "4".equals(state) || "5".equals(state))) {
-                    return false;
-                }
+            if (null != resultObj.getString("code") && !"10000".equals(resultObj.getString("code")) ){
+                logDto.setErrorMessage(resultObj.getString("message"));
             }
-            logDto.setErrorMessage(resultObj.getString("message"));
         } catch (Exception e){
             log.info("phone state check error data:{}  exception:{}", shujubaoMobileNameParam.getMobile(), e.getMessage());
         }
-        return  result;
+        return resultObj;
     }
 
     @Override

+ 9 - 19
src/main/java/com/hr/externelSystem/ShujubaoThreeElementVerificationService.java

@@ -24,7 +24,7 @@ import java.util.*;
  */
 @Service
 @Slf4j
-public class ShujubaoThreeElementVerificationService implements BizHandler<ShujubaoTEVParam,Boolean>{
+public class ShujubaoThreeElementVerificationService implements BizHandler<ShujubaoTEVParam,JSONObject>{
 
 
     @Override
@@ -33,11 +33,11 @@ public class ShujubaoThreeElementVerificationService implements BizHandler<Shuju
     }
 
     @Override
-    public Boolean handle(ShujubaoTEVParam shujubaoTEVParam, IpInterfacePO ipInterfacePO, ApiLogDto logDto) {
+    public JSONObject handle(ShujubaoTEVParam shujubaoTEVParam, IpInterfacePO ipInterfacePO, ApiLogDto logDto) {
 
         String interfaceConfig = ipInterfacePO.getInterfaceConfig();
         ShujubaoMobileNameDto paramDto = JSON.parseObject(interfaceConfig, ShujubaoMobileNameDto.class);
-
+        JSONObject resultObj = new JSONObject();
 
         try {
             Map<String, String> requestMap = new HashMap<>();
@@ -51,27 +51,17 @@ public class ShujubaoThreeElementVerificationService implements BizHandler<Shuju
             String response = HttpClientUtils.post(paramDto.getUrl(), requestMap);
             log.info("调用【数据宝】三要素校验接口的结果为: {}", response);
 
-            JSONObject respJson = JSONObject.parseObject(response);
+            resultObj = JSONObject.parseObject(response);
             logDto.setResponseParam(response);
-            logDto.setHttpStatus(respJson.getString("code"));
-            if(null != respJson && Objects.equals(respJson.getString("code"), "10000")){
-                JSONObject dataJson = JSONObject.parseObject(respJson.getString("data"));
-                if(null != dataJson && dataJson.getInteger("state") != 3){
-                    switch (dataJson.getInteger("state")){
-                        case 1:
-                           return true;
-                        case 2:
-                            return false;
-                        default:
-                            return false;
-                    }
-                }
+            logDto.setHttpStatus(resultObj.getString("code"));
+            if(!Objects.equals(resultObj.getString("code"), "10000")){
+                logDto.setErrorMessage(resultObj.getString("message"));
             }
-            logDto.setErrorMessage(respJson.getString("message"));
+
         } catch (Exception e) {
             log.info("三要素校验接口调用失败, 失败原因: {},", e.getMessage(), e);
         }
-        return false;
+        return resultObj;
     }
 
     @Override