From 155344781fbe12c878c208ad5359d8aa135612bc Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 23 Mar 2021 11:05:48 +0800 Subject: [PATCH 01/18] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=201.=E8=8E=B7?= =?UTF-8?q?=E5=8F=96open-api=20accessToken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-commons/epmet-commons-security/pom.xml | 26 ++++ .../commons/security/jwt/JwtTokenUtils.java | 112 ++++++++++++++++++ .../sign/openapi/OpenApiSignUtils.java | 76 ++++++++++++ .../tools/exception/EpmetErrorCode.java | 5 +- .../epmet/commons/tools/redis/RedisKeys.java | 10 ++ .../commons/tools/utils/ConvertUtils.java | 40 ++++++- epmet-commons/pom.xml | 3 +- .../epmet/dto/form/AccessTokenFormDTO.java | 19 +++ .../epmet-ext/epmet-ext-server/pom.xml | 10 ++ .../java/com/epmet/config/OpenApiConfig.java | 15 +++ .../OpenApiAccessTokenController.java | 88 ++++++++++++++ .../service/OpenApiAccessTokenService.java | 15 +++ .../impl/OpenApiAccessTokenServiceImpl.java | 44 +++++++ .../src/main/resources/bootstrap.yml | 5 + 14 files changed, 462 insertions(+), 6 deletions(-) create mode 100644 epmet-commons/epmet-commons-security/pom.xml create mode 100644 epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtTokenUtils.java create mode 100644 epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java create mode 100644 epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/AccessTokenFormDTO.java create mode 100644 epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/config/OpenApiConfig.java create mode 100644 epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java create mode 100644 epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/OpenApiAccessTokenService.java create mode 100644 epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java diff --git a/epmet-commons/epmet-commons-security/pom.xml b/epmet-commons/epmet-commons-security/pom.xml new file mode 100644 index 0000000000..a4bebe4c54 --- /dev/null +++ b/epmet-commons/epmet-commons-security/pom.xml @@ -0,0 +1,26 @@ + + + + epmet-commons + com.epmet + 2.0.0 + + 4.0.0 + + epmet-commons-security + + + + com.epmet + epmet-commons-tools + 2.0.0 + + + io.jsonwebtoken + jjwt + 0.7.0 + + + \ No newline at end of file diff --git a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtTokenUtils.java b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtTokenUtils.java new file mode 100644 index 0000000000..8cbae20749 --- /dev/null +++ b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtTokenUtils.java @@ -0,0 +1,112 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + *

+ * https://www.renren.io + *

+ * 版权所有,侵权必究! + */ + +package com.epmet.commons.security.jwt; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; +import org.joda.time.DateTime; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * Jwt工具类 + * + * @author Mark sunlightcs@gmail.com + * @since 1.0.0 + */ +@Component +public class JwtTokenUtils { + private static final Logger logger = LoggerFactory.getLogger(JwtTokenUtils.class); + + public Claims getClaimByToken(String token, String secret) { + try { + return Jwts.parser() + .setSigningKey(secret) + .parseClaimsJws(token) + .getBody(); + } catch (Exception e) { + logger.debug("validate is token error, token = " + token, e); + return null; + } + } + + /** + * @return java.util.Date + * @param token + * @Author yinzuomei + * @Description 获取token的有效期截止时间 + * @Date 2020/3/18 22:17 + **/ + public Date getExpiration(String token, String secret){ + try { + return Jwts.parser() + .setSigningKey(secret) + .parseClaimsJws(token) + .getBody().getExpiration(); + } catch (Exception e) { + logger.debug("validate is token error, token = " + token, e); + return null; + } + } + + /** + * @return java.lang.String + * @Author yinzuomei + * @Description 根据app+client+userId生成token + * @Date 2020/3/18 22:29 + **/ + public String createToken(Map claims, int expire, String secret) { + return Jwts.builder() + .setHeaderParam("typ", "JWT") + .setClaims(claims) + .setIssuedAt(new Date()) + .setExpiration(DateTime.now().plusSeconds(expire).toDate()) + .signWith(SignatureAlgorithm.HS512, secret) + .compact(); + } + + /** + * token是否过期 + * + * @return true:过期 + */ + public boolean isTokenExpired(Date expiration) { + return expiration.before(new Date()); + } + + public static void main(String[] args) { + Map map=new HashMap<>(); + map.put("app","gov"); + map.put("client","wxmp"); + map.put("userId","100526ABC"); + String tokenStr=Jwts.builder() + .setHeaderParam("typ", "JWT") + .setClaims(map) + .setIssuedAt(new Date()) + .setExpiration(DateTime.now().plusSeconds(604800).toDate()) + .signWith(SignatureAlgorithm.HS512, "7016867071f0ebf1c46f123eaaf4b9d6[elink.epmet]") + .compact(); + System.out.println(tokenStr); + Claims claims= Jwts.parser() + .setSigningKey("7016867071f0ebf1c46f123eaaf4b9d6[elink.epmet]") + .parseClaimsJws(tokenStr) + .getBody(); + System.out.println("app="+ claims.get("app")); + System.out.println("client="+ claims.get("client")); + System.out.println("userId="+ claims.get("userId")); + } + +} diff --git a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java new file mode 100644 index 0000000000..33b82b1a23 --- /dev/null +++ b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java @@ -0,0 +1,76 @@ +package com.epmet.commons.security.sign.openapi; + +import com.epmet.commons.tools.utils.Md5Util; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * OpenApi签名工具 + */ +public class OpenApiSignUtils { + + /** + * @Description 创建签名 + * @return + * @author wxz + * @date 2021.03.22 16:47 + */ + public static String createSign(Map contentMap, String signKey) { + String str2beSigned = mapToSignStr(contentMap); + str2beSigned = str2beSigned.concat("&signKey=").concat(signKey); + return Md5Util.md5(str2beSigned); + } + + /** + * @Description 验签 + * @return + * @author wxz + * @date 2021.03.22 16:51 + */ + public static boolean checkSign(Map contentMap, String signKey) { + String newSign = createSign(contentMap, signKey); + return newSign.equals(contentMap.get("sign")); + } + + /** + * @Description map转化为签名明文 + * @return + * @author wxz + * @date 2021.03.22 16:47 + */ + public static String mapToSignStr(Map map) { + Set keySet = map.keySet(); + String[] keyArray = (String[])keySet.toArray(new String[keySet.size()]); + Arrays.sort(keyArray); + StringBuilder sb = new StringBuilder(); + + for(int i = 0; i < keyArray.length; ++i) { + String key = keyArray[i]; + String val = (String)map.get(key); + if (val != null && val.trim().length() > 0 && !"sign".equals(key)) { + if (!sb.toString().isEmpty()) { + sb.append("&"); + } + + sb.append(key).append("=").append((String)map.get(key)); + } + } + + return sb.toString(); + } + + + public static void main(String[] args) { + + HashMap content = new HashMap<>(); + content.put("appId", "7d98b8af2d05752b4225709c4cfd4bd0"); + + String secret = "3209ee9f41704482be1a1fb5873a25376f2899191ca846119d44168316bc3e44"; + + String sign = createSign(content, secret); + System.out.println(sign); + } +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index ac6d50bd9f..47546c0e81 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -143,7 +143,10 @@ public enum EpmetErrorCode { TOPIC_SHIFTED_TO_ISSUE_UNDER_AUDITING(9004,"当前话题正在转议题审核"), TOPIC_ALREADY_SHIFTED_TO_ISSUE(9005,"该话题已被转为议题,请勿重复操作"), TOPIC_IS_HIDDEN(9006,"该话题已被屏蔽,请先解除屏蔽"), - TOPIC_IS_CLOSED(9008,"该话题已关闭,无法转为议题"); + TOPIC_IS_CLOSED(9008,"该话题已关闭,无法转为议题"), + + // open api异常 + OPEN_API_SIGN_ERROR(9100, "签名错误"); private int code; private String msg; diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index 098dd1c14d..20bde9e05f 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -370,4 +370,14 @@ public class RedisKeys { public static String getCustomerApiServiceKey(String customerId) { return rootPrefix.concat("customer:thirdplat:apiservice:").concat(customerId); } + + /** + * @Description 获取openApi的accessToken的key + * @return + * @author wxz + * @date 2021.03.23 10:25 + */ + public static String getOpenApiAccessTokenKey(String appId) { + return rootPrefix.concat("openapi:accesstoken:").concat(appId); + } } diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ConvertUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ConvertUtils.java index 93c653e178..6d2e509797 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ConvertUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ConvertUtils.java @@ -12,11 +12,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.*; /** * 转换工具类 @@ -87,4 +90,33 @@ public class ConvertUtils { } return t; } + + /** + * @Description entity转map + * @return + * @author wxz + * @date 2021.03.22 16:38 + */ + public static Map entityToMap(Object bean) throws IntrospectionException, InvocationTargetException, IllegalAccessException { + Class type = bean.getClass(); + Map returnMap = new HashMap(16); + BeanInfo beanInfo = Introspector.getBeanInfo(type); + PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); + + for(int i = 0; i < propertyDescriptors.length; ++i) { + PropertyDescriptor descriptor = propertyDescriptors[i]; + String propertyName = descriptor.getName(); + if (!"class".equals(propertyName)) { + Method readMethod = descriptor.getReadMethod(); + Object result = readMethod.invoke(bean); + if (result != null) { + returnMap.put(propertyName, String.valueOf(result)); + } else { + returnMap.put(propertyName, ""); + } + } + } + + return returnMap; + } } diff --git a/epmet-commons/pom.xml b/epmet-commons/pom.xml index 636480c48f..b495dd438e 100644 --- a/epmet-commons/pom.xml +++ b/epmet-commons/pom.xml @@ -25,6 +25,7 @@ epmet-commons-extapp-auth epmet-commons-thirdplat epmet-commons-rocketmq - + epmet-commons-security + diff --git a/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/AccessTokenFormDTO.java b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/AccessTokenFormDTO.java new file mode 100644 index 0000000000..4b315ae326 --- /dev/null +++ b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/AccessTokenFormDTO.java @@ -0,0 +1,19 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +@Data +public class AccessTokenFormDTO { + + public interface GetAccessTokenGroup {} + + // 签名字符串密文 + @NotBlank(message = "签名字段不能为空", groups = { GetAccessTokenGroup.class }) + private String sign; + + // 应用id + @NotBlank(message = "AppId字段不能为空", groups = { GetAccessTokenGroup.class }) + private String appId; +} diff --git a/epmet-module/epmet-ext/epmet-ext-server/pom.xml b/epmet-module/epmet-ext/epmet-ext-server/pom.xml index f33a428e27..d12766c5e9 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/pom.xml +++ b/epmet-module/epmet-ext/epmet-ext-server/pom.xml @@ -21,6 +21,16 @@ + + com.epmet + common-service-client + 2.0.0 + + + com.epmet + epmet-commons-security + 2.0.0 + com.epmet epmet-ext-client diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/config/OpenApiConfig.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/config/OpenApiConfig.java new file mode 100644 index 0000000000..706c01af35 --- /dev/null +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/config/OpenApiConfig.java @@ -0,0 +1,15 @@ +package com.epmet.config; + +import lombok.Data; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; + +@Component +@Data +public class OpenApiConfig { + + @Value("${openApi.accessToken.expire}") + private int accessTokenExpire; + +} diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java new file mode 100644 index 0000000000..1580ca1b6a --- /dev/null +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java @@ -0,0 +1,88 @@ +package com.epmet.controller; + +import com.epmet.commons.security.sign.openapi.OpenApiSignUtils; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.ExceptionUtils; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.redis.RedisUtils; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.dto.form.AccessTokenFormDTO; +import com.epmet.feign.EpmetCommonServiceOpenFeignClient; +import com.epmet.service.OpenApiAccessTokenService; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.beans.IntrospectionException; +import java.lang.reflect.InvocationTargetException; + +@RestController +@RequestMapping("open-api") +public class OpenApiAccessTokenController { + + @Autowired + private OpenApiAccessTokenService openApiAccessTokenService; + + @Autowired + private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; + + @Autowired + private RedisUtils redisUtils; + + private Logger logger = LoggerFactory.getLogger(OpenApiAccessTokenController.class); + + /** + * @Description 获取AccessToken + * @return + * @author wxz + * @date 2021.03.23 09:52 + */ + @PostMapping("get-access-token") + public Result getAccessToken(@RequestBody AccessTokenFormDTO input) { + // 1.校验参数 + ValidatorUtils.validateEntity(input); + String appId = input.getAppId(); + + // 2.取secret + String secret = (String)redisUtils.get(RedisKeys.getExternalAppSecretKey(appId)); + if (StringUtils.isBlank(secret)) { + Result result = commonServiceOpenFeignClient.getSecret(appId); + if (!result.success()) { + throw new RenException("调用common service查询secret失败"); + } + secret = result.getData(); + if (StringUtils.isBlank(secret)) { + throw new RenException(String.format("根据appId%s没有找到对应的secret", appId)); + } + redisUtils.set(RedisKeys.getExternalAppSecretKey(appId), secret); + } + + // 3.验签 + try { + if (!OpenApiSignUtils.checkSign(ConvertUtils.entityToMap(input), secret)) { + throw new RenException(EpmetErrorCode.OPEN_API_SIGN_ERROR.getCode(), EpmetErrorCode.OPEN_API_SIGN_ERROR.getMsg()); + } + } catch (RenException e) { + // 如果是自己抛出的异常则继续抛出 + throw e; + } catch (Exception e) { + // 是其他意外发生的异常 + String errorStackTrace = ExceptionUtils.getErrorStackTrace(e); + logger.error("验签发生未知异常:{}", errorStackTrace); + throw new RenException("验签发生未知异常,请查看ext服务详细日志"); + } + + //4.生成token + String accessToken = openApiAccessTokenService.getAccessToken(appId, secret); + return new Result().ok(accessToken); + } + +} diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/OpenApiAccessTokenService.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/OpenApiAccessTokenService.java new file mode 100644 index 0000000000..56c3bd4630 --- /dev/null +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/OpenApiAccessTokenService.java @@ -0,0 +1,15 @@ +package com.epmet.service; + +/** + * access token的service + */ +public interface OpenApiAccessTokenService { + + /** + * @Description 获取AccessToken + * @return + * @author wxz + * @date 2021.03.22 22:57 + */ + String getAccessToken(String appId, String secret); +} diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java new file mode 100644 index 0000000000..8610eb2ce0 --- /dev/null +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java @@ -0,0 +1,44 @@ +package com.epmet.service.impl; + +import com.epmet.commons.security.jwt.JwtTokenUtils; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.redis.RedisUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.utils.SpringContextUtils; +import com.epmet.config.OpenApiConfig; +import com.epmet.feign.EpmetCommonServiceOpenFeignClient; +import com.epmet.service.OpenApiAccessTokenService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.util.HashMap; + +@Service +public class OpenApiAccessTokenServiceImpl implements OpenApiAccessTokenService { + + @Autowired + private JwtTokenUtils jwtTokenUtils; + + @Autowired + private OpenApiConfig openApiConfig; + + @Autowired + private RedisUtils redisUtils; + + @Override + public String getAccessToken(String appId, String secret) { + HashMap claim = new HashMap<>(); + claim.put("appId", appId); + + String token = jwtTokenUtils.createToken(claim, openApiConfig.getAccessTokenExpire(), secret); + + // 缓存token + redisUtils.set(RedisKeys.getOpenApiAccessTokenKey(appId), token, openApiConfig.getAccessTokenExpire()); + + return token; + } +} diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/resources/bootstrap.yml b/epmet-module/epmet-ext/epmet-ext-server/src/main/resources/bootstrap.yml index 7a067d1606..9696f37468 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/resources/bootstrap.yml +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/resources/bootstrap.yml @@ -110,3 +110,8 @@ shutdown: graceful: enable: true #是否开启优雅停机 waitTimeSecs: 30 # 优雅停机等待时间,超过30秒,发出告警 + +# 对外开放接口配置 +openApi: + accessToken: + expire: 7200000 From 604c78541a3fe656c79acb8850c5e0bade3c25f3 Mon Sep 17 00:00:00 2001 From: wxz Date: Wed, 24 Mar 2021 10:49:07 +0800 Subject: [PATCH 02/18] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=20=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=89=8B=E5=8A=A8=E9=AA=8C=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jwt/{JwtTokenUtils.java => JwtUtils.java} | 4 +- .../sign/openapi/OpenApiSignUtils.java | 3 +- .../tools/exception/EpmetErrorCode.java | 3 +- .../epmet/commons/tools/redis/RedisKeys.java | 4 +- epmet-gateway/pom.xml | 9 +- .../auth/ExtAppFetchTokenAuthProcessor.java | 84 +++++++++++++++++++ .../com/epmet/auth/ExternalAuthProcessor.java | 30 +++++-- .../src/main/resources/bootstrap.yml | 4 + .../EpmetCommonServiceOpenFeignClient.java | 2 +- .../dto/form/openapi/GetOrgDetailFormDTO.java | 15 ++++ .../dto/form/openapi/OpenApiBaseFormDTO.java | 13 +++ .../controller/OpenApiOrgController.java | 63 ++++++++++++++ .../impl/OpenApiAccessTokenServiceImpl.java | 13 +-- 13 files changed, 220 insertions(+), 27 deletions(-) rename epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/{JwtTokenUtils.java => JwtUtils.java} (98%) create mode 100644 epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java create mode 100644 epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/GetOrgDetailFormDTO.java create mode 100644 epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/OpenApiBaseFormDTO.java create mode 100644 epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiOrgController.java diff --git a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtTokenUtils.java b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtUtils.java similarity index 98% rename from epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtTokenUtils.java rename to epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtUtils.java index 8cbae20749..23b738d623 100644 --- a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtTokenUtils.java +++ b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtUtils.java @@ -28,8 +28,8 @@ import java.util.Map; * @since 1.0.0 */ @Component -public class JwtTokenUtils { - private static final Logger logger = LoggerFactory.getLogger(JwtTokenUtils.class); +public class JwtUtils { + private static final Logger logger = LoggerFactory.getLogger(JwtUtils.class); public Claims getClaimByToken(String token, String secret) { try { diff --git a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java index 33b82b1a23..306bb5ab3d 100644 --- a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java +++ b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java @@ -66,7 +66,8 @@ public class OpenApiSignUtils { public static void main(String[] args) { HashMap content = new HashMap<>(); - content.put("appId", "7d98b8af2d05752b4225709c4cfd4bd0"); + content.put("orgId", "aaa"); + content.put("test", ""); String secret = "3209ee9f41704482be1a1fb5873a25376f2899191ca846119d44168316bc3e44"; diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index 47546c0e81..e22f5f7983 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -146,7 +146,8 @@ public enum EpmetErrorCode { TOPIC_IS_CLOSED(9008,"该话题已关闭,无法转为议题"), // open api异常 - OPEN_API_SIGN_ERROR(9100, "签名错误"); + OPEN_API_SIGN_ERROR(9100, "签名错误"), + OPEN_API_SIGN_TOKEN_EXPIRED(9101, "Token过期"); private int code; private String msg; diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index 20bde9e05f..5ba36b541b 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -377,7 +377,7 @@ public class RedisKeys { * @author wxz * @date 2021.03.23 10:25 */ - public static String getOpenApiAccessTokenKey(String appId) { - return rootPrefix.concat("openapi:accesstoken:").concat(appId); + public static String getOpenApiAccessTokenKey(String accessToken) { + return rootPrefix.concat("openapi:accesstoken:").concat(accessToken); } } diff --git a/epmet-gateway/pom.xml b/epmet-gateway/pom.xml index 08eda7167e..560063fe23 100644 --- a/epmet-gateway/pom.xml +++ b/epmet-gateway/pom.xml @@ -13,6 +13,11 @@ jar + + com.epmet + epmet-commons-security + 2.0.0 + com.epmet epmet-commons-tools @@ -329,8 +334,8 @@ lb://epmet-point-server - lb://epmet-ext-server - + + http://127.0.0.1:8113 lb://data-aggregator-server diff --git a/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java b/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java new file mode 100644 index 0000000000..236914ccb2 --- /dev/null +++ b/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java @@ -0,0 +1,84 @@ +package com.epmet.auth; + +import com.epmet.commons.security.jwt.JwtUtils; +import com.epmet.commons.security.sign.openapi.OpenApiSignUtils; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.redis.RedisUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.utils.SpringContextUtils; +import com.epmet.feign.EpmetCommonServiceOpenFeignClient; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; + +/** + * 外部应用认证处理器:来平台token的方式 + */ +@Component +public class ExtAppFetchTokenAuthProcessor extends ExtAppAuthProcessor { + + @Autowired + private JwtUtils jwtTokenUtils; + + @Autowired + private RedisUtils redisUtils; + + @Override + public void auth(String appId, String token, Long ts, ServerWebExchange exchange) { + // 这种方式不需要其他平台传appId,因此我们自己从redis中取 + appId = (String) redisUtils.get(RedisKeys.getOpenApiAccessTokenKey(token)); + + // 1.token过期校验 + if (StringUtils.isBlank(appId)) { + throw new RenException(EpmetErrorCode.OPEN_API_SIGN_TOKEN_EXPIRED.getCode(), + EpmetErrorCode.OPEN_API_SIGN_TOKEN_EXPIRED.getMsg()); + } + + String secret = getSecret(appId); + + if (jwtTokenUtils.isTokenExpired(jwtTokenUtils.getExpiration(token, secret))) { + throw new RenException(EpmetErrorCode.OPEN_API_SIGN_TOKEN_EXPIRED.getCode(), + EpmetErrorCode.OPEN_API_SIGN_TOKEN_EXPIRED.getMsg()); + } + + // 2.验签 + // 验签暂时放到具体接口中 + //openApiSignUtils.checkSign(); + + // 2. 获取claims + Claims claims = jwtTokenUtils.getClaimByToken(token, secret); + appId = claims.get("appId", String.class); + + if (!StringUtils.isBlank(appId)) { + ServerHttpRequest.Builder mutate = exchange.getRequest().mutate(); + mutate.header("appId", appId); + exchange.mutate().request(mutate.build()).build(); + } + } + + /** + * @Description 获取秘钥 + * @return + * @author wxz + * @date 2021.03.23 14:12 + */ + private String getSecret(String appId) { + EpmetCommonServiceOpenFeignClient commonService = SpringContextUtils.getBean(EpmetCommonServiceOpenFeignClient.class); + Result result = commonService.getSecret(appId); + if (result == null || !result.success()) { + throw new RenException("fetchToken方式的外部应用认证,获取secret失败"); + } + String secret = result.getData(); + if (StringUtils.isBlank(secret)) { + throw new RenException("fetchToken方式的外部应用认证,获取secret失败"); + } + + return secret; + } +} diff --git a/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java b/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java index 8af2cdd5ef..b2ac9f477e 100644 --- a/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java +++ b/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java @@ -31,9 +31,15 @@ public class ExternalAuthProcessor extends AuthProcessor { public static final String APP_ID_CUSTOMER_ID_KEY = "CustomerId"; public static final String APP_ID_AUTY_TYPE_KEY = "AuthType"; - // 认证方式 + /** + * 认证方式 + */ + // 调用方生成jwt public static final String APP_AUTH_TYPE_JWT = "jwt"; + // 调用方生成md5 public static final String APP_AUTH_TYPE_MD5 = "md5"; + // 获取token方式 + public static final String APP_AUTH_TYPE_FETCH_TOKEN = "fetchToken"; @Autowired @@ -42,6 +48,9 @@ public class ExternalAuthProcessor extends AuthProcessor { @Autowired private ExtAppMD5AuthProcessor md5AuthProcessor; + @Autowired + private ExtAppFetchTokenAuthProcessor fetchTokenAuthProcessor; + private final AntPathMatcher antPathMatcher = new AntPathMatcher(); @Autowired @@ -68,24 +77,29 @@ public class ExternalAuthProcessor extends AuthProcessor { HttpHeaders headers = request.getHeaders(); String token = headers.getFirst(ACCESS_TOKEN_HEADER_KEY); - String appId = headers.getFirst(APP_ID_HEADER_KEY); String ts = headers.getFirst(APP_ID_TIMESTAMP_KEY); String customerId = headers.getFirst(APP_ID_CUSTOMER_ID_KEY); String authType = headers.getFirst(APP_ID_AUTY_TYPE_KEY); - if (StringUtils.isAnyBlank(token, appId)) { - throw new RenException(EpmetErrorCode.ERR401.getCode(), "请求头中的AccessToken和AppId不能为空"); - } - - logger.info("外部应用请求认证拦截Aspect执行,appId:{}, token:{}, ts:{}, customerId:{}, authType:{}", - appId, token, ts, customerId, authType); + logger.info("外部应用请求认证拦截Aspect执行,token:{}, ts:{}, customerId:{}, authType:{}", + token, ts, customerId, authType); // 没传authType或者传的jwt都用jwtprocessor处理 try { if (StringUtils.isBlank(authType) || APP_AUTH_TYPE_JWT.equals(authType)) { + String appId = headers.getFirst(APP_ID_HEADER_KEY); + if (StringUtils.isAnyBlank(token, appId)) { + throw new RenException(EpmetErrorCode.ERR401.getCode(), "请求头中的AccessToken和AppId不能为空"); + } jwtAuthProcessor.auth(appId, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange); } else if (APP_AUTH_TYPE_MD5.equals(authType)) { + String appId = headers.getFirst(APP_ID_HEADER_KEY); + if (StringUtils.isAnyBlank(token, appId)) { + throw new RenException(EpmetErrorCode.ERR401.getCode(), "请求头中的AccessToken和AppId不能为空"); + } md5AuthProcessor.auth(appId, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange); + } else if (APP_AUTH_TYPE_FETCH_TOKEN.equals(authType)) { + fetchTokenAuthProcessor.auth(null, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange); } else { throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), "未知的外部认证类型"); } diff --git a/epmet-gateway/src/main/resources/bootstrap.yml b/epmet-gateway/src/main/resources/bootstrap.yml index 7a6c236128..1e59675b46 100644 --- a/epmet-gateway/src/main/resources/bootstrap.yml +++ b/epmet-gateway/src/main/resources/bootstrap.yml @@ -422,6 +422,10 @@ feign: httpclient: enabled: true +logging: + level: + com.epmet: debug + hystrix: command: default: diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java index 66a1f46ee7..296489af6e 100644 --- a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java @@ -20,7 +20,7 @@ import java.util.Map; * @date 2020/6/4 10:28 */ @FeignClient(name = ServiceConstant.EPMET_COMMON_SERVICE, fallback = EpmetCommonServiceOpenFeignClientFallback.class) -// @FeignClient(name = ServiceConstant.EPMET_COMMON_SERVICE, fallback = EpmetCommonServiceOpenFeignClientFallback.class, url = "http://localhost:8103") + //@FeignClient(name = ServiceConstant.EPMET_COMMON_SERVICE, fallback = EpmetCommonServiceOpenFeignClientFallback.class, url = "http://192.168.1.132:8103") public interface EpmetCommonServiceOpenFeignClient { /** * @param formDTO diff --git a/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/GetOrgDetailFormDTO.java b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/GetOrgDetailFormDTO.java new file mode 100644 index 0000000000..820225682a --- /dev/null +++ b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/GetOrgDetailFormDTO.java @@ -0,0 +1,15 @@ +package com.epmet.dto.form.openapi; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +@Data +public class GetOrgDetailFormDTO extends OpenApiBaseFormDTO { + + @NotBlank(message = "orgId不能为空") + private String orgId; + + private String test; + +} diff --git a/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/OpenApiBaseFormDTO.java b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/OpenApiBaseFormDTO.java new file mode 100644 index 0000000000..c9385ece77 --- /dev/null +++ b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/OpenApiBaseFormDTO.java @@ -0,0 +1,13 @@ +package com.epmet.dto.form.openapi; + +import lombok.Data; + +/** + * open api基础类 + */ +@Data +public class OpenApiBaseFormDTO { + + private String sign; + +} diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiOrgController.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiOrgController.java new file mode 100644 index 0000000000..e3f0c9fdcd --- /dev/null +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiOrgController.java @@ -0,0 +1,63 @@ +package com.epmet.controller; + +import com.epmet.commons.security.sign.openapi.OpenApiSignUtils; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.redis.RedisUtils; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.form.openapi.GetOrgDetailFormDTO; +import com.epmet.feign.EpmetCommonServiceOpenFeignClient; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +@RestController +@RequestMapping("open-api") +public class OpenApiOrgController { + + @Autowired + private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; + + @Autowired + private RedisUtils redisUtils; + + @PostMapping("/get-org-detail") + public Result getOrgDetail(@RequestBody GetOrgDetailFormDTO input, + @RequestHeader("appId") String appId) { + // 验签 + Map params = null; + try { + params = ConvertUtils.entityToMap(input); + } catch (Exception e) { + e.printStackTrace(); + } + + if (!OpenApiSignUtils.checkSign(params, getSecret(appId))) { + // 验签失败,抛出异常提示 + throw new RenException(EpmetErrorCode.OPEN_API_SIGN_ERROR.getCode()); + } + + return new Result().ok("测试org"); + } + + private String getSecret(String appId) { + String secret = (String)redisUtils.get(RedisKeys.getExternalAppSecretKey(appId)); + if (StringUtils.isBlank(secret)) { + Result result = commonServiceOpenFeignClient.getSecret(appId); + if (!result.success()) { + throw new RenException("调用common service查询secret失败"); + } + secret = result.getData(); + if (StringUtils.isBlank(secret)) { + throw new RenException(String.format("根据appId%s没有找到对应的secret", appId)); + } + redisUtils.set(RedisKeys.getExternalAppSecretKey(appId), secret); + } + return secret; + } + +} diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java index 8610eb2ce0..4cdee0c279 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java @@ -1,18 +1,11 @@ package com.epmet.service.impl; -import com.epmet.commons.security.jwt.JwtTokenUtils; -import com.epmet.commons.tools.exception.EpmetErrorCode; -import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.security.jwt.JwtUtils; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; -import com.epmet.commons.tools.utils.Result; -import com.epmet.commons.tools.utils.SpringContextUtils; import com.epmet.config.OpenApiConfig; -import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.service.OpenApiAccessTokenService; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.util.HashMap; @@ -21,7 +14,7 @@ import java.util.HashMap; public class OpenApiAccessTokenServiceImpl implements OpenApiAccessTokenService { @Autowired - private JwtTokenUtils jwtTokenUtils; + private JwtUtils jwtTokenUtils; @Autowired private OpenApiConfig openApiConfig; @@ -37,7 +30,7 @@ public class OpenApiAccessTokenServiceImpl implements OpenApiAccessTokenService String token = jwtTokenUtils.createToken(claim, openApiConfig.getAccessTokenExpire(), secret); // 缓存token - redisUtils.set(RedisKeys.getOpenApiAccessTokenKey(appId), token, openApiConfig.getAccessTokenExpire()); + redisUtils.set(RedisKeys.getOpenApiAccessTokenKey(token), appId, openApiConfig.getAccessTokenExpire()); return token; } From 9cc61899a0a9578b7f8db1562986b951148c1e87 Mon Sep 17 00:00:00 2001 From: wxz Date: Wed, 24 Mar 2021 10:54:51 +0800 Subject: [PATCH 03/18] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-gateway/src/main/resources/bootstrap.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/epmet-gateway/src/main/resources/bootstrap.yml b/epmet-gateway/src/main/resources/bootstrap.yml index 1e59675b46..1e6189861c 100644 --- a/epmet-gateway/src/main/resources/bootstrap.yml +++ b/epmet-gateway/src/main/resources/bootstrap.yml @@ -422,9 +422,9 @@ feign: httpclient: enabled: true -logging: - level: - com.epmet: debug +#logging: +# level: +# com.epmet: debug hystrix: command: From 0e0f3142e474fa028510b330dad2b290347d495f Mon Sep 17 00:00:00 2001 From: wxz Date: Wed, 24 Mar 2021 13:52:18 +0800 Subject: [PATCH 04/18] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=20=E9=AA=8C?= =?UTF-8?q?=E7=AD=BE=E6=B3=A8=E8=A7=A3=E5=92=8CAOP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/ExtAppFetchTokenAuthProcessor.java | 2 +- .../epmet/annotation/OpenApiCheckSign.java | 13 ++ .../epmet/aspect/OpenApiCheckSignAspect.java | 125 ++++++++++++++++++ .../controller/OpenApiOrgController.java | 56 ++------ 4 files changed, 149 insertions(+), 47 deletions(-) create mode 100644 epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/annotation/OpenApiCheckSign.java create mode 100644 epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiCheckSignAspect.java diff --git a/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java b/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java index 236914ccb2..728c3b54e0 100644 --- a/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java +++ b/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java @@ -57,7 +57,7 @@ public class ExtAppFetchTokenAuthProcessor extends ExtAppAuthProcessor { if (!StringUtils.isBlank(appId)) { ServerHttpRequest.Builder mutate = exchange.getRequest().mutate(); - mutate.header("appId", appId); + mutate.header("AppId", appId); exchange.mutate().request(mutate.build()).build(); } } diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/annotation/OpenApiCheckSign.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/annotation/OpenApiCheckSign.java new file mode 100644 index 0000000000..10bbcc156e --- /dev/null +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/annotation/OpenApiCheckSign.java @@ -0,0 +1,13 @@ +package com.epmet.annotation; + +import java.lang.annotation.*; + +/** + * OpenApi验签注解 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface OpenApiCheckSign { + +} diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiCheckSignAspect.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiCheckSignAspect.java new file mode 100644 index 0000000000..21953df71a --- /dev/null +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiCheckSignAspect.java @@ -0,0 +1,125 @@ +package com.epmet.aspect; + +import com.epmet.commons.mybatis.aspect.DataFilterAspect; +import com.epmet.commons.security.sign.openapi.OpenApiSignUtils; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.redis.RedisUtils; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.feign.EpmetCommonServiceOpenFeignClient; +import org.apache.commons.lang3.StringUtils; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.reflect.MethodSignature; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import java.beans.IntrospectionException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.Arrays; +import java.util.Map; +import java.util.Set; + +@Aspect +@Component +@Order(1) +public class OpenApiCheckSignAspect { + + @Autowired + private RedisUtils redisUtils; + + @Autowired + private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; + + private static final Logger log = LoggerFactory.getLogger(DataFilterAspect.class); + + /** + * @Description 验签 + * @return + * @author wxz + * @date 2021.03.24 13:39 + */ + @Before("execution(* com.epmet.controller.*Controller*.*(..)) && @annotation(com.epmet.annotation.OpenApiCheckSign)") + public void checkSign(JoinPoint point) { + Object[] args = point.getArgs(); + MethodSignature methodSignature = (MethodSignature) point.getSignature(); + Method method = methodSignature.getMethod(); + Parameter[] parameters = method.getParameters(); + for (int i = 0; i < parameters.length; i++) { + if (parameters[i].isAnnotationPresent(RequestBody.class)) { + Map argMap = null; + try { + argMap = ConvertUtils.entityToMap(args[i]); + } catch (Exception e) { + throw new RenException("验签参数转化发生异常"); + } + if (!OpenApiSignUtils.checkSign(argMap, getSecret(getAppId()))) { + // 验签失败 + throw new RenException(EpmetErrorCode.OPEN_API_SIGN_ERROR.getCode()); + } + } + } + } + + /** + * @return + * @Description 取secret + * @author wxz + * @date 2021.03.24 12:49 + */ + private String getSecret(String appId) { + String secret = (String) redisUtils.get(RedisKeys.getExternalAppSecretKey(appId)); + if (StringUtils.isBlank(secret)) { + Result result = commonServiceOpenFeignClient.getSecret(appId); + if (!result.success()) { + throw new RenException("调用common service查询secret失败"); + } + secret = result.getData(); + if (StringUtils.isBlank(secret)) { + throw new RenException(String.format("根据appId%s没有找到对应的secret", appId)); + } + redisUtils.set(RedisKeys.getExternalAppSecretKey(appId), secret); + } + return secret; + } + + /** + * @return + * @Description 获取request + * @author wxz + * @date 2021.03.24 12:52 + */ + public HttpServletRequest getRequest() { + RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); + ServletRequestAttributes sra = (ServletRequestAttributes) requestAttributes; + return sra.getRequest(); + } + + /** + * @return + * @Description 获取appId + * @author wxz + * @date 2021.03.24 12:53 + */ + public String getAppId() { + HttpServletRequest request = getRequest(); + String appId = request.getHeader("AppId"); + if (StringUtils.isBlank(appId)) { + throw new RenException("请求头中未携带AppId"); + } + return appId; + } +} diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiOrgController.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiOrgController.java index e3f0c9fdcd..30e97da2bf 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiOrgController.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiOrgController.java @@ -1,63 +1,27 @@ package com.epmet.controller; -import com.epmet.commons.security.sign.openapi.OpenApiSignUtils; -import com.epmet.commons.tools.exception.EpmetErrorCode; -import com.epmet.commons.tools.exception.RenException; -import com.epmet.commons.tools.redis.RedisKeys; -import com.epmet.commons.tools.redis.RedisUtils; -import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.annotation.OpenApiCheckSign; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.form.openapi.GetOrgDetailFormDTO; -import com.epmet.feign.EpmetCommonServiceOpenFeignClient; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import java.util.Map; - @RestController @RequestMapping("open-api") public class OpenApiOrgController { - @Autowired - private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; - - @Autowired - private RedisUtils redisUtils; - + /** + * @Description OpenApiCheckSign是验签注解,OpenApi的接口请加上该注解 + * @return + * @author wxz + * @date 2021.03.24 12:55 + */ + @OpenApiCheckSign @PostMapping("/get-org-detail") public Result getOrgDetail(@RequestBody GetOrgDetailFormDTO input, - @RequestHeader("appId") String appId) { - // 验签 - Map params = null; - try { - params = ConvertUtils.entityToMap(input); - } catch (Exception e) { - e.printStackTrace(); - } - - if (!OpenApiSignUtils.checkSign(params, getSecret(appId))) { - // 验签失败,抛出异常提示 - throw new RenException(EpmetErrorCode.OPEN_API_SIGN_ERROR.getCode()); - } - + @RequestHeader("AppId") String appId) { return new Result().ok("测试org"); } - private String getSecret(String appId) { - String secret = (String)redisUtils.get(RedisKeys.getExternalAppSecretKey(appId)); - if (StringUtils.isBlank(secret)) { - Result result = commonServiceOpenFeignClient.getSecret(appId); - if (!result.success()) { - throw new RenException("调用common service查询secret失败"); - } - secret = result.getData(); - if (StringUtils.isBlank(secret)) { - throw new RenException(String.format("根据appId%s没有找到对应的secret", appId)); - } - redisUtils.set(RedisKeys.getExternalAppSecretKey(appId), secret); - } - return secret; - } + } From e9377ae529e3485045df16723df6cb51ed755bc3 Mon Sep 17 00:00:00 2001 From: wxz Date: Thu, 25 Mar 2021 16:52:44 +0800 Subject: [PATCH 05/18] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aepmet-commons-?= =?UTF-8?q?openapi=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-commons/epmet-commons-openapi/pom.xml | 17 +++++++++++++++++ .../openapi/constants/HeaderFieldKeys.java | 7 +++++++ .../openapi/constants/RequestBodyFieldKeys.java | 10 ++++++++++ .../openapi/constants/RequestParamKeys.java | 11 +++++++++++ 4 files changed, 45 insertions(+) create mode 100644 epmet-commons/epmet-commons-openapi/pom.xml create mode 100644 epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/HeaderFieldKeys.java create mode 100644 epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestBodyFieldKeys.java create mode 100644 epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestParamKeys.java diff --git a/epmet-commons/epmet-commons-openapi/pom.xml b/epmet-commons/epmet-commons-openapi/pom.xml new file mode 100644 index 0000000000..61a6197357 --- /dev/null +++ b/epmet-commons/epmet-commons-openapi/pom.xml @@ -0,0 +1,17 @@ + + + + 2.0.0 + + epmet-commons + com.epmet + 2.0.0 + + 4.0.0 + + epmet-commons-openapi + + + \ No newline at end of file diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/HeaderFieldKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/HeaderFieldKeys.java new file mode 100644 index 0000000000..35dfff71db --- /dev/null +++ b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/HeaderFieldKeys.java @@ -0,0 +1,7 @@ +package com.epmet.commons.openapi.constants; + +public interface HeaderFieldKeys { + + String APP_ID = "AppId"; + +} diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestBodyFieldKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestBodyFieldKeys.java new file mode 100644 index 0000000000..3c461a6c69 --- /dev/null +++ b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestBodyFieldKeys.java @@ -0,0 +1,10 @@ +package com.epmet.commons.openapi.constants; + +/** + * 请求体字段key + */ +public interface RequestBodyFieldKeys { + + String APP_ID = "appId"; + +} diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestParamKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestParamKeys.java new file mode 100644 index 0000000000..08c6c092b1 --- /dev/null +++ b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestParamKeys.java @@ -0,0 +1,11 @@ +package com.epmet.commons.openapi.constants; + +/** + * url请求参数key + */ +public class RequestParamKeys { + + public static String APP_ID = "app_id"; + public static String AUTH_TYPE = "auth_type"; + +} From e3eae2955768d17947f6465599200a4337f509e4 Mon Sep 17 00:00:00 2001 From: jianjun Date: Thu, 25 Mar 2021 16:57:36 +0800 Subject: [PATCH 06/18] =?UTF-8?q?=E5=BC=95=E5=85=A5openApi=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-gateway/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/epmet-gateway/pom.xml b/epmet-gateway/pom.xml index 560063fe23..5414a2cb14 100644 --- a/epmet-gateway/pom.xml +++ b/epmet-gateway/pom.xml @@ -70,6 +70,11 @@ common-service-client 2.0.0 + + com.epmet + epmet-commons-openapi + 2.0.0 + From dfaf657c44f328783ff2ffe5bfccb06f8e7423d3 Mon Sep 17 00:00:00 2001 From: jianjun Date: Thu, 25 Mar 2021 18:00:58 +0800 Subject: [PATCH 07/18] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20commons=20openapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-commons/epmet-commons-openapi/pom.xml | 4 +--- .../openapi/constants => openapi}/HeaderFieldKeys.java | 2 +- .../openapi/constants => openapi}/RequestBodyFieldKeys.java | 2 +- .../openapi/constants => openapi}/RequestParamKeys.java | 2 +- epmet-commons/pom.xml | 3 ++- epmet-gateway/pom.xml | 1 + 6 files changed, 7 insertions(+), 7 deletions(-) rename epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/{commons/openapi/constants => openapi}/HeaderFieldKeys.java (60%) rename epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/{commons/openapi/constants => openapi}/RequestBodyFieldKeys.java (69%) rename epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/{commons/openapi/constants => openapi}/RequestParamKeys.java (78%) diff --git a/epmet-commons/epmet-commons-openapi/pom.xml b/epmet-commons/epmet-commons-openapi/pom.xml index 61a6197357..41093f03fa 100644 --- a/epmet-commons/epmet-commons-openapi/pom.xml +++ b/epmet-commons/epmet-commons-openapi/pom.xml @@ -2,8 +2,6 @@ - - 2.0.0 epmet-commons com.epmet @@ -14,4 +12,4 @@ epmet-commons-openapi - \ No newline at end of file + diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/HeaderFieldKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/HeaderFieldKeys.java similarity index 60% rename from epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/HeaderFieldKeys.java rename to epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/HeaderFieldKeys.java index 35dfff71db..9360c5f51f 100644 --- a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/HeaderFieldKeys.java +++ b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/HeaderFieldKeys.java @@ -1,4 +1,4 @@ -package com.epmet.commons.openapi.constants; +package com.epmet.openapi; public interface HeaderFieldKeys { diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestBodyFieldKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/RequestBodyFieldKeys.java similarity index 69% rename from epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestBodyFieldKeys.java rename to epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/RequestBodyFieldKeys.java index 3c461a6c69..3ce4555283 100644 --- a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestBodyFieldKeys.java +++ b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/RequestBodyFieldKeys.java @@ -1,4 +1,4 @@ -package com.epmet.commons.openapi.constants; +package com.epmet.openapi; /** * 请求体字段key diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestParamKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/RequestParamKeys.java similarity index 78% rename from epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestParamKeys.java rename to epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/RequestParamKeys.java index 08c6c092b1..a503713682 100644 --- a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestParamKeys.java +++ b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/RequestParamKeys.java @@ -1,4 +1,4 @@ -package com.epmet.commons.openapi.constants; +package com.epmet.openapi; /** * url请求参数key diff --git a/epmet-commons/pom.xml b/epmet-commons/pom.xml index b495dd438e..9e0d315827 100644 --- a/epmet-commons/pom.xml +++ b/epmet-commons/pom.xml @@ -26,6 +26,7 @@ epmet-commons-thirdplat epmet-commons-rocketmq epmet-commons-security - + epmet-commons-openapi + diff --git a/epmet-gateway/pom.xml b/epmet-gateway/pom.xml index 5414a2cb14..d901d0940e 100644 --- a/epmet-gateway/pom.xml +++ b/epmet-gateway/pom.xml @@ -74,6 +74,7 @@ com.epmet epmet-commons-openapi 2.0.0 + compile From 64aca2e5defd9df4ec9a31b471a179aa7c454e8c Mon Sep 17 00:00:00 2001 From: wxz Date: Thu, 25 Mar 2021 20:38:52 +0800 Subject: [PATCH 08/18] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E4=BC=A0?= =?UTF-8?q?=E5=8F=82=E6=96=B9=E5=BC=8F=E4=BF=AE=E6=94=B9=20half?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-commons/epmet-commons-openapi/pom.xml | 17 ---- .../openapi/constants/HeaderFieldKeys.java | 7 -- .../constants/RequestBodyFieldKeys.java | 10 -- .../openapi/constants/RequestParamKeys.java | 11 --- .../sign/openapi/OpenApiSignUtils.java | 36 ++++++-- .../tools/exception/EpmetErrorCode.java | 4 +- .../epmet/commons/tools/redis/RedisKeys.java | 10 ++ .../auth/ExtAppFetchTokenAuthProcessor.java | 29 +++--- .../com/epmet/auth/ExternalAuthProcessor.java | 17 +++- .../filter/CpAuthGatewayFilterFactory.java | 6 ++ .../java/com/epmet/filter/CpProperty.java | 5 + .../epmet/utils/ServerHttpRequestUtils.java | 19 ++++ .../src/main/resources/bootstrap.yml | 5 + .../epmet/dto/form/AccessTokenFormDTO.java | 9 +- .../dto/form/openapi/OpenApiBaseFormDTO.java | 18 ++++ ...ct.java => OpenApiRequestCheckAspect.java} | 91 ++++++++++++++++--- .../OpenApiAccessTokenController.java | 20 +--- pom.xml | 2 +- 18 files changed, 212 insertions(+), 104 deletions(-) delete mode 100644 epmet-commons/epmet-commons-openapi/pom.xml delete mode 100644 epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/HeaderFieldKeys.java delete mode 100644 epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestBodyFieldKeys.java delete mode 100644 epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestParamKeys.java create mode 100644 epmet-gateway/src/main/java/com/epmet/utils/ServerHttpRequestUtils.java rename epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/{OpenApiCheckSignAspect.java => OpenApiRequestCheckAspect.java} (59%) diff --git a/epmet-commons/epmet-commons-openapi/pom.xml b/epmet-commons/epmet-commons-openapi/pom.xml deleted file mode 100644 index 61a6197357..0000000000 --- a/epmet-commons/epmet-commons-openapi/pom.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - 2.0.0 - - epmet-commons - com.epmet - 2.0.0 - - 4.0.0 - - epmet-commons-openapi - - - \ No newline at end of file diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/HeaderFieldKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/HeaderFieldKeys.java deleted file mode 100644 index 35dfff71db..0000000000 --- a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/HeaderFieldKeys.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.epmet.commons.openapi.constants; - -public interface HeaderFieldKeys { - - String APP_ID = "AppId"; - -} diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestBodyFieldKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestBodyFieldKeys.java deleted file mode 100644 index 3c461a6c69..0000000000 --- a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestBodyFieldKeys.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.epmet.commons.openapi.constants; - -/** - * 请求体字段key - */ -public interface RequestBodyFieldKeys { - - String APP_ID = "appId"; - -} diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestParamKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestParamKeys.java deleted file mode 100644 index 08c6c092b1..0000000000 --- a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/commons/openapi/constants/RequestParamKeys.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.epmet.commons.openapi.constants; - -/** - * url请求参数key - */ -public class RequestParamKeys { - - public static String APP_ID = "app_id"; - public static String AUTH_TYPE = "auth_type"; - -} diff --git a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java index 306bb5ab3d..9a64226174 100644 --- a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java +++ b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java @@ -2,10 +2,7 @@ package com.epmet.commons.security.sign.openapi; import com.epmet.commons.tools.utils.Md5Util; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * OpenApi签名工具 @@ -62,16 +59,41 @@ public class OpenApiSignUtils { return sb.toString(); } - public static void main(String[] args) { + //generateGetAccessTokenSign(); + generateGetOrgDetailSign(); + } + + private static void generateGetAccessTokenSign() { + long now = System.currentTimeMillis(); + System.out.println(now); HashMap content = new HashMap<>(); - content.put("orgId", "aaa"); - content.put("test", ""); + content.put("appId", "7d98b8af2d05752b4225709c4cfd4bd0"); + content.put("timestamp", String.valueOf(now)); + content.put("nonce", "aaa"); String secret = "3209ee9f41704482be1a1fb5873a25376f2899191ca846119d44168316bc3e44"; String sign = createSign(content, secret); System.out.println(sign); } + + private static void generateGetOrgDetailSign() { + long now = System.currentTimeMillis(); + String uuid = UUID.randomUUID().toString(); + System.out.println("时间戳:" + now); + System.out.println("随机数:" + uuid); + + HashMap content = new HashMap<>(); + content.put("orgId", "aaa"); + content.put("test", null); + content.put("timestamp", String.valueOf(now)); + content.put("nonce", uuid); + + String secret = "3209ee9f41704482be1a1fb5873a25376f2899191ca846119d44168316bc3e44"; + + String sign = createSign(content, secret); + System.out.println("签名:" + sign); + } } diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index e22f5f7983..f83a55d32f 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -147,7 +147,9 @@ public enum EpmetErrorCode { // open api异常 OPEN_API_SIGN_ERROR(9100, "签名错误"), - OPEN_API_SIGN_TOKEN_EXPIRED(9101, "Token过期"); + OPEN_API_TOKEN_EXPIRED(9101, "Token过期"), + OPEN_API_PARAMS_MISSING(9102, "参数不完整"), + OPEN_API_PARAMS_APPID_DIFF(9103, "app_id不一致"); // app_id在请求参数中和在token中不一致 private int code; private String msg; diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index 4d21946025..dd5ca2e18a 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -396,4 +396,14 @@ public class RedisKeys { public static String getOpenApiAccessTokenKey(String accessToken) { return rootPrefix.concat("openapi:accesstoken:").concat(accessToken); } + + /** + * @Description 获取OpenApi请求随机数nonce + * @return + * @author wxz + * @date 2021.03.24 17:49 + */ + public static String getOpenApiNonceKey(String nonce) { + return rootPrefix.concat("openapi:nonce:").concat(nonce); + } } diff --git a/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java b/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java index 728c3b54e0..5954b2bd30 100644 --- a/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java +++ b/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java @@ -26,25 +26,19 @@ public class ExtAppFetchTokenAuthProcessor extends ExtAppAuthProcessor { @Autowired private JwtUtils jwtTokenUtils; - @Autowired - private RedisUtils redisUtils; - @Override public void auth(String appId, String token, Long ts, ServerWebExchange exchange) { - // 这种方式不需要其他平台传appId,因此我们自己从redis中取 - appId = (String) redisUtils.get(RedisKeys.getOpenApiAccessTokenKey(token)); - // 1.token过期校验 if (StringUtils.isBlank(appId)) { - throw new RenException(EpmetErrorCode.OPEN_API_SIGN_TOKEN_EXPIRED.getCode(), - EpmetErrorCode.OPEN_API_SIGN_TOKEN_EXPIRED.getMsg()); + throw new RenException(EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getCode(), + EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getMsg()); } String secret = getSecret(appId); if (jwtTokenUtils.isTokenExpired(jwtTokenUtils.getExpiration(token, secret))) { - throw new RenException(EpmetErrorCode.OPEN_API_SIGN_TOKEN_EXPIRED.getCode(), - EpmetErrorCode.OPEN_API_SIGN_TOKEN_EXPIRED.getMsg()); + throw new RenException(EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getCode(), + EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getMsg()); } // 2.验签 @@ -53,13 +47,18 @@ public class ExtAppFetchTokenAuthProcessor extends ExtAppAuthProcessor { // 2. 获取claims Claims claims = jwtTokenUtils.getClaimByToken(token, secret); - appId = claims.get("appId", String.class); + String appIdInAccessToken = claims.get("appId", String.class); - if (!StringUtils.isBlank(appId)) { - ServerHttpRequest.Builder mutate = exchange.getRequest().mutate(); - mutate.header("AppId", appId); - exchange.mutate().request(mutate.build()).build(); + if (!appId.equals(appIdInAccessToken)) { + // 参数列表的appId和token中封装的不一致 + throw new RenException(EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getCode(), + EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getMsg()); } + + // 3.将app_id放入header中 + ServerHttpRequest.Builder mutate = exchange.getRequest().mutate(); + mutate.header("AppId", appId); + exchange.mutate().request(mutate.build()).build(); } /** diff --git a/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java b/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java index b2ac9f477e..1b928ac295 100644 --- a/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java +++ b/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java @@ -4,6 +4,7 @@ import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.exception.RenException; import com.epmet.filter.CpProperty; +import com.epmet.utils.ServerHttpRequestUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,6 +14,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.stereotype.Component; import org.springframework.util.AntPathMatcher; +import org.springframework.util.MultiValueMap; import org.springframework.web.server.ServerWebExchange; /** @@ -67,6 +69,7 @@ public class ExternalAuthProcessor extends AuthProcessor { for (String url : cpProperty.getExternalOpenUrls()) { if (antPathMatcher.match(url, requestUri)) { inPaths = true; + break; } } @@ -74,6 +77,13 @@ public class ExternalAuthProcessor extends AuthProcessor { throw new RenException(EpmetErrorCode.ERR401.getCode(), "所请求的url并未对外部应用开放"); } + // 放行白名单 + for (String url : cpProperty.getExternalAuthUrlsWhiteList()) { + if (antPathMatcher.match(url, requestUri)) { + return exchange; + } + } + HttpHeaders headers = request.getHeaders(); String token = headers.getFirst(ACCESS_TOKEN_HEADER_KEY); @@ -99,7 +109,12 @@ public class ExternalAuthProcessor extends AuthProcessor { } md5AuthProcessor.auth(appId, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange); } else if (APP_AUTH_TYPE_FETCH_TOKEN.equals(authType)) { - fetchTokenAuthProcessor.auth(null, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange); + String paramName = "app_id"; + String appId = ServerHttpRequestUtils.getRequestParam(request, paramName); + if (StringUtils.isBlank(appId)) { + throw new RenException(EpmetErrorCode.OPEN_API_PARAMS_MISSING.getCode(),"缺少参数".concat(paramName)); + } + fetchTokenAuthProcessor.auth(appId, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange); } else { throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), "未知的外部认证类型"); } diff --git a/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java b/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java index bb97dc2be7..c01c553b75 100644 --- a/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java +++ b/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java @@ -10,6 +10,7 @@ import com.epmet.commons.tools.utils.IpUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.constant.AuthTypeConstant; import com.epmet.constant.TokenHeaderKeyConstant; +import com.epmet.utils.ServerHttpRequestUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -111,6 +112,11 @@ public class CpAuthGatewayFilterFactory extends AbstractGatewayFilterFactory externalOpenUrls; + /** + * 对外开放url白名单 + */ + private List externalAuthUrlsWhiteList; + /** * 不处理token,直接通过 */ diff --git a/epmet-gateway/src/main/java/com/epmet/utils/ServerHttpRequestUtils.java b/epmet-gateway/src/main/java/com/epmet/utils/ServerHttpRequestUtils.java new file mode 100644 index 0000000000..334134baa1 --- /dev/null +++ b/epmet-gateway/src/main/java/com/epmet/utils/ServerHttpRequestUtils.java @@ -0,0 +1,19 @@ +package com.epmet.utils; + +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.util.MultiValueMap; + +public class ServerHttpRequestUtils { + + /** + * @Description 从url中获取appId + * @return + * @author wxz + * @date 2021.03.25 15:13 + */ + public static String getRequestParam(ServerHttpRequest request, String paramName) { + MultiValueMap queryParams = request.getQueryParams(); + return queryParams.getFirst(paramName); + } + +} diff --git a/epmet-gateway/src/main/resources/bootstrap.yml b/epmet-gateway/src/main/resources/bootstrap.yml index ce7d55ae65..436d4d9225 100644 --- a/epmet-gateway/src/main/resources/bootstrap.yml +++ b/epmet-gateway/src/main/resources/bootstrap.yml @@ -474,6 +474,11 @@ epmet: - /epmetuser/customerstaff/customerlist - /message/template/** - /data/aggregator/project/projectdistribution + + # 对外开放接口认证白名单 + externalAuthUrlsWhiteList: + - /epmet/ext/open-api/get-access-token + swaggerUrls: jwt: diff --git a/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/AccessTokenFormDTO.java b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/AccessTokenFormDTO.java index 4b315ae326..9fe569e75e 100644 --- a/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/AccessTokenFormDTO.java +++ b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/AccessTokenFormDTO.java @@ -1,17 +1,12 @@ package com.epmet.dto.form; +import com.epmet.dto.form.openapi.OpenApiBaseFormDTO; import lombok.Data; import javax.validation.constraints.NotBlank; @Data -public class AccessTokenFormDTO { - - public interface GetAccessTokenGroup {} - - // 签名字符串密文 - @NotBlank(message = "签名字段不能为空", groups = { GetAccessTokenGroup.class }) - private String sign; +public class AccessTokenFormDTO extends OpenApiBaseFormDTO { // 应用id @NotBlank(message = "AppId字段不能为空", groups = { GetAccessTokenGroup.class }) diff --git a/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/OpenApiBaseFormDTO.java b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/OpenApiBaseFormDTO.java index c9385ece77..68f46e351b 100644 --- a/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/OpenApiBaseFormDTO.java +++ b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/OpenApiBaseFormDTO.java @@ -2,12 +2,30 @@ package com.epmet.dto.form.openapi; import lombok.Data; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + /** * open api基础类 */ @Data public class OpenApiBaseFormDTO { + public interface GetAccessTokenGroup {} + + @NotBlank(message = "签名不能为空", groups = { GetAccessTokenGroup.class }) private String sign; + /** + * 时间戳,ms + */ + @NotNull(message = "时间戳不能为空", groups = { GetAccessTokenGroup.class }) + private Long timestamp; + + /** + * 随机数,每次请求唯一 + */ + @NotBlank(message = "随机字段nonce不能为空", groups = { GetAccessTokenGroup.class }) + private String nonce; + } diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiCheckSignAspect.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java similarity index 59% rename from epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiCheckSignAspect.java rename to epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java index 21953df71a..22f3280c25 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiCheckSignAspect.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java @@ -26,6 +26,7 @@ import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; import java.beans.IntrospectionException; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Parameter; @@ -33,10 +34,15 @@ import java.util.Arrays; import java.util.Map; import java.util.Set; +/** + * OpenApi检查请求切面 + * 1.验签防止参数篡改 + * 2.timestamp+nonce防止请求重放攻击 + */ @Aspect @Component @Order(1) -public class OpenApiCheckSignAspect { +public class OpenApiRequestCheckAspect { @Autowired private RedisUtils redisUtils; @@ -53,27 +59,60 @@ public class OpenApiCheckSignAspect { * @date 2021.03.24 13:39 */ @Before("execution(* com.epmet.controller.*Controller*.*(..)) && @annotation(com.epmet.annotation.OpenApiCheckSign)") - public void checkSign(JoinPoint point) { + public void check(JoinPoint point) { Object[] args = point.getArgs(); MethodSignature methodSignature = (MethodSignature) point.getSignature(); Method method = methodSignature.getMethod(); Parameter[] parameters = method.getParameters(); + + HttpServletRequest request = getRequest(); + String appId = request.getHeader("AppId"); + for (int i = 0; i < parameters.length; i++) { if (parameters[i].isAnnotationPresent(RequestBody.class)) { - Map argMap = null; + Map argMap; try { argMap = ConvertUtils.entityToMap(args[i]); } catch (Exception e) { throw new RenException("验签参数转化发生异常"); } - if (!OpenApiSignUtils.checkSign(argMap, getSecret(getAppId()))) { + + argMap.put(""); + + if (!OpenApiSignUtils.checkSign(argMap, getSecret(appId))) { // 验签失败 throw new RenException(EpmetErrorCode.OPEN_API_SIGN_ERROR.getCode()); } + checkRepeatRequest(argMap); } } } + /** + * 检查请求重放 + * @param argMap + */ + void checkRepeatRequest(Map argMap) { + String timestampStr = argMap.get("timestamp"); + if (StringUtils.isBlank(timestampStr)) { + throw new RenException(EpmetErrorCode.OPEN_API_PARAMS_MISSING.getCode()); + } + long timestamp = Long.valueOf(timestampStr).longValue(); + long now = System.currentTimeMillis(); + long requestTimeDiff = 60000; + if (Math.abs(now - timestamp) > requestTimeDiff) { + // 只允许1分钟之内的请求,允许服务器之间时差为1分钟 + throw new RenException(String.format("请求已过时,允许时差为%s ms", requestTimeDiff)); + } + String nonce = argMap.get("nonce"); + String nonceInCache = redisUtils.getString(RedisKeys.getOpenApiNonceKey(nonce)); + if (StringUtils.isNotBlank(nonceInCache)) { + throw new RenException("请求重复"); + } + //将nonce缓存到redis,有效期1分钟 + redisUtils.set(RedisKeys.getOpenApiNonceKey(nonce), "1", requestTimeDiff); + } + /** * @return * @Description 取secret @@ -114,12 +153,42 @@ public class OpenApiCheckSignAspect { * @author wxz * @date 2021.03.24 12:53 */ - public String getAppId() { - HttpServletRequest request = getRequest(); - String appId = request.getHeader("AppId"); - if (StringUtils.isBlank(appId)) { - throw new RenException("请求头中未携带AppId"); - } - return appId; + //public String getAppId(Parameter[] parameters, Object[] args) { + // HttpServletRequest request = getRequest(); + // String appId = request.getHeader("AppId"); + // if (StringUtils.isBlank(appId)) { + // for (int i = 0; i < parameters.length; i++) { + // if (parameters[i].isAnnotationPresent(RequestBody.class)) { + // Object arg = args[i]; + // try { + // appId = getAppIdFromDTO(arg); + // } catch (IllegalAccessException e) { + // e.printStackTrace(); + // } + // } + // } + // } + // if (StringUtils.isBlank(appId)) { + // throw new RenException("未携带AppId"); + // } + // return appId; + //} + + //private String getAppIdFromDTO(Object dto) throws IllegalAccessException { + // Field[] declaredFields = dto.getClass().getDeclaredFields(); + // for (int i = 0; i < declaredFields.length; i++) { + // Field field = declaredFields[i]; + // String fieldName = field.getName(); + // if ("appId".equals(fieldName)) { + // field.setAccessible(true); + // String value = (String) field.get(dto); + // return value; + // } + // } + // return null; + //} + + public static void main(String[] args) { + System.out.println(System.currentTimeMillis()); } } diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java index 1580ca1b6a..c189e2fb3b 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java @@ -1,5 +1,6 @@ package com.epmet.controller; +import com.epmet.annotation.OpenApiCheckSign; import com.epmet.commons.security.sign.openapi.OpenApiSignUtils; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.ExceptionUtils; @@ -10,6 +11,7 @@ import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.form.AccessTokenFormDTO; +import com.epmet.dto.form.openapi.OpenApiBaseFormDTO; import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.service.OpenApiAccessTokenService; import org.apache.commons.lang3.StringUtils; @@ -45,10 +47,11 @@ public class OpenApiAccessTokenController { * @author wxz * @date 2021.03.23 09:52 */ + @OpenApiCheckSign @PostMapping("get-access-token") public Result getAccessToken(@RequestBody AccessTokenFormDTO input) { // 1.校验参数 - ValidatorUtils.validateEntity(input); + ValidatorUtils.validateEntity(input, OpenApiBaseFormDTO.GetAccessTokenGroup.class); String appId = input.getAppId(); // 2.取secret @@ -65,21 +68,6 @@ public class OpenApiAccessTokenController { redisUtils.set(RedisKeys.getExternalAppSecretKey(appId), secret); } - // 3.验签 - try { - if (!OpenApiSignUtils.checkSign(ConvertUtils.entityToMap(input), secret)) { - throw new RenException(EpmetErrorCode.OPEN_API_SIGN_ERROR.getCode(), EpmetErrorCode.OPEN_API_SIGN_ERROR.getMsg()); - } - } catch (RenException e) { - // 如果是自己抛出的异常则继续抛出 - throw e; - } catch (Exception e) { - // 是其他意外发生的异常 - String errorStackTrace = ExceptionUtils.getErrorStackTrace(e); - logger.error("验签发生未知异常:{}", errorStackTrace); - throw new RenException("验签发生未知异常,请查看ext服务详细日志"); - } - //4.生成token String accessToken = openApiAccessTokenService.getAccessToken(appId, secret); return new Result().ok(accessToken); diff --git a/pom.xml b/pom.xml index b0d6621300..9420c9ff24 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ epmet-module epmet-user epmet-openapi - + UTF-8 From 8afaecaee60ae021fa08beb47edf2e177581b133 Mon Sep 17 00:00:00 2001 From: wxz Date: Thu, 25 Mar 2021 20:44:01 +0800 Subject: [PATCH 09/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet-openapi-adv-client/pom.xml | 16 - .../epmet-openapi-adv-server/Dockerfile | 11 - .../deploy/docker-compose-dev.yml | 18 - .../deploy/docker-compose-prod.yml | 18 - .../deploy/docker-compose-test.yml | 18 - .../epmet-openapi-adv-server/pom.xml | 227 ------ .../java/com/epmet/adv/AdvApplication.java | 15 - .../epmet/adv/aspect/RequestLogAspect.java | 40 - .../epmet/adv/config/ModuleConfigImpl.java | 26 - .../adv/controller/AdvVideoController.java | 28 - .../java/com/epmet/adv/dao/AdvVedioDao.java | 33 - .../com/epmet/adv/entity/AdvVedioEntity.java | 56 -- .../epmet/adv/service/AdvVedioService.java | 7 - .../adv/service/impl/AdvVedioServiceImpl.java | 18 - .../src/main/resources/bootstrap.yml | 140 ---- .../db/migration/V0.0.1__createAdvVedio.sql | 18 - .../src/main/resources/logback-spring.xml | 169 ---- .../src/main/resources/mapper/AdvVedioDao.xml | 35 - epmet-openapi/epmet-openapi-adv/pom.xml | 21 - epmet-openapi/epmet-openapi-scan/Dockerfile | 11 - .../deploy/docker-compose-dev.yml | 18 - .../deploy/docker-compose-prod.yml | 18 - .../deploy/docker-compose-test.yml | 18 - epmet-openapi/epmet-openapi-scan/pom.xml | 208 ----- .../epmet/openapi/scan/ScanApplication.java | 30 - .../openapi/scan/aspect/RequestLogAspect.java | 40 - .../scan/common/constant/SysConstant.java | 30 - .../scan/common/enu/CommonErrorCodeEnum.java | 68 -- .../openapi/scan/common/enu/ImgSceneEnum.java | 47 -- .../openapi/scan/common/enu/LabelEnum.java | 66 -- .../openapi/scan/common/enu/RegionIdEnum.java | 49 -- .../scan/common/enu/SuggestionEnum.java | 48 -- .../scan/common/enu/SysResponseEnum.java | 46 -- .../scan/common/enu/TextSceneEnum.java | 46 -- .../scan/common/enu/VideoSceneEnum.java | 50 -- .../scan/common/enu/VoiceSceneEnum.java | 47 -- .../exception/ExecuteHttpException.java | 29 - .../openapi/scan/common/redis/RedisKeys.java | 38 - .../scan/common/util/HttpClientManager.java | 171 ---- .../scan/common/util/IAcsClientUtil.java | 67 -- .../openapi/scan/common/util/MapUtil.java | 55 -- .../openapi/scan/config/ModuleConfigImpl.java | 26 - .../openapi/scan/config/WebAppConfig.java | 31 - .../scan/controller/BackDoorController.java | 32 - .../scan/controller/ScanController.java | 116 --- .../interceptor/ScanApiAuthInterceptor.java | 60 -- .../scan/service/impl/ScanService.java | 69 -- .../scan/service/impl/ScanServiceImpl.java | 734 ------------------ .../scan/support/param/ImgScanParam.java | 48 -- .../openapi/scan/support/param/ImgTask.java | 31 - .../scan/support/param/TextScanParam.java | 48 -- .../openapi/scan/support/param/TextTask.java | 33 - .../support/param/VoiceAsyncScanParam.java | 68 -- .../openapi/scan/support/param/VoiceTask.java | 31 - .../param/video/VideoAsyncScanParam.java | 76 -- .../param/video/VideoAsyncScanTask.java | 30 - .../support/result/ImgAsyncScanResult.java | 24 - .../scan/support/result/ScanTaskResult.java | 28 - .../support/result/SceneDetailResult.java | 31 - .../scan/support/result/SyncScanResult.java | 42 - .../result/VoiceAsyncScanDetailDTO.java | 47 -- .../support/result/VoiceAsyncScanResult.java | 89 --- .../result/VoiceAsyncScanResultDTO.java | 57 -- .../result/VoiceAsyncScanTaskDataDTO.java | 40 - .../result/VoiceAsyncScanTaskResult.java | 46 -- .../video/VideoAsyncScanTaskDataDTO.java | 41 - .../video/VideoAsyncScanTaskResultDTO.java | 45 -- .../support/result/video/VideoResultDTO.java | 48 -- .../result/video/VideoScanOriginDetail.java | 53 -- .../video/VideoScanOriginalResultDTO.java | 51 -- .../src/main/resources/bootstrap.yml | 91 --- .../src/main/resources/logback-spring.xml | 169 ---- .../src/main/resources/readme | 7 - .../src/test/java/BaseSample.java | 50 -- .../java/ImageAsyncScanRequestSample.java | 95 --- .../java/ImageAsyncScanResultsSample.java | 83 -- .../test/java/ImageSyncScanRequestSample.java | 101 --- .../java/VoiceAsyncScanRequestSample.java | 90 --- .../VoiceAsyncScanResultsRequestSample.java | 113 --- epmet-openapi/pom.xml | 19 - 80 files changed, 5007 deletions(-) delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-client/pom.xml delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/Dockerfile delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-dev.yml delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-prod.yml delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-test.yml delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/pom.xml delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/AdvApplication.java delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/aspect/RequestLogAspect.java delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/config/ModuleConfigImpl.java delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/controller/AdvVideoController.java delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/dao/AdvVedioDao.java delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/entity/AdvVedioEntity.java delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/AdvVedioService.java delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/impl/AdvVedioServiceImpl.java delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/bootstrap.yml delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/db/migration/V0.0.1__createAdvVedio.sql delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/logback-spring.xml delete mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/mapper/AdvVedioDao.xml delete mode 100644 epmet-openapi/epmet-openapi-adv/pom.xml delete mode 100644 epmet-openapi/epmet-openapi-scan/Dockerfile delete mode 100644 epmet-openapi/epmet-openapi-scan/deploy/docker-compose-dev.yml delete mode 100644 epmet-openapi/epmet-openapi-scan/deploy/docker-compose-prod.yml delete mode 100644 epmet-openapi/epmet-openapi-scan/deploy/docker-compose-test.yml delete mode 100644 epmet-openapi/epmet-openapi-scan/pom.xml delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/ScanApplication.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/aspect/RequestLogAspect.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/CommonErrorCodeEnum.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/ImgSceneEnum.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/LabelEnum.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/RegionIdEnum.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SuggestionEnum.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/TextSceneEnum.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VideoSceneEnum.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VoiceSceneEnum.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExecuteHttpException.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/redis/RedisKeys.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/HttpClientManager.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/IAcsClientUtil.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/MapUtil.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/ModuleConfigImpl.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/WebAppConfig.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/BackDoorController.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiAuthInterceptor.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanService.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextTask.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceAsyncScanParam.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceTask.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanParam.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanTask.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAsyncScanResult.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ScanTaskResult.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SceneDetailResult.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SyncScanResult.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanDetailDTO.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResult.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResultDTO.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskDataDTO.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskResult.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskDataDTO.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskResultDTO.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoResultDTO.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginDetail.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginalResultDTO.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/resources/bootstrap.yml delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/resources/logback-spring.xml delete mode 100644 epmet-openapi/epmet-openapi-scan/src/main/resources/readme delete mode 100644 epmet-openapi/epmet-openapi-scan/src/test/java/BaseSample.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanRequestSample.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanResultsSample.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/test/java/ImageSyncScanRequestSample.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanRequestSample.java delete mode 100644 epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanResultsRequestSample.java delete mode 100644 epmet-openapi/pom.xml diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-client/pom.xml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-client/pom.xml deleted file mode 100644 index 5c57808384..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-client/pom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - epmet-openapi-adv - com.epmet - 2.0.0 - ../pom.xml - - 4.0.0 - - epmet-openapi-adv-client - - - \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/Dockerfile b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/Dockerfile deleted file mode 100644 index d15b865820..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM java:8 - -RUN export LANG="zh_CN.UTF-8" -RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime -RUN echo 'Asia/Shanghai' > /etc/timezone - -COPY ./target/*.jar ./epmet-openapi-adv.jar - -EXPOSE 8115 - -ENTRYPOINT ["sh", "-c", "exec $RUN_INSTRUCT"] \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-dev.yml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-dev.yml deleted file mode 100644 index 55c505363d..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-dev.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: "3.7" -services: - epmet-openapi-adv-server: - container_name: epmet-openapi-adv-server-dev - image: 192.168.1.130:10080/epmet-cloud-dev/epmet-openapi-adv-server:version_placeholder - ports: - - "8015:8015" - network_mode: host # 不会创建新的网络 - volumes: - - "/opt/epmet-cloud-logs/dev:/logs" - environment: - RUN_INSTRUCT: "java -Xms32m -Xmx200m -jar ./epmet-openapi-adv.jar" - restart: "unless-stopped" - deploy: - resources: - limits: - cpus: '0.1' - memory: 300M \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-prod.yml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-prod.yml deleted file mode 100644 index b5a13e04e3..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-prod.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: "3.7" -services: - epmet-openapi-adv-server: - container_name: epmet-openapi-adv-server-prod - image: registry-vpc.cn-qingdao.aliyuncs.com/epmet-cloud-master/epmet-openapi-adv-server:0.3.3 - ports: - - "8015:8015" - network_mode: host # 不会创建新的网络 - volumes: - - "/opt/epmet-cloud-logs/prod:/logs" - environment: - RUN_INSTRUCT: "java -Xms256m -Xmx512m -jar ./epmet-openapi-adv.jar" - restart: "unless-stopped" - deploy: - resources: - limits: - cpus: '0.1' - memory: 600M \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-test.yml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-test.yml deleted file mode 100644 index 45d536cb2f..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-test.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: "3.7" -services: - epmet-openapi-adv-server: - container_name: epmet-openapi-adv-server-test - image: registry-vpc.cn-qingdao.aliyuncs.com/epmet-cloud-release/epmet-openapi-adv-server:version_placeholder - ports: - - "8015:8015" - network_mode: host # 不会创建新的网络 - volumes: - - "/opt/epmet-cloud-logs/test:/logs" - environment: - RUN_INSTRUCT: "java -Xms32m -Xmx200m -jar ./epmet-openapi-adv.jar" - restart: "unless-stopped" - deploy: - resources: - limits: - cpus: '0.1' - memory: 300M \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/pom.xml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/pom.xml deleted file mode 100644 index 8dd1602e70..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/pom.xml +++ /dev/null @@ -1,227 +0,0 @@ - - - - 0.3.3 - - epmet-openapi-adv - com.epmet - 2.0.0 - ../pom.xml - - 4.0.0 - - epmet-openapi-adv-server - - - - com.epmet - epmet-commons-mybatis - 2.0.0 - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework - spring-context-support - - - org.springframework.boot - spring-boot-starter-actuator - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-config - - - - io.github.openfeign - feign-httpclient - 10.3.0 - - - - - ${project.artifactId} - - - org.springframework.boot - spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - true - - - - - ${project.basedir}/src/main/java - - - true - ${basedir}/src/main/resources - - - - - - - dev - - 8115 - dev - - - - - - epmet_adv_user - EpmEt-db-UsEr - - 0 - 192.168.1.130 - 6379 - 123456 - - true - 192.168.1.130:8848 - 6ceab336-d004-4acf-89c6-e121d06f4988 - - - false - - - false - - - https://oapi.dingtalk.com/robot/send?access_token=90782b119f82a5b6bb8e0f819b6a77bbc2102b53aa2d7d2e24fa10b66d580b1c - - SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 - - - - - local - - true - - - 8115 - local - - - - - - epmet_adv_user - EpmEt-db-UsEr - - 0 - 118.190.150.119 - 47379 - 123456 - - false - 192.168.1.130:8848 - 6ceab336-d004-4acf-89c6-e121d06f4988 - - - false - - - false - - - https://oapi.dingtalk.com/robot/send?access_token=90782b119f82a5b6bb8e0f819b6a77bbc2102b53aa2d7d2e24fa10b66d580b1c - - SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 - - https://epmet-dev.elinkservice.cn/api/epmetscan/api - - - - test - - - 8115 - test - - - - - - epmet - elink@833066 - - 0 - r-m5eoz5b6tkx09y6bpz.redis.rds.aliyuncs.com - 6379 - EpmEtrEdIs!q@w - - true - 192.168.10.150:8848 - 67e3c350-533e-4d7c-9f8f-faf1b4aa82ae - - - false - - - true - - - https://oapi.dingtalk.com/robot/send?access_token=90782b119f82a5b6bb8e0f819b6a77bbc2102b53aa2d7d2e24fa10b66d580b1c - - SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 - - - - - prod - - 8115 - prod - - - - - - epmet_adv_user - EpmEt-db-UsEr - - 0 - r-m5ez3n1j0qc3ykq2ut.redis.rds.aliyuncs.com - 6379 - EpmEtclOUdrEdIs!Q2w - - true - 192.168.11.180:8848 - bd205d23-e696-47be-b995-916313f86e99 - - - false - - - true - - - - https://oapi.dingtalk.com/robot/send?access_token=a5f66c3374b1642fe2142dbf56d5997e280172d4e8f2b546c9423a68c82ece6c - - SEC95f4f40b533ad379ea6a6d1af6dd37029383cfe1b7cd96dfac2678be2c1c3ed1 - - - - - - \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/AdvApplication.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/AdvApplication.java deleted file mode 100644 index 61c5d3b4b8..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/AdvApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.epmet; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.openfeign.EnableFeignClients; - -@SpringBootApplication -@EnableDiscoveryClient -@EnableFeignClients -public class AdvApplication { - public static void main(String[] args) { - SpringApplication.run(AdvApplication.class, args); - } -} diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/aspect/RequestLogAspect.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/aspect/RequestLogAspect.java deleted file mode 100644 index e06fdc2c95..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/aspect/RequestLogAspect.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.epmet.adv.aspect; - -import com.epmet.commons.tools.aspect.BaseRequestLogAspect; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; -import org.springframework.web.context.request.RequestAttributes; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -import javax.servlet.http.HttpServletRequest; - -/** - * 日志/异常处理切面实现,调用父类方法完成日志记录和异常处理。 - */ -@Aspect -@Component -@Order(0) -public class RequestLogAspect extends BaseRequestLogAspect { - - @Override - @Around(value = "execution(* com.epmet.adv.controller.*Controller*.*(..)) ") - public Object proceed(ProceedingJoinPoint point) throws Throwable { - return super.proceed(point, getRequest()); - } - - /** - * 获取Request对象 - * - * @return - */ - private HttpServletRequest getRequest() { - RequestAttributes ra = RequestContextHolder.getRequestAttributes(); - ServletRequestAttributes sra = (ServletRequestAttributes) ra; - return sra.getRequest(); - } - -} diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/config/ModuleConfigImpl.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/config/ModuleConfigImpl.java deleted file mode 100644 index 8d88549b66..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/config/ModuleConfigImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2018 人人开源 All rights reserved. - * - * https://www.renren.io - * - * 版权所有,侵权必究! - */ - -package com.epmet.adv.config; - -import com.epmet.commons.tools.config.ModuleConfig; -import org.springframework.stereotype.Service; - -/** - * 模块配置信息 - * - * @author Mark sunlightcs@gmail.com - * @since 1.0.0 - */ -@Service -public class ModuleConfigImpl implements ModuleConfig { - @Override - public String getName() { - return "adv"; - } -} diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/controller/AdvVideoController.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/controller/AdvVideoController.java deleted file mode 100644 index 5c032ad562..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/controller/AdvVideoController.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.epmet.adv.controller; - -import com.epmet.adv.entity.AdvVedioEntity; -import com.epmet.adv.service.AdvVedioService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.io.IOException; - -@Controller -@RequestMapping("video") -public class AdvVideoController { - - @Autowired - private AdvVedioService advVedioService; - - @GetMapping("company-adv") - public String toVedio() throws IOException { - AdvVedioEntity enableAdvVedioEntity = advVedioService.getEnableAdvVedioEntity(); - String redirectUrl = enableAdvVedioEntity != null ? enableAdvVedioEntity.getPath() : "404"; - return String.format("redirect:%s", redirectUrl); - //response.sendRedirect("www.baidu.com"); - } - -} diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/dao/AdvVedioDao.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/dao/AdvVedioDao.java deleted file mode 100644 index c14da09d52..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/dao/AdvVedioDao.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2018 人人开源 https://www.renren.io - *

- * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - *

- * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - *

- * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.epmet.adv.dao; - -import com.epmet.adv.entity.AdvVedioEntity; -import com.epmet.commons.mybatis.dao.BaseDao; -import org.apache.ibatis.annotations.Mapper; - -/** - * 宣传视频 - * - * @author generator generator@elink-cn.com - * @since v1.0.0 2020-12-30 - */ -@Mapper -public interface AdvVedioDao extends BaseDao { - AdvVedioEntity getEnableAdvVedioEntity(); -} \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/entity/AdvVedioEntity.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/entity/AdvVedioEntity.java deleted file mode 100644 index a25c6ea77e..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/entity/AdvVedioEntity.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright 2018 人人开源 https://www.renren.io - *

- * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - *

- * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - *

- * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.epmet.adv.entity; - -import com.baomidou.mybatisplus.annotation.TableName; - -import com.epmet.commons.mybatis.entity.BaseEpmetEntity; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.Date; - -/** - * 宣传视频 - * - * @author generator generator@elink-cn.com - * @since v1.0.0 2020-12-30 - */ -@Data -@EqualsAndHashCode(callSuper=false) -@TableName("adv_vedio") -public class AdvVedioEntity extends BaseEpmetEntity { - - private static final long serialVersionUID = 1L; - - /** - * 存储路径 - */ - private String path; - - /** - * 存储类型。aliyun_oss,local - */ - private String storeType; - - /** - * 是否启用 - */ - private Integer enable; - -} diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/AdvVedioService.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/AdvVedioService.java deleted file mode 100644 index 38091ee496..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/AdvVedioService.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.epmet.adv.service; - -import com.epmet.adv.entity.AdvVedioEntity; - -public interface AdvVedioService { - AdvVedioEntity getEnableAdvVedioEntity(); -} diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/impl/AdvVedioServiceImpl.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/impl/AdvVedioServiceImpl.java deleted file mode 100644 index cecc710c39..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/impl/AdvVedioServiceImpl.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.epmet.adv.service.impl; - -import com.epmet.adv.dao.AdvVedioDao; -import com.epmet.adv.entity.AdvVedioEntity; -import com.epmet.adv.service.AdvVedioService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class AdvVedioServiceImpl implements AdvVedioService { - @Autowired - private AdvVedioDao advVedioDao; - - public AdvVedioEntity getEnableAdvVedioEntity() { - return advVedioDao.getEnableAdvVedioEntity(); - } - -} diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/bootstrap.yml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/bootstrap.yml deleted file mode 100644 index 0bd40dcca7..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/bootstrap.yml +++ /dev/null @@ -1,140 +0,0 @@ -server: - port: @server.port@ - version: @version@ - servlet: - context-path: /adv - -spring: - main: - allow-bean-definition-overriding: true - application: - name: epmet-openapi-adv-server - #环境 dev|test|prod - profiles: - active: @spring.profiles.active@ - messages: - encoding: UTF-8 - basename: i18n/messages_common - jackson: - time-zone: GMT+8 - date-format: yyyy-MM-dd HH:mm:ss - redis: - database: @spring.redis.index@ - host: @spring.redis.host@ - port: @spring.redis.port@ - password: @spring.redis.password@ - timeout: 30s - datasource: - druid: - #MySQL - driver-class-name: com.mysql.cj.jdbc.Driver - url: @spring.datasource.druid.url@ - username: @spring.datasource.druid.username@ - password: @spring.datasource.druid.password@ - initial-size: 10 - max-active: 100 - min-idle: 10 - max-wait: 60000 - pool-prepared-statements: true - max-pool-prepared-statement-per-connection-size: 20 - time-between-eviction-runs-millis: 60000 - min-evictable-idle-time-millis: 300000 - #Oracle需要打开注释 - #validation-query: SELECT 1 FROM DUAL - test-while-idle: true - test-on-borrow: false - test-on-return: false - filter: - stat: - log-slow-sql: true - slow-sql-millis: 1000 - merge-sql: false - wall: - config: - multi-statement-allow: true - # 数据迁移工具flyway - flyway: - enabled: @spring.flyway.enabled@ - locations: classpath:db/migration - url: @spring.datasource.druid.url@ - user: @spring.datasource.druid.username@ - password: @spring.datasource.druid.password@ - baseline-on-migrate: true - baseline-version: 0 - cloud: - nacos: - discovery: - server-addr: @nacos.server-addr@ - #nacos的命名空间ID,默认是public - namespace: @nacos.discovery.namespace@ - #不把自己注册到注册中心的地址 - register-enabled: @nacos.register-enabled@ - ip: @nacos.ip@ - config: - enabled: @nacos.config-enabled@ - server-addr: @nacos.server-addr@ - namespace: @nacos.config.namespace@ - group: @nacos.config.group@ - file-extension: yaml -management: - endpoints: - web: - exposure: - include: "*" - endpoint: - health: - show-details: ALWAYS - -mybatis-plus: - mapper-locations: classpath:/mapper/**/*.xml - #实体扫描,多个package用逗号或者分号分隔 - typeAliasesPackage: com.epmet.entity - global-config: - #数据库相关配置 - db-config: - #主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID"; - id-type: ID_WORKER - #字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断" - field-strategy: NOT_NULL - #驼峰下划线转换 - column-underline: true - banner: false - #原生配置 - configuration: - map-underscore-to-camel-case: true - cache-enabled: false - call-setters-on-nulls: true - jdbc-type-for-null: 'null' - -feign: - hystrix: - enabled: true - client: - config: - default: - loggerLevel: BASIC - okhttp: - enabled: true - - -hystrix: - command: - default: - execution: - isolation: - thread: - timeoutInMilliseconds: 60000 #缺省为1000 - -ribbon: - ReadTimeout: 300000 - ConnectTimeout: 300000 - -#pageHelper分页插件 -pagehelper: - helper-dialect: mysql - reasonable: false #分页合理化配置,例如输入页码为-1,则自动转化为最小页码1 - -dingTalk: - robot: - webHook: @dingTalk.robot.webHook@ - secret: @dingTalk.robot.secret@ diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/db/migration/V0.0.1__createAdvVedio.sql b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/db/migration/V0.0.1__createAdvVedio.sql deleted file mode 100644 index 007c12b55f..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/db/migration/V0.0.1__createAdvVedio.sql +++ /dev/null @@ -1,18 +0,0 @@ --- create database epmet_adv default character set utf8mb4; - --- CREATE USER epmet_adv_user@'%' IDENTIFIED BY 'EpmEt-db-UsEr'; --- GRANT ALL ON `epmet_adv%`.* TO 'epmet_adv_user'@'%'; --- flush privileges; - -CREATE TABLE `adv_vedio` ( - `ID` varchar(64) NOT NULL COMMENT 'id' primary key , - `PATH` varchar(255) NOT NULL COMMENT '存储路径', - `STORE_TYPE` varchar(30) NOT NULL COMMENT '存储类型。aliyun_oss,local', - `ENABLE` tinyint(1) NOT NULL COMMENT '是否启用', - `REVISION` int(11) DEFAULT NULL COMMENT '乐观锁', - `DEL_FLAG` int(11) unsigned DEFAULT NULL COMMENT '删除标识 0:未删除 1:删除', - `CREATED_BY` varchar(32) DEFAULT NULL COMMENT '创建者', - `CREATED_TIME` datetime DEFAULT NULL COMMENT '创建时间', - `UPDATED_BY` varchar(32) DEFAULT NULL COMMENT '更新者', - `UPDATED_TIME` datetime DEFAULT NULL COMMENT '更新时间' -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='宣传视频' \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/logback-spring.xml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/logback-spring.xml deleted file mode 100644 index 06a21d317c..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,169 +0,0 @@ - - - - - - - - - - - - ${appname} - - - - - - - - - debug - - - ${CONSOLE_LOG_PATTERN} - - UTF-8 - - - - - - - - ${log.path}/debug.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - - ${log.path}/debug-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 15 - - - - debug - ACCEPT - DENY - - - - - - - ${log.path}/info.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - - ${log.path}/info-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 15 - - - - info - ACCEPT - DENY - - - - - - - ${log.path}/warn.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - ${log.path}/warn-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 15 - - - - warn - ACCEPT - DENY - - - - - - - ${log.path}/error.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - ${log.path}/error-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 15 - - - - ERROR - ACCEPT - DENY - ${webHook} - ${secret} - ${appname} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/mapper/AdvVedioDao.xml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/mapper/AdvVedioDao.xml deleted file mode 100644 index 92a4993b9f..0000000000 --- a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/mapper/AdvVedioDao.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/pom.xml b/epmet-openapi/epmet-openapi-adv/pom.xml deleted file mode 100644 index 13490687d1..0000000000 --- a/epmet-openapi/epmet-openapi-adv/pom.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - epmet-openapi - com.epmet - 2.0.0 - - pom - 4.0.0 - - epmet-openapi-adv - - - epmet-openapi-adv-client - epmet-openapi-adv-server - - - - \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/Dockerfile b/epmet-openapi/epmet-openapi-scan/Dockerfile deleted file mode 100644 index 868fc70ac1..0000000000 --- a/epmet-openapi/epmet-openapi-scan/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM java:8 - -RUN export LANG="zh_CN.UTF-8" -RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime -RUN echo 'Asia/Shanghai' > /etc/timezone - -COPY ./target/*.jar ./epmet-openapi-scan.jar - -EXPOSE 8107 - -ENTRYPOINT ["sh", "-c", "exec $RUN_INSTRUCT"] \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-dev.yml b/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-dev.yml deleted file mode 100644 index 4e86ab5e89..0000000000 --- a/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-dev.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: "3.7" -services: - epmet-openapi-scan: - container_name: epmet-openapi-scan-dev - image: 192.168.1.130:10080/epmet-cloud-dev/epmet-openapi-scan:version_placeholder - ports: - - "8107:8107" - network_mode: host # 不会创建新的网络 - volumes: - - "/opt/epmet-cloud-logs/dev:/logs" - environment: - RUN_INSTRUCT: "java -Xms32m -Xmx200m -jar ./epmet-openapi-scan.jar" - restart: "unless-stopped" - deploy: - resources: - limits: - cpus: '0.1' - memory: 300M \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-prod.yml b/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-prod.yml deleted file mode 100644 index 69873777e7..0000000000 --- a/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-prod.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: "3.7" -services: - epmet-openapi-scan: - container_name: epmet-openapi-scan-prod - image: registry-vpc.cn-qingdao.aliyuncs.com/epmet-cloud-master/epmet-openapi-scan:0.3.24 - ports: - - "8107:8107" - network_mode: host # 不会创建新的网络 - volumes: - - "/opt/epmet-cloud-logs/prod:/logs" - environment: - RUN_INSTRUCT: "java -Xms256m -Xmx512m -jar ./epmet-openapi-scan.jar" - restart: "unless-stopped" - deploy: - resources: - limits: - cpus: '0.1' - memory: 600M \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-test.yml b/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-test.yml deleted file mode 100644 index 49ce30a8c1..0000000000 --- a/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-test.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: "3.7" -services: - epmet-openapi-scan: - container_name: epmet-openapi-scan-test - image: registry-vpc.cn-qingdao.aliyuncs.com/epmet-cloud-release/epmet-openapi-scan:version_placeholder - ports: - - "8107:8107" - network_mode: host # 不会创建新的网络 - volumes: - - "/opt/epmet-cloud-logs/test:/logs" - environment: - RUN_INSTRUCT: "java -Xms32m -Xmx200m -jar ./epmet-openapi-scan.jar" - restart: "unless-stopped" - deploy: - resources: - limits: - cpus: '0.1' - memory: 300M \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/pom.xml b/epmet-openapi/epmet-openapi-scan/pom.xml deleted file mode 100644 index b80b8a843e..0000000000 --- a/epmet-openapi/epmet-openapi-scan/pom.xml +++ /dev/null @@ -1,208 +0,0 @@ - - - - 4.0.0 - 0.3.24 - epmet-openapi-scan - jar - - - epmet-openapi - com.epmet - 2.0.0 - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework - spring-context-support - - - org.springframework.boot - spring-boot-starter-actuator - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-config - - - com.epmet - epmet-commons-tools - 2.0.0 - - - - com.aliyun - aliyun-java-sdk-core - 4.1.1 - - - com.aliyun - aliyun-java-sdk-green - 3.5.1 - - - - org.apache.httpcomponents - httpclient - 4.5.2 - - - - - ${project.artifactId} - - - org.springframework.boot - spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - true - - - - - ${project.basedir}/src/main/java - - - true - ${basedir}/src/main/resources - - - - - - - dev - - 8107 - dev - - - - 0 - 192.168.1.130 - 6379 - 123456 - - true - 192.168.1.130:8848 - 6ceab336-d004-4acf-89c6-e121d06f4988 - - - false - - - - https://oapi.dingtalk.com/robot/send?access_token=90782b119f82a5b6bb8e0f819b6a77bbc2102b53aa2d7d2e24fa10b66d580b1c - - SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 - - - - - local - - true - - - 8107 - dev - - - - 0 - 192.168.1.130 - 6379 - 123456 - - false - 192.168.1.130:8848 - 6ceab336-d004-4acf-89c6-e121d06f4988 - - - false - - - - https://oapi.dingtalk.com/robot/send?access_token=90782b119f82a5b6bb8e0f819b6a77bbc2102b53aa2d7d2e24fa10b66d580b1c - - SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 - - - - - test - - 8107 - test - - - 0 - r-m5eoz5b6tkx09y6bpz.redis.rds.aliyuncs.com - 6379 - EpmEtrEdIs!q@w - - true - 192.168.10.150:8848 - 67e3c350-533e-4d7c-9f8f-faf1b4aa82ae - - - false - - - - https://oapi.dingtalk.com/robot/send?access_token=90782b119f82a5b6bb8e0f819b6a77bbc2102b53aa2d7d2e24fa10b66d580b1c - - SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 - - - - - - prod - - - 8107 - prod - - - 0 - r-m5ez3n1j0qc3ykq2ut.redis.rds.aliyuncs.com - 6379 - EpmEtclOUdrEdIs!Q2w - - true - 192.168.11.180:8848 - bd205d23-e696-47be-b995-916313f86e99 - - - false - - - - - - https://oapi.dingtalk.com/robot/send?access_token=a5f66c3374b1642fe2142dbf56d5997e280172d4e8f2b546c9423a68c82ece6c - - SEC95f4f40b533ad379ea6a6d1af6dd37029383cfe1b7cd96dfac2678be2c1c3ed1 - - - - - - \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/ScanApplication.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/ScanApplication.java deleted file mode 100644 index 38f55211d2..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/ScanApplication.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) 2018 人人开源 All rights reserved. - * - * https://www.renren.io - * - * 版权所有,侵权必究! - */ - -package com.epmet.openapi.scan; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ComponentScan; - -/** - * 管理后台 - * - * @author Mark sunlightcs@gmail.com - * @since 1.0.0 - */ - -@SpringBootApplication -@ComponentScan(basePackages = "com.epmet") -public class ScanApplication { - - public static void main(String[] args) { - SpringApplication.run(ScanApplication.class, args); - } - -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/aspect/RequestLogAspect.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/aspect/RequestLogAspect.java deleted file mode 100644 index ae6960a52d..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/aspect/RequestLogAspect.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.epmet.openapi.scan.aspect; - -import com.epmet.commons.tools.aspect.BaseRequestLogAspect; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; -import org.springframework.web.context.request.RequestAttributes; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -import javax.servlet.http.HttpServletRequest; - -/** - * 日志/异常处理切面实现,调用父类方法完成日志记录和异常处理。 - */ -@Aspect -@Component -@Order(0) -public class RequestLogAspect extends BaseRequestLogAspect { - - @Override - @Around(value = "execution(* com.epmet.openapi.scan.controller.*Controller*.*(..)) ") - public Object proceed(ProceedingJoinPoint point) throws Throwable { - return super.proceed(point, getRequest()); - } - - /** - * 获取Request对象 - * - * @return - */ - private HttpServletRequest getRequest() { - RequestAttributes ra = RequestContextHolder.getRequestAttributes(); - ServletRequestAttributes sra = (ServletRequestAttributes) ra; - return sra.getRequest(); - } - -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java deleted file mode 100644 index 387294c23b..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.epmet.openapi.scan.common.constant; - -/** - * 系统常量 - * - * @author jianjun liu - * @date 2020-06-05 10:42 - **/ -public class SysConstant { - - public static final String UTF8 = "utf-8"; - /** - * 文本审核最大任务数 - */ - public static final Integer MAX_TASK_SIZE = 100; - - /** - * 图片审核最大任务数 - */ - public static final Integer MAX_SCAN_IMG_TASK_SIZE = 10; - - public static final String CODE = "code"; - public static final String DATA = "data"; - - - /** - * 任务正在执行中,建议您等待一段时间(例如5s)后再查询结果。 - */ - public static final int PROCESSING=280; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/CommonErrorCodeEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/CommonErrorCodeEnum.java deleted file mode 100644 index 8ebed5781f..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/CommonErrorCodeEnum.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.epmet.openapi.scan.common.enu; - -import com.epmet.commons.tools.constant.StrConstant; - -/** - * 公共错误码 - * - * @author yinzuomei@elink-cn.com - * @date 2021/1/10 19:43 - */ -public enum CommonErrorCodeEnum { - OK(200, "请求成功。"), - PROCESSING(280, "任务正在执行中,建议您等待一段时间(例如5s)后再查询结果。"), - BAD_REQUEST(400, "请求有误,通常由于请求参数不正确导致,请仔细检查请求参数。"), - NOT_ALLOWED(401, "请求失败,通常是由于使用了不安全的图片、视频、语音链接地址。"), - FORBIDDEN(403, "请求访问失败,通常由于您的图片、视频、语音链接无法访问导致,请确认公网是否可访问,并且无防盗链策略。"), - NOT_FOUND(404, "待检测内容未找到,通常是由于您的图片、视频、语音内容无法下载导致,请确认内容可通过公网访问到。"), - DOWNLOAD_FAILED(480, "下载失败,请确认待检测内容的大小、分辨率(如果有)在API的限制范围内。"), - GENERAL_ERROR(500, "一般是服务端临时出错。建议重试,若持续返回该错误码,请通过工单联系我们。"), - DB_FAILED(580, "数据库操作失败。建议重试,若持续返回该错误码,请通过工单联系我们。"), - TIMEOUT(581, "超时。建议重试,若持续返回该错误码,请通过工单联系我们。"), - CACHE_FAILED(585, "缓存出错。建议重试,若持续返回该错误码,请通过工单联系我们。"), - ALGO_FAILED(586, "算法出错。请通过工单联系我们。"), - MQ_FAILED(587, "中间件出错。请通过工单联系我们。"), - EXCEED_QUOTA(588, "请求频率超出配额。默认配额:图片检测50张/秒,视频检测20路/秒,语音检测20路/秒,文本检测100条/秒。如果需要调整配额,请通过工单联系我们。"), - TOO_LARGE(589, "待检测内容过大,请确保检测的内容在API的限制范围内。建议重试,若持续返回该错误码,请通过工单联系我们。"), - BAD_FORMAT(590, "待检测内容格式错误,请确保检测的内容在API的限制范围内。"), - CONNECTION_POOL_FULL(591, "连接池满。请通过工单联系我们。"), - DOWNLOAD_TIMEOUT(592, "下载超时,下载时间限制为3s,请确保检测的内容大小在API的限制范围内。"), - EXPIRED(594, "任务过期,如taskId过期。"), - CATCH_FRAME_FAILED(595, "截帧失败,请通过工单联系我们。"), - PERMISSION_DENY(596, "账号未授权、账号欠费、账号未开通、账号被禁等原因,具体可以参考返回的msg。"); - - - private Integer code; - private String desc; - - CommonErrorCodeEnum(Integer code, String desc) { - this.code = code; - this.desc = desc; - } - - public Integer getCode() { - return code; - } - - public void setCode(Integer code) { - this.code = code; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } - - public static String getErrorMsg(Integer value) { - CommonErrorCodeEnum[] codeEnums = values(); - for (CommonErrorCodeEnum commonErrorCodeEnum : codeEnums) { - if (commonErrorCodeEnum.getCode().equals(value)) { - return commonErrorCodeEnum.getDesc(); - } - } - return StrConstant.EPMETY_STR; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/ImgSceneEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/ImgSceneEnum.java deleted file mode 100644 index cfb8d77ac2..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/ImgSceneEnum.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.epmet.openapi.scan.common.enu; - -import java.util.ArrayList; -import java.util.List; - -/** - * desc:图片检测场景 - * @author jianjun liu - * @date 2020-06-04 21:39 - **/ -public enum ImgSceneEnum { - PORN("porn", "图片智能鉴黄"), - TERRORISM("terrorism", "图片暴恐涉政识别"); - - private String code; - private String desc; - - ImgSceneEnum(String code, String desc) { - this.code = code; - this.desc = desc; - } - - public static List getImgSceneList() { - List result = new ArrayList<>(); - ImgSceneEnum[] values = ImgSceneEnum.values(); - for (ImgSceneEnum v : values) { - result.add(v.getCode()); - } - return result; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/LabelEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/LabelEnum.java deleted file mode 100644 index 7ad96f3171..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/LabelEnum.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.epmet.openapi.scan.common.enu; - -import java.util.ArrayList; -import java.util.List; - -/** - * 阿里检测结果的分类字典 - * - * @author yinzuomei@elink-cn.com - * @date 2020/12/18 14:04 - */ -public enum LabelEnum { - NORMAL("normal", "正常文本"), - SPAM("spam", "含垃圾信息"), - AD("ad", "广告"), - POLITICS("politics","涉政"), - TERRORISM("terrorism","暴恐"), - ABUSE("abuse","辱骂"), - PORN("porn","色情"), - FLOOD("flood","灌水"), - CONTRABAND("contraband","违禁"), - MEANINGLESS("meaningless","无意义"), - CUSTOMIZED("customized","自定义"); - - private String code; - private String desc; - - LabelEnum(String code, String desc) { - this.code = code; - this.desc = desc; - } - - public static List getLabelEnumList() { - List result = new ArrayList<>(); - LabelEnum[] values = LabelEnum.values(); - for (LabelEnum v : values) { - result.add(v.getCode()); - } - return result; - } - - public static String getDesc(String code) { - LabelEnum[] businessModeEnums = values(); - for (LabelEnum labelEnum : businessModeEnums) { - if (labelEnum.getCode().equals(code)) { - return labelEnum.getDesc(); - } - } - return ""; - } - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/RegionIdEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/RegionIdEnum.java deleted file mode 100644 index e1dbd5897b..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/RegionIdEnum.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.epmet.openapi.scan.common.enu; - -/** - * @author jianjun liu - * @email liujianjun@yunzongnet.com - * @date 2020-06-04 21:39 - **/ -public enum RegionIdEnum { - SHANG_HAI("cn-shanghai","green.cn-shanghai.aliyuncs.com"), - BEI_JING("cn-beijing","green.cn-beijing.aliyuncs.com"), - AP_SOUTHEAST_1("ap-southeast-1","green.ap-southeast-1.aliyuncs.com"), - US_WEST_1("us-west-1","green.us-west-1.aliyuncs.com"); - - private String regionId; - private String domain; - RegionIdEnum(String regionId, String domain){ - this.regionId = regionId; - this.domain = domain; - } - - public static String getDoMain(String regionId){ - if (regionId == null) { - return SHANG_HAI.getDomain(); - } - RegionIdEnum[] values = RegionIdEnum.values(); - for (RegionIdEnum v : values) { - if (regionId.equals(v.getDomain())) { - return v.getDomain(); - } - } - return SHANG_HAI.getDomain(); - } - - public String getRegionId() { - return regionId; - } - - public void setRegionId(String regionId) { - this.regionId = regionId; - } - - public String getDomain() { - return domain; - } - - public void setDomain(String domain) { - this.domain = domain; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SuggestionEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SuggestionEnum.java deleted file mode 100644 index 3881508341..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SuggestionEnum.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.epmet.openapi.scan.common.enu; - -import java.util.ArrayList; -import java.util.List; - -/** - * desc:检测建议 - * @author jianjun liu - * @date 2020-06-04 21:39 - **/ -public enum SuggestionEnum { - PASS("pass", "正常"), - REVIEW("review", "需要人工审核"), - BLOCK("block", "内容违规"); - - private String code; - private String desc; - - SuggestionEnum(String code, String desc) { - this.code = code; - this.desc = desc; - } - - public static List getImgSceneList() { - List result = new ArrayList<>(); - SuggestionEnum[] values = SuggestionEnum.values(); - for (SuggestionEnum v : values) { - result.add(v.getCode()); - } - return result; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java deleted file mode 100644 index f906186333..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.epmet.openapi.scan.common.enu; - -/** - * @author jianjun liu - * @date 2020-06-04 21:39 - **/ -public enum SysResponseEnum { - /** - * - * 业务代码枚举类 - * - * 编码样式:【CCCBBOOXX】 - * 编码示例说明: - * CCC 中心编码&业务系统 (110-内容扫描服务中心服务) - * BB 业务类型(00-默认 ) - * OO 操作类型(00-默认) - * XX 具体编码(00-成功,01-失败,02-参数错误,10-异常 99-系统错误) - * - */ - /*通用枚举 */ - EXCEPTION(10001,"系统异常"), - THIRD_PLATFORM_SERVER_ERROR(10002,"第三方检测服务异常,请稍候重试"), - THIRD_PLATFORM_RESP_STATUS_ERROR(10003,"第三方检测服务响应异常,请稍候重试"), - THIRD_PLATFORM_RESP_CODE_ERROR(10004,"第三方检测服务检测异常,请稍候重试"), - - - /*审核内容 业务 01*/ - SCAN_TASK_LIST_PARAM_ERROR(110010001,"任务列表长度超过限制"), - SCAN_PARAM_ERROR(110010002,"参数格式不正确"), - ; - - private Integer code; - private String msg; - SysResponseEnum(Integer code, String msg){ - this.code = code; - this.msg = msg; - } - - public Integer getCode() { - return code; - } - - public String getMsg() { - return msg; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/TextSceneEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/TextSceneEnum.java deleted file mode 100644 index 263d6e25ed..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/TextSceneEnum.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.epmet.openapi.scan.common.enu; - -import java.util.ArrayList; -import java.util.List; - -/** - * desc:文本检测场景 - * @author jianjun liu - * @date 2020-06-04 21:39 - **/ -public enum TextSceneEnum { - ANTISPAM("antispam", "文本垃圾内容检测"); - - private String code; - private String desc; - - TextSceneEnum(String code, String desc) { - this.code = code; - this.desc = desc; - } - - public static List getTextSceneList() { - List result = new ArrayList<>(); - TextSceneEnum[] values = TextSceneEnum.values(); - for (TextSceneEnum v : values) { - result.add(v.getCode()); - } - return result; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VideoSceneEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VideoSceneEnum.java deleted file mode 100644 index 864d137dd2..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VideoSceneEnum.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.epmet.openapi.scan.common.enu; - -import java.util.ArrayList; -import java.util.List; - -/** - * desc:视频检测场景 - * @author yinzuomei@elink-cn.com - * @date 2020/12/29 13:47 - **/ -public enum VideoSceneEnum { - PORN("porn", "视频智能鉴黄"), - TERRORISM("terrorism", "视频暴恐涉政"), - LIVE("live","视频不良场景"), - LOGO("logo","视频logo"), - AD("ad","视频图文违规"); - - private String code; - private String desc; - - VideoSceneEnum(String code, String desc) { - this.code = code; - this.desc = desc; - } - - public static List getVideoSceneList() { - List result = new ArrayList<>(); - VideoSceneEnum[] values = VideoSceneEnum.values(); - for (VideoSceneEnum v : values) { - result.add(v.getCode()); - } - return result; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VoiceSceneEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VoiceSceneEnum.java deleted file mode 100644 index 777b92f0d7..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VoiceSceneEnum.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.epmet.openapi.scan.common.enu; - -import java.util.ArrayList; -import java.util.List; - -/** - * 语音异步检测场景 - * - * @author yinzuomei@elink-cn.com - * @date 2020/12/9 10:12 - */ -public enum VoiceSceneEnum { - ANTISPAM("antispam", "检测场景,取值:antispam"); - - private String code; - private String desc; - - VoiceSceneEnum(String code, String desc) { - this.code = code; - this.desc = desc; - } - - public static List getVoiceSceneList() { - List result = new ArrayList<>(); - VoiceSceneEnum[] values = VoiceSceneEnum.values(); - for (VoiceSceneEnum v : values) { - result.add(v.getCode()); - } - return result; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExecuteHttpException.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExecuteHttpException.java deleted file mode 100644 index a5694da79c..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExecuteHttpException.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.epmet.openapi.scan.common.exception; - -import com.epmet.openapi.scan.common.enu.SysResponseEnum; - -/** - * @author jianjun liu - * @date 2020-06-05 10:31 - **/ -public class ExecuteHttpException extends RuntimeException { - private int code; - private String msg; - - public ExecuteHttpException(String msg) { - this(SysResponseEnum.EXCEPTION.getCode(), msg); - } - - public ExecuteHttpException(int code, String msg) { - this.code = code; - this.msg = msg; - } - - public int getCode() { - return code; - } - - public String getMsg() { - return msg; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/redis/RedisKeys.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/redis/RedisKeys.java deleted file mode 100644 index 2939bd62eb..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/redis/RedisKeys.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (c) 2018 人人开源 All rights reserved. - *

- * https://www.renren.io - *

- * 版权所有,侵权必究! - */ - -package com.epmet.openapi.scan.common.redis; - -/** - * @author Mark sunlightcs@gmail.com - * @since 1.0.0 - */ -public class RedisKeys { - - /** - * 党群e事通redis前缀 - */ - private static String rootPrefix = "epmet:"; - - /** - * desc:白名单Key - * @return - */ - public static String getWhiteList () { - return rootPrefix.concat("openapi:scan:whitelist"); - } - - /** - * desc: 语音检测任务,异步回调,需要根据taskId获取存储seed的Key - * @param taskId 提交检测任务API接口返回的taskId eg:1001 - * @return epmet:openapi:scan:voice:seed:1001 - */ - public static String getVoiceScanSeedKey(String taskId){ - return rootPrefix.concat("openapi:scan:voice:seed:").concat(taskId); - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/HttpClientManager.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/HttpClientManager.java deleted file mode 100644 index 7ca0302331..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/HttpClientManager.java +++ /dev/null @@ -1,171 +0,0 @@ -package com.epmet.openapi.scan.common.util; - -import com.alibaba.fastjson.JSON; -import com.epmet.commons.tools.utils.Result; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; -import org.apache.http.HttpStatus; -import org.apache.http.NameValuePair; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpRequestBase; -import org.apache.http.client.utils.URIBuilder; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.message.BasicNameValuePair; -import org.apache.http.util.EntityUtils; -import org.springframework.util.CollectionUtils; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * desc: http 工具类 - * date: 2020/6/4 22:27 - * - * @author: jianjun liu - */ -@Slf4j -public class HttpClientManager { - private static int connectionTimeout = 3000;// 连接超时时间,毫秒 - private static int soTimeout = 10000;// 读取数据超时时间,毫秒 - /** - * HttpClient对象 - */ - private static CloseableHttpClient httpclient = HttpClients.custom().disableAutomaticRetries().build(); - - /*** 超时设置 ****/ - private static RequestConfig requestConfig = RequestConfig.custom() - .setSocketTimeout(soTimeout) - .setConnectTimeout(connectionTimeout) - .build();//设置请求和传输超时时间 - - public static HttpClientManager getInstance() { - return SingleClass.instance; - } - - private static class SingleClass { - private final static HttpClientManager instance = new HttpClientManager(); - } - - /** - * desc: 发送json post 请求 - * param: url,jsonStrParam - * return: Result - * date: 2019/2/21 9:12 - * - * @author: jianjun liu - */ - public Result sendPost(String url, Map paramsMap) { - - try { - HttpPost httppost = new HttpPost(url); - httppost.setConfig(requestConfig); - httppost.addHeader("Content-Type", "application/x-www-form-urlencoded charset=utf-8"); - - List list = new ArrayList(); - for (String key : paramsMap.keySet()) { - list.add(new BasicNameValuePair(key, String.valueOf(paramsMap.get(key)))); - } - UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(list, "utf-8"); - httppost.setEntity(urlEncodedFormEntity); - - return execute(httppost); - } catch (Exception e) { - e.printStackTrace(); - log.error("send exception", e); - return new Result().error(8000, e.getMessage()); - } - - } - - /** - * desc: 发送json post 请求 - * param: url,jsonStrParam - * return: Result - * date: 2019/2/21 9:12 - * - * @author: jianjun liu - */ - public Result sendPostByJSON(String url, String jsonStrParam) { - - try { - HttpPost httppost = new HttpPost(url); - httppost.setConfig(requestConfig); - httppost.addHeader("Content-Type", "application/json; charset=utf-8"); - if (StringUtils.isNotEmpty(jsonStrParam)) { - StringEntity se = new StringEntity(jsonStrParam, "utf-8"); - httppost.setEntity(se); - } - return execute(httppost); - } catch (Exception e) { - e.printStackTrace(); - log.error("send exception", e); - return new Result().error(8000, e.getMessage()); - } - - } - - /** - * desc: 发送get请求 - * param:url, params - * return: Result - * date: 2019/2/21 9:16 - * - * @author: jianjun liu - */ - public Result sendGet(String url, Map params) { - - try { - URIBuilder builder = new URIBuilder(url); - if (!CollectionUtils.isEmpty(params)) { - Set set = params.keySet(); - for (String key : set) { - builder.setParameter(key, params.get(key) == null ? "" : String.valueOf(params.get(key))); - } - } - HttpGet httpGet = new HttpGet(builder.build()); - httpGet.setConfig(requestConfig); - return execute(httpGet); - } catch (Exception e) { - log.error("sendGet exception", e); - return new Result().error(8000, e.getMessage()); - } - } - - private Result execute(HttpRequestBase httpMethod) { - CloseableHttpResponse response = null; - try { - response = httpclient.execute(httpMethod); - log.debug("http send response:{}", JSON.toJSONString(response)); - if (response != null && response.getStatusLine() != null) { - if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { - String result = EntityUtils.toString(response.getEntity()); - return new Result().ok(result); - } else { - log.warn("execute http method fail,httpStatus:{0}", response.getStatusLine().getStatusCode()); - } - } - } catch (Exception e) { - log.error("execute exception", e); - } finally { - httpMethod.releaseConnection(); - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - } - } - return new Result().error(8000, "系统异常"); - } -} - - diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/IAcsClientUtil.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/IAcsClientUtil.java deleted file mode 100644 index c0c8362727..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/IAcsClientUtil.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.epmet.openapi.scan.common.util; - -/** - * @author jianjun liu - * @date 2020-06-05 10:03 - **/ - -import com.aliyuncs.DefaultAcsClient; -import com.aliyuncs.IAcsClient; -import com.aliyuncs.exceptions.ClientException; -import com.aliyuncs.profile.DefaultProfile; -import com.aliyuncs.profile.IClientProfile; -import com.epmet.openapi.scan.common.enu.RegionIdEnum; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; - -@Slf4j -@Component -public class IAcsClientUtil { - private static String accessKeyId; - private static String secret; - private static String product = "Green"; - - private static String regionId; - private static String endpointName = ""; - - private static IClientProfile profile; - - - @PostConstruct - private void initProFile() { - profile = DefaultProfile.getProfile(regionId, accessKeyId, secret); - try { - DefaultProfile.addEndpoint(endpointName, regionId, product, RegionIdEnum.getDoMain(regionId)); - } catch (ClientException e) { - log.error("initProFile exception", e.getMessage()); - } - } - - - public static IAcsClient getIAcsClient() { - return new DefaultAcsClient(profile); - } - - @Value("${aliyun.green.accessKeyId}") - public void setAccessKeyId(String accessKeyId) { - IAcsClientUtil.accessKeyId = accessKeyId; - } - - @Value("${aliyun.green.accessKeySecret}") - public void setSecret(String secret) { - IAcsClientUtil.secret = secret; - } - - @Value("${aliyun.green.regionId}") - public void setRegionId(String regionId) { - IAcsClientUtil.regionId = regionId; - } - - @Value("${aliyun.green.regionId}") - public void setEndpointName(String endpointName) { - IAcsClientUtil.endpointName = endpointName; - } -} \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/MapUtil.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/MapUtil.java deleted file mode 100644 index e98dbfd7a2..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/MapUtil.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.epmet.openapi.scan.common.util; - -import org.apache.commons.lang3.StringUtils; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author jianjun liu - * @date 2020-06-05 16:44 - **/ -public class MapUtil { - /** - * 将url参数转换成map - * - * @param param aa=11&bb=22&cc=33 - * @return - */ - public static Map getUrlParams(String param) { - Map map = new HashMap<>(0); - if (StringUtils.isBlank(param)) { - return map; - } - String[] params = param.split("&"); - for (int i = 0; i < params.length; i++) { - String[] p = params[i].split("="); - if (p.length == 2) { - map.put(p[0], p[1]); - } - } - return map; - } - - /** - * 将map转换成url - * - * @param map - * @return - */ - public static String getUrlParamsByMap(Map map) { - if (map == null) { - return ""; - } - StringBuffer sb = new StringBuffer(); - for (Map.Entry entry : map.entrySet()) { - sb.append(entry.getKey() + "=" + entry.getValue()); - sb.append("&"); - } - String s = sb.toString(); - if (s.endsWith("&")) { - s = StringUtils.substringBeforeLast(s, "&"); - } - return s; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/ModuleConfigImpl.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/ModuleConfigImpl.java deleted file mode 100644 index 68532b7819..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/ModuleConfigImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2018 人人开源 All rights reserved. - * - * https://www.renren.io - * - * 版权所有,侵权必究! - */ - -package com.epmet.openapi.scan.config; - -import com.epmet.commons.tools.config.ModuleConfig; -import org.springframework.stereotype.Service; - -/** - * 模块配置信息 - * - * @author Mark sunlightcs@gmail.com - * @since 1.0.0 - */ -@Service -public class ModuleConfigImpl implements ModuleConfig { - @Override - public String getName() { - return "epmetscan"; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/WebAppConfig.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/WebAppConfig.java deleted file mode 100644 index c955a7f555..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/WebAppConfig.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.epmet.openapi.scan.config; - -import com.epmet.openapi.scan.interceptor.ScanApiAuthInterceptor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -/** - * @author jianjun liu - * @email liujianjun@yunzongnet.com - * @date 2020-06-08 14:30 - **/ - - @Configuration - public class WebAppConfig implements WebMvcConfigurer{ - @Autowired - private ScanApiAuthInterceptor scanApiAuthInterceptor; - - // 多个拦截器组成一个拦截器链 - // addPathPatterns 用于添加拦截规则 - // excludePathPatterns 用户排除拦截 - - @Override - public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(scanApiAuthInterceptor)//添加拦截器 - .addPathPatterns("/**") //拦截所有请求 - .excludePathPatterns("/opback/**");//对应的不拦截的请求 - } - } - diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/BackDoorController.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/BackDoorController.java deleted file mode 100644 index 433ff1b06d..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/BackDoorController.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.epmet.openapi.scan.controller; - -import com.alibaba.fastjson.JSON; -import com.epmet.openapi.scan.common.redis.RedisKeys; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.SetOperations; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Set; - -/** - * @author jianjun liu - * @date 2020-06-04 20:39 - **/ -@RestController -@RequestMapping("opback") -public class BackDoorController { - @Autowired - private RedisTemplate redisTemplate; - - @RequestMapping("addWhite") - public String addWhite(@RequestParam String ip) { - SetOperations setOperations = redisTemplate.opsForSet(); - String whiteList = RedisKeys.getWhiteList(); - Long add = setOperations.add(whiteList, ip); - Set members = setOperations.members(whiteList); - return "ip:" + ip + "添加" + (add > 0 ? "成功" : "失败") + ",当前所有列表:" + JSON.toJSONString(members); - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java deleted file mode 100644 index cee27d28b8..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.epmet.openapi.scan.controller; - -import com.epmet.commons.tools.utils.Result; -import com.epmet.commons.tools.validator.ValidatorUtils; -import com.epmet.openapi.scan.common.constant.SysConstant; -import com.epmet.openapi.scan.common.enu.SysResponseEnum; -import com.epmet.openapi.scan.service.impl.ScanService; -import com.epmet.openapi.scan.support.param.ImgScanParam; -import com.epmet.openapi.scan.support.param.TextScanParam; -import com.epmet.openapi.scan.support.param.VoiceAsyncScanParam; -import com.epmet.openapi.scan.support.param.video.VideoAsyncScanParam; -import com.epmet.openapi.scan.support.result.ImgAsyncScanResult; -import com.epmet.openapi.scan.support.result.SyncScanResult; -import com.epmet.openapi.scan.support.result.VoiceAsyncScanResult; -import com.epmet.openapi.scan.support.result.VoiceAsyncScanTaskResult; -import com.epmet.openapi.scan.support.result.video.VideoAsyncScanTaskResultDTO; -import com.epmet.openapi.scan.support.result.video.VideoResultDTO; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; - -/** - * @author jianjun liu - * @email liujianjun@yunzongnet.com - * @date 2020-06-05 10:39 - **/ -@RestController -@RequestMapping("api") -public class ScanController { - - @Autowired - private ScanService scanService; - - /** - * desc:图片同步检测接口 - * - * @param param - * @return - */ - @RequestMapping("imgSyncScan") - public Result ImgSyncScan(@RequestBody ImgScanParam param) { - ValidatorUtils.validateEntity(param); - return scanService.sendSyncImgScan(param); - } - - /** - * desc:文本同步检测接口 - * - * @param param - * @return - */ - @RequestMapping("textSyncScan") - public Result textSyncScan(@RequestBody TextScanParam param) { - ValidatorUtils.validateEntity(param); - return scanService.sendTextScan(param); - } - - //@RequestMapping("imgAsyncScan") - public Result ImgAsyncScan(@RequestBody ImgScanParam param) { - return null;//scanService.sendASyncImgScan(param); - } - - - /** - * @description 语音异步检测 - * @Date 2020/12/9 9:14 - **/ - @PostMapping("voiceAsyncScan") - public Result voiceAsyncScan(@RequestBody VoiceAsyncScanParam param){ - ValidatorUtils.validateEntity(param); - return scanService.sendVoiceAsyncScan(param); - } - - /** - * @param taskIds 要查询的异步检测任务的taskId列表。数组中的元素个数不超过100个 - * @author yinzuomei - * @description 语音异步检测结果查询 - * @Date 2020/12/9 11:16 - **/ - @PostMapping("voiceResults") - public Result> voiceResults(@RequestBody List taskIds){ - return scanService.voiceResults(taskIds); - } - - /** - * @author yinzuomei - * @description 视频检测-异步检测 - **/ - @PostMapping("videoAsyncScan") - public Result videoAsyncScan(@RequestBody VideoAsyncScanParam param) { - ValidatorUtils.validateEntity(param); - return scanService.videoAsyncScan(param); - } - - /** - * @author yinzuomei - * @description 视频异步检测结果查询接口 - **/ - @PostMapping("videoResults") - public Result videoResults(@RequestBody List taskIds) { - if (CollectionUtils.isEmpty(taskIds)) { - return new Result<>(); - } - //检测对象不能为空,且最多支持100个元素 - if (org.springframework.util.CollectionUtils.isEmpty(taskIds) || taskIds.size() > SysConstant.MAX_TASK_SIZE) { - return new Result().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), - SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg().concat(SysConstant.MAX_TASK_SIZE.toString())); - } - return scanService.videoResults(taskIds); - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiAuthInterceptor.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiAuthInterceptor.java deleted file mode 100644 index 6ce851a45e..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiAuthInterceptor.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.epmet.openapi.scan.interceptor; - -import com.alibaba.fastjson.JSON; -import com.epmet.commons.tools.exception.EpmetErrorCode; -import com.epmet.commons.tools.utils.IpUtils; -import com.epmet.commons.tools.utils.Result; -import com.epmet.openapi.scan.common.redis.RedisKeys; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.SetOperations; -import org.springframework.stereotype.Component; -import org.springframework.web.servlet.HandlerInterceptor; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; - -/** - * @author jianjun liu - * @date 2020-06-05 16:36 - **/ -@Component -public class ScanApiAuthInterceptor implements HandlerInterceptor { - private static final Logger log = LoggerFactory.getLogger(ScanApiAuthInterceptor.class); - @Autowired - private RedisTemplate redisTemplate; - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - String ip = IpUtils.getIpAddr(request); - SetOperations setOperations = redisTemplate.opsForSet(); - if (!setOperations.isMember(RedisKeys.getWhiteList(), ip)) { - log.warn("preHandle ip:{} is not in whitelist", ip); - String result = JSON.toJSONString(new Result<>().error(EpmetErrorCode.ERR401.getCode(), EpmetErrorCode.ERR401.getMsg())); - responseJson(response, result); - return false; - } - return true; - } - - private void responseJson(HttpServletResponse response, String json) throws Exception { - PrintWriter writer = null; - response.setCharacterEncoding("UTF-8"); - response.setContentType("text/json; charset=utf-8"); - try { - writer = response.getWriter(); - writer.print(json); - } catch (IOException e) { - log.error(e.toString()); - } finally { - if (writer != null) { - writer.close(); - } - } - } - -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanService.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanService.java deleted file mode 100644 index 4a3e734893..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanService.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.epmet.openapi.scan.service.impl; - -import com.epmet.commons.tools.utils.Result; -import com.epmet.openapi.scan.support.param.ImgScanParam; -import com.epmet.openapi.scan.support.param.TextScanParam; -import com.epmet.openapi.scan.support.param.VoiceAsyncScanParam; -import com.epmet.openapi.scan.support.param.video.VideoAsyncScanParam; -import com.epmet.openapi.scan.support.result.SyncScanResult; -import com.epmet.openapi.scan.support.result.VoiceAsyncScanResult; -import com.epmet.openapi.scan.support.result.VoiceAsyncScanTaskResult; -import com.epmet.openapi.scan.support.result.video.VideoAsyncScanTaskResultDTO; -import com.epmet.openapi.scan.support.result.video.VideoResultDTO; - -import java.util.List; - -/** - * desc:内容扫描接口 - * - * @author jianjun liu - * @email liujianjun@yunzongnet.com - * @date 2020-06-05 13:12 - **/ -public interface ScanService { - /** - * desc:扫描文本内容 同步 - * @param textScanParam - * @return ImgAsyncScanResult - */ - public Result sendTextScan(TextScanParam textScanParam); - - - /** - * desc:扫描图片内容 同步 - * @param imgScanParam - * @return - */ - public Result sendSyncImgScan(ImgScanParam imgScanParam); - - /** - * 语音异步检测 - * - * @param param - * @return com.epmet.openapi.scan.support.result.VoiceAsyncScanTaskResult - */ - Result sendVoiceAsyncScan(VoiceAsyncScanParam param); - - /** - * 语音异步检测结果查询 - * - * @param taskIds 要查询的异步检测任务的taskId列表。数组中的元素个数不超过100个 - * @return com.epmet.openapi.scan.support.result.VoiceAsyncScanResult - */ - Result> voiceResults(List taskIds); - - /** - * desc:视频检测-异步检测 - * @param videoAsyncScanParam - * @return 异步检测)返回数据:taskId<=>dataId - */ - Result videoAsyncScan(VideoAsyncScanParam videoAsyncScanParam); - - /** - * @param taskIds - * @author yinzuomei - * @description 视频异步检测结果查询接口 - * @Date 2020/12/29 16:10 - **/ - Result videoResults(List taskIds); -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java deleted file mode 100644 index 44dd0da3de..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java +++ /dev/null @@ -1,734 +0,0 @@ -package com.epmet.openapi.scan.service.impl; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.aliyuncs.AcsRequest; -import com.aliyuncs.green.model.v20180509.*; -import com.aliyuncs.http.FormatType; -import com.aliyuncs.http.HttpResponse; -import com.epmet.commons.tools.constant.NumConstant; -import com.epmet.commons.tools.utils.ConvertUtils; -import com.aliyuncs.http.MethodType; -import com.epmet.commons.tools.utils.Result; -import com.epmet.openapi.scan.common.constant.SysConstant; -import com.epmet.openapi.scan.common.enu.*; -import com.epmet.openapi.scan.common.exception.ExecuteHttpException; -import com.epmet.openapi.scan.common.redis.RedisKeys; -import com.epmet.openapi.scan.common.util.IAcsClientUtil; -import com.epmet.openapi.scan.support.param.*; -import com.epmet.openapi.scan.support.param.video.VideoAsyncScanParam; -import com.epmet.openapi.scan.support.param.video.VideoAsyncScanTask; -import com.epmet.openapi.scan.support.result.*; -import com.epmet.openapi.scan.support.result.video.*; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.ListUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.http.HttpStatus; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.ValueOperations; -import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; - -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -/** - * @author jianjun liu - * @email liujianjun@yunzongnet.com - * @date 2020-06-05 13:16 - **/ -@Slf4j -@Service -public class ScanServiceImpl implements ScanService { - @Value("${aliyun.green.regionId}") - private String regionId; - @Value("${aliyun.green.bizType}") - private String bizType; - @Autowired - private RedisTemplate redisTemplate; - @Override - public Result sendTextScan(TextScanParam textScanParam) { - //默认参数 - // 鉴黄 暴恐涉政 - textScanParam.setScenes(TextSceneEnum.getTextSceneList()); - textScanParam.setBizType(bizType); - - List textTasks = textScanParam.getTasks(); - if (CollectionUtils.isEmpty(textTasks) || textTasks.size() > SysConstant.MAX_TASK_SIZE) { - return new Result().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg().concat(SysConstant.MAX_TASK_SIZE.toString())); - } - - TextScanRequest textScanRequest = getTextScanRequest(); - - try { - textScanRequest.setHttpContent(JSON.toJSONString(textScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); - } catch (UnsupportedEncodingException e) { - log.error("sendTextScan parse param exception", e); - return new Result().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); - } - - try { - SyncScanResult textScanResult = executeSyncText(textScanRequest); - return new Result().ok(textScanResult); - } catch (ExecuteHttpException e) { - log.error("sendTextScan execute Exception", e); - return new Result().error(e.getCode(), e.getMsg()); - } - } - - private TextScanRequest getTextScanRequest() { - TextScanRequest textScanRequest = new TextScanRequest(); - textScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式 - textScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法 - textScanRequest.setEncoding(SysConstant.UTF8); - textScanRequest.setRegionId(regionId); - textScanRequest.setConnectTimeout(3000); - textScanRequest.setReadTimeout(6000); - return textScanRequest; - } - - @Override - public Result sendSyncImgScan(ImgScanParam imgScanParam) { - //默认参数 - // 鉴黄 暴恐涉政 - imgScanParam.setScenes(ImgSceneEnum.getImgSceneList()); - imgScanParam.setBizType(bizType); - - List imgTasks = imgScanParam.getTasks(); - if (CollectionUtils.isEmpty(imgTasks) || imgTasks.size() > SysConstant.MAX_TASK_SIZE) { - return new Result().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg().concat(SysConstant.MAX_TASK_SIZE.toString())); - } - if (imgTasks.size() <= SysConstant.MAX_SCAN_IMG_TASK_SIZE) { - return doScanImg(imgScanParam); - } - log.info("sendSyncImgScan tasks size:{} over 10", imgTasks.size()); - List> partition = ListUtils.partition(imgTasks, SysConstant.MAX_SCAN_IMG_TASK_SIZE); - SyncScanResult finalResult = new SyncScanResult(); - for (List tasks : partition) { - ImgScanParam scanParam = new ImgScanParam(); - scanParam.setBizType(imgScanParam.getBizType()); - scanParam.setScenes(imgScanParam.getScenes()); - scanParam.setTasks(tasks); - scanParam.setCallback(imgScanParam.getCallback()); - scanParam.setSeed(imgScanParam.getSeed()); - Result partResult = doScanImg(scanParam); - try { - Thread.sleep(5L); - } catch (InterruptedException e) { - log.error("sendSyncImgScan InterruptedException"); - } - if (partResult.success()) { - SyncScanResult data = partResult.getData(); - finalResult.getSuccessDataIds().addAll(data.getSuccessDataIds()); - finalResult.getFailDataIds().addAll(data.getFailDataIds()); - finalResult.getDetails().addAll(data.getDetails()); - } else { - return partResult; - } - } - return new Result().ok(finalResult); - - - } - - private Result doScanImg(ImgScanParam imgScanParam) { - ImageSyncScanRequest imageSyncScanRequest = getImgScanRequest(); - try { - imageSyncScanRequest.setHttpContent(JSON.toJSONString(imgScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); - } catch (UnsupportedEncodingException e) { - log.error("sendSyncImgScan parse param exception", e); - return new Result().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); - } - - try { - SyncScanResult scanResult = executeSyncImg(imageSyncScanRequest); - return new Result().ok(scanResult); - } catch (ExecuteHttpException e) { - log.error("sendImgScan execute exception,param:{},fail msg:{}", JSON.toJSONString(imgScanParam), e.getMsg()); - return new Result().error(e.getCode(), e.getMsg()); - } - } - - private ImageSyncScanRequest getImgScanRequest() { - ImageSyncScanRequest imageSyncScanRequest = new ImageSyncScanRequest(); - imageSyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式 - imageSyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法 - imageSyncScanRequest.setEncoding(SysConstant.UTF8); - imageSyncScanRequest.setRegionId(regionId); - imageSyncScanRequest.setConnectTimeout(3000); - imageSyncScanRequest.setReadTimeout(6000); - return imageSyncScanRequest; - } - - public SyncScanResult executeSyncText(AcsRequest textScanRequest) { - SyncScanResult result = new SyncScanResult(); - try { - HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(textScanRequest); - - if (httpResponse.isSuccess()) { - JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), SysConstant.UTF8)); - if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { - //任务 列表 - List scanTaskResults = scrResponse.getJSONArray(SysConstant.DATA).toJavaList(ScanTaskResult.class); - for (ScanTaskResult taskResult : scanTaskResults) { - result.getDetails().add(taskResult); - //又根据场景不同 - if (HttpStatus.SC_OK != taskResult.getCode()) { - if (!result.getFailDataIds().contains(taskResult.getDataId())) { - result.getFailDataIds().add(taskResult.getDataId()); - log.warn("executeSyncText task process fail:code:{},result:{}", taskResult.getCode(), JSON.toJSONString(taskResult)); - } - continue; - } - //如果是多个场景 则为对个 BaseScanResult - List sceneResults = taskResult.getResults(); - //是文本检测 目前就一种场景 - boolean isSuccess = true; - for (SceneDetailResult sceneResult : sceneResults) { - String suggestion = sceneResult.getSuggestion(); - if (SuggestionEnum.BLOCK.getCode().equals(suggestion)) { - isSuccess = false; - break; - } - } - if (isSuccess) { - result.getSuccessDataIds().add(taskResult.getDataId()); - } else { - log.warn("executeSyncText dataId:{} block:{}", taskResult.getDataId(), JSON.toJSONString(taskResult.getResults())); - result.getFailDataIds().add(taskResult.getDataId()); - } - } - return result; - } else { - log.warn("executeSyncText response not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); - } - } else { - log.warn("executeSyncText response status is not success. httpResponse:{}", JSON.toJSONString(httpResponse)); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); - } - } catch (Exception e) { - log.error("executeSyncText exception IAcsClientUtil do action exception", e); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getMsg()); - } - } - - private SyncScanResult executeSyncImg(AcsRequest request) { - SyncScanResult result = new SyncScanResult(); - try { - HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(request); - if (httpResponse.isSuccess()) { - JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), SysConstant.UTF8)); - if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { - JSONArray taskResults = scrResponse.getJSONArray(SysConstant.DATA); - List scanTaskResults = taskResults.toJavaList(ScanTaskResult.class); - for (ScanTaskResult taskResult : scanTaskResults) { - result.getDetails().add(taskResult); - if (HttpStatus.SC_OK != taskResult.getCode()) { - if (!result.getFailDataIds().contains(taskResult.getDataId())) { - result.getFailDataIds().add(taskResult.getDataId()); - log.warn("executeSyncImg detect not success. code:{},result:{}", taskResult.getCode(), JSON.toJSONString(taskResult)); - } - continue; - } - //如果是多个场景 则为对个 BaseScanResult - List sceneResults = taskResult.getResults(); - - boolean isSuccess = true; - for (SceneDetailResult sceneResult : sceneResults) { - String suggestion = sceneResult.getSuggestion(); - if (SuggestionEnum.BLOCK.getCode().equals(suggestion)) { - isSuccess = false; - break; - } - } - if (isSuccess) { - result.getSuccessDataIds().add(taskResult.getDataId()); - } else { - log.warn("executeSyncImg dataId:{} block:{}", taskResult.getDataId(), JSON.toJSONString(taskResult.getResults())); - result.getFailDataIds().add(taskResult.getDataId()); - } - } - return result; - } else { - log.warn("executeSyncImg detect not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); - } - } else { - log.warn("executeSyncImg response status is not success. httpResponse:{}", JSON.toJSONString(httpResponse)); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); - } - } catch (Exception e) { - log.error("executeSyncImg exception IAcsClientUtil do action exception", e); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getMsg()); - } - } - - /** - * @author yinzuomei - * @description 语音异步检测 - * @Date 2020/12/9 10:02 - */ - @Override - public Result sendVoiceAsyncScan(VoiceAsyncScanParam voiceAsyncScanParam) { - //检测对象不能为空,且最多支持100个元素 - List voiceTasks = voiceAsyncScanParam.getTasks(); - if (CollectionUtils.isEmpty(voiceTasks) || voiceTasks.size() > SysConstant.MAX_TASK_SIZE) { - return new Result().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), - SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg().concat(SysConstant.MAX_TASK_SIZE.toString())); - } - - //默认参数 - voiceAsyncScanParam.setScenes(VoiceSceneEnum.getVoiceSceneList()); - voiceAsyncScanParam.setBizType(bizType); - // 如果是语音流检测,则修改为true。现在默认为音频文件检测false - voiceAsyncScanParam.setLive(false); - voiceAsyncScanParam.setSeed(UUID.randomUUID().toString().replace("-", "")); - - VoiceAsyncScanRequest voiceAsyncScanRequest=getVoiceAsyncScanRequest(); - - try { - voiceAsyncScanRequest.setHttpContent(JSON.toJSONString(voiceAsyncScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); - } catch (UnsupportedEncodingException e) { - log.error("sendVoiceAsyncScan parse param exception", e); - return new Result().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); - } - log.info("语音异步检测入参:"+JSON.toJSONString(voiceAsyncScanParam,true)); - List taskList; - try { - taskList = executeSyncVoice(voiceAsyncScanRequest); - log.info("语音异步检测返参taskList:"+JSON.toJSONString(taskList,true)); - } catch (ExecuteHttpException e) { - log.error("sendVoiceAsyncScan execute Exception", e); - return new Result().error(e.getCode(), e.getMsg()); - } - //成功返回 - VoiceAsyncScanTaskResult resultDto=new VoiceAsyncScanTaskResult(); - resultDto.setSeed(voiceAsyncScanParam.getSeed()); - List successList = new ArrayList<>(); - List failedList = new ArrayList<>(); - taskList.forEach(taskDetail -> { - if (HttpStatus.SC_OK == taskDetail.getCode()) { - successList.add(taskDetail); - } else { - failedList.add(taskDetail); - } - }); - resultDto.setSuccessTasks(successList); - resultDto.setFailTasks(failedList); - resultDto.setAllSuccess(resultDto.isAllSuccess()); - if (StringUtils.isNotBlank(voiceAsyncScanParam.getCallback())) { - // 存储seed和 任务id、dataId的关系 用于回调鉴权 - log.info("need to save seed and taskId、dataId的关系"); - ValueOperations valueOperations=redisTemplate.opsForValue(); - taskList.forEach(task -> { - String seedKey = RedisKeys.getVoiceScanSeedKey(task.getTaskId()); - valueOperations.set(seedKey,voiceAsyncScanParam.getSeed()); - }); - } - return new Result().ok(resultDto); - } - - /** - * @param - * @author yinzuomei - * @description 构造语音异步检测请求对象 - * @Date 2020/12/9 10:44 - **/ - private VoiceAsyncScanRequest getVoiceAsyncScanRequest() { - VoiceAsyncScanRequest voiceAsyncScanRequest = new VoiceAsyncScanRequest(); - // 指定api返回格式 - voiceAsyncScanRequest.setAcceptFormat(FormatType.JSON); - // 指定请求方法 - voiceAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); - voiceAsyncScanRequest.setEncoding(SysConstant.UTF8); - voiceAsyncScanRequest.setRegionId(regionId); - voiceAsyncScanRequest.setConnectTimeout(3000); - voiceAsyncScanRequest.setReadTimeout(6000); - return voiceAsyncScanRequest; - } - - /** - * @param voiceAsyncScanRequest - * @author yinzuomei - * @description 解析返参 - * @Date 2020/12/9 10:44 - **/ - private List executeSyncVoice(AcsRequest voiceAsyncScanRequest) { - try { - HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(voiceAsyncScanRequest); - - if (httpResponse.isSuccess()) { - - JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); - //后面注释掉此日志 - log.info("VoiceAsyncScanRequest原生接口返参:" + JSON.toJSONString(scrResponse, true)); - - if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { - - //获取data列表 - JSONArray dataResults = scrResponse.getJSONArray(SysConstant.DATA); - List resultList = dataResults.toJavaList(VoiceAsyncScanTaskDataDTO.class); - //成功返回 - return resultList; - - } else { - - log.warn("executeSyncVoice detect not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getCode(), - SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); - } - - } else { - log.warn("executeSyncVoice response status is not success. httpResponse:{}", JSON.toJSONString(httpResponse)); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getCode(), - SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); - } - - } catch (Exception e) { - log.error("executeSyncVoice exception IAcsClientUtil do action exception", e); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getMsg()); - } - } - - - /** - * @param taskIds 要查询的异步检测任务的taskId列表。数组中的元素个数不超过100个 - * @author yinzuomei - * @description 语音异步检测结果查询 - * @Date 2020/12/9 11:17 - **/ - @Override - public Result> voiceResults(List taskIds) { - //检测对象不能为空,且最多支持100个元素 - if (CollectionUtils.isEmpty(taskIds) || taskIds.size() > SysConstant.MAX_TASK_SIZE) { - return new Result>().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), - SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg().concat(SysConstant.MAX_TASK_SIZE.toString())); - } - - VoiceAsyncScanResultsRequest request=getVoiceAsyncScanResultsRequest(); - try { - request.setHttpContent(JSON.toJSONString(taskIds).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); - } catch (UnsupportedEncodingException e) { - log.error("voiceResults parse param exception", e); - return new Result>().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); - } - - // log.info("语音异步检测结果查询入参:"+JSON.toJSONString(taskIds,true)); - - try { - HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(request); - if (httpResponse.isSuccess()) { - - JSONObject scrResponse=JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); - //后面注释掉此返参 - log.info("VoiceAsyncScanResultsRequest原生接口返参:"+JSON.toJSONString(scrResponse, true)); - if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { - //获取data列表 - JSONArray dataResults = scrResponse.getJSONArray(SysConstant.DATA); - List resultList = dataResults.toJavaList(VoiceAsyncScanResult.class); - List resultData=processVoiceAsyncScanResult(resultList); - //成功返回 - return new Result>().ok(resultData); - - }else{ - - log.warn("voiceResults detect not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getCode(), - SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); - } - - } else { - log.warn("语音异步检测结果查询预警 getVoiceAsyncScanResult response status is not success. httpResponse:{}", JSON.toJSONString(httpResponse)); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getCode(), - SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); - } - } catch (Exception e) { - log.error("voiceResults exception IAcsClientUtil do action exception", e); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getMsg()); - } - - } - - private List processVoiceAsyncScanResult(List resultList) { - List list = new ArrayList<>(); - for (VoiceAsyncScanResult voiceAsyncScanResult : resultList) { - if (SysConstant.PROCESSING == voiceAsyncScanResult.getCode()) { - //280:表示处理中,需要继续轮询 - continue; - } - VoiceAsyncScanResult dto = ConvertUtils.sourceToTarget(voiceAsyncScanResult, VoiceAsyncScanResult.class); - if (HttpStatus.SC_OK == voiceAsyncScanResult.getCode()) { - if (!CollectionUtils.isEmpty(voiceAsyncScanResult.getResults()) && voiceAsyncScanResult.getResults().size() > NumConstant.ZERO) { - //目前只有一个检测场景,所以只判断返回来的第一个场景 - VoiceAsyncScanResultDTO voiceAsyncScanResultDTO = voiceAsyncScanResult.getResults().get(NumConstant.ZERO); - if (null != voiceAsyncScanResultDTO) { - dto.setLabel(voiceAsyncScanResultDTO.getLabel()); - dto.setLabelDesc(LabelEnum.getDesc(voiceAsyncScanResultDTO.getLabel())); - dto.setSuggestion(voiceAsyncScanResultDTO.getSuggestion()); - } - } - } else if(HttpStatus.SC_NOT_FOUND == voiceAsyncScanResult.getCode()) { - dto.setSuggestion(SuggestionEnum.REVIEW.getCode()); - dto.setLabel(NumConstant.EMPTY_STR); - dto.setLabelDesc("智能检测任务失败,结果已失效," + SuggestionEnum.REVIEW.getDesc()); - }else{ - //其他:表示任务失败 - dto.setSuggestion(SuggestionEnum.REVIEW.getCode()); - dto.setLabel(NumConstant.EMPTY_STR); - dto.setLabelDesc("智能检测任务失败," + SuggestionEnum.REVIEW.getDesc()); - } - list.add(dto); - } - return list; - } - - private VoiceAsyncScanResultsRequest getVoiceAsyncScanResultsRequest(){ - VoiceAsyncScanResultsRequest getResultsRequest = new VoiceAsyncScanResultsRequest(); - // 指定API返回格式。 - getResultsRequest.setAcceptFormat(FormatType.JSON); - // 指定请求方法。 - getResultsRequest.setMethod(com.aliyuncs.http.MethodType.POST); - getResultsRequest.setEncoding(SysConstant.UTF8); - getResultsRequest.setRegionId(regionId); - /** - * 请务必设置超时时间。 - */ - getResultsRequest.setConnectTimeout(3000); - getResultsRequest.setReadTimeout(6000); - return getResultsRequest; - } - - /** - * desc:视频检测-异步检测 - * - * @param videoAsyncScanParam - * @return - */ - @Override - public Result videoAsyncScan(VideoAsyncScanParam videoAsyncScanParam) { - //一次至多提交100个检测对象 - List videoTasks = videoAsyncScanParam.getTasks(); - if (CollectionUtils.isEmpty(videoTasks) || videoTasks.size() > SysConstant.MAX_TASK_SIZE) { - return new Result().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg().concat(SysConstant.MAX_TASK_SIZE.toString())); - } - //默认参数赋值 - videoAsyncScanParam.setScenes(VideoSceneEnum.getVideoSceneList()); - videoAsyncScanParam.setBizType(bizType); - videoAsyncScanParam.setAudioScenes(VoiceSceneEnum.getVoiceSceneList()); - videoAsyncScanParam.setSeed(UUID.randomUUID().toString().replace("-", "")); - //API文档没写限制多少最大多少,应该与图片一致 - if (videoTasks.size() <= SysConstant.MAX_SCAN_IMG_TASK_SIZE) { - return doScanVideo(videoAsyncScanParam); - } - log.info("videoAsyncScan tasks size:{} over 10", videoTasks.size()); - //分组调用,一次提交10个 - List> partition = ListUtils.partition(videoTasks, SysConstant.MAX_SCAN_IMG_TASK_SIZE); - VideoAsyncScanTaskResultDTO finalResult = new VideoAsyncScanTaskResultDTO(); - for (List tasks : partition) { - VideoAsyncScanParam videParam = new VideoAsyncScanParam(); - videParam.setBizType(videoAsyncScanParam.getBizType()); - videParam.setScenes(videoAsyncScanParam.getScenes()); - videParam.setTasks(tasks); - videParam.setCallback(videoAsyncScanParam.getCallback()); - videParam.setSeed(videoAsyncScanParam.getSeed()); - videParam.setAudioScenes(videoAsyncScanParam.getAudioScenes()); - Result partResult = doScanVideo(videParam); - try { - Thread.sleep(5L); - } catch (InterruptedException e) { - log.error("videoAsyncScan InterruptedException"); - } - if (partResult.success()) { - VideoAsyncScanTaskResultDTO data = partResult.getData(); - finalResult.setSeed(data.getSeed()); - finalResult.getSuccessTasks().addAll(data.getSuccessTasks()); - finalResult.getFailTasks().addAll(data.getFailTasks()); - } else { - return partResult; - } - } - return new Result().ok(finalResult); - } - - private Result doScanVideo(VideoAsyncScanParam videoAsyncScanParam) { - VideoAsyncScanRequest videoAsyncScanRequest = getVideoAsyncScanRequest(); - try { - videoAsyncScanRequest.setHttpContent(JSON.toJSONString(videoAsyncScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); - } catch (UnsupportedEncodingException e) { - log.error("doScanVideo parse param exception", e); - return new Result().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); - } - - try { - VideoAsyncScanTaskResultDTO scanResult = executeAsyncVideo(videoAsyncScanRequest); - scanResult.setSeed(videoAsyncScanParam.getSeed()); - return new Result().ok(scanResult); - } catch (ExecuteHttpException e) { - log.error("doScanVideo execute exception,param:{},fail msg:{}", JSON.toJSONString(videoAsyncScanParam), e.getMsg()); - return new Result().error(e.getCode(), e.getMsg()); - } - } - - private VideoAsyncScanRequest getVideoAsyncScanRequest() { - VideoAsyncScanRequest videoAsyncScanRequest = new VideoAsyncScanRequest(); - videoAsyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定API返回格式。 - videoAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法。 - /** - * 请务必设置超时时间。 - */ - videoAsyncScanRequest.setConnectTimeout(3000); - videoAsyncScanRequest.setReadTimeout(6000); - return videoAsyncScanRequest; - } - - private VideoAsyncScanTaskResultDTO executeAsyncVideo(VideoAsyncScanRequest videoAsyncScanRequest) { - try { - HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(videoAsyncScanRequest); - if (httpResponse.isSuccess()) { - JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); - if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { - //获取data列表 - JSONArray dataResults = scrResponse.getJSONArray(SysConstant.DATA); - List dataList = dataResults.toJavaList(VideoAsyncScanTaskDataDTO.class); - VideoAsyncScanTaskResultDTO result=new VideoAsyncScanTaskResultDTO(); - dataList.forEach(data->{ - if (HttpStatus.SC_OK == data.getCode()) { - result.getSuccessTasks().add(data); - } else { - result.getFailTasks().add(data); - } - }); - return result; - } else { - log.warn("executeAsyncVideo detect not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getCode(), - SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); - } - } else { - log.warn("executeAsyncVideo response status is not success. httpResponse:{}", JSON.toJSONString(httpResponse)); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getCode(), - SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); - } - } catch (Exception e) { - log.error("executeAsyncVideo exception IAcsClientUtil do action exception", e); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getMsg()); - } - } - - /** - * @param taskIds - * @author yinzuomei - * @description 视频异步检测结果查询接口 - * @Date 2020/12/29 16:10 - **/ - @Override - public Result videoResults(List taskIds) { - VideoAsyncScanResultsRequest videoAsyncScanResultsRequest = new VideoAsyncScanResultsRequest(); - videoAsyncScanResultsRequest.setAcceptFormat(FormatType.JSON); - videoAsyncScanResultsRequest.setMethod(com.aliyuncs.http.MethodType.POST); - videoAsyncScanResultsRequest.setConnectTimeout(3000); - videoAsyncScanResultsRequest.setReadTimeout(6000); - try { - videoAsyncScanResultsRequest.setHttpContent(JSON.toJSONString(taskIds).getBytes("UTF-8"), "UTF-8", FormatType.JSON); - } catch (UnsupportedEncodingException e) { - log.error("videoResults parse param exception", e); - return new Result().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); - } - try { - HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(videoAsyncScanResultsRequest); - if (httpResponse.isSuccess()) { - JSONObject responseObject = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); - log.info("查询视频检测结果返参"+JSON.toJSONString(responseObject)); - if (HttpStatus.SC_OK == responseObject.getInteger(SysConstant.CODE)) { - //获取data列表 - JSONArray dataResults = responseObject.getJSONArray(SysConstant.DATA); - List resultList = dataResults.toJavaList(VideoScanOriginalResultDTO.class); - //解析数据 - VideoResultDTO resultDTO = processVideoResults(resultList); - //成功返回 - return new Result().ok(resultDTO); - } else { - log.warn("查询视频检测结果,接口返回code=" + responseObject.getInteger(SysConstant.CODE)); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getCode(), - SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); - } - } else { - log.warn("查询视频检测结果,API返回失败"); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getCode(), - SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); - } - } catch (Exception e) { - log.error("videoResults exception ", e); - throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getMsg()); - } - } - - /** - * @author yinzuomei - * @description - **/ - private VideoResultDTO processVideoResults(List resultList) { - VideoResultDTO videoResultDTO = new VideoResultDTO(); - resultList.forEach(result -> { - result.setCodeDesc(CommonErrorCodeEnum.getErrorMsg(result.getCode())); - if (result.getCode().equals(CommonErrorCodeEnum.PROCESSING.getCode())) { - //任务正在检测中,继续轮询 - } else if (result.getCode().equals(CommonErrorCodeEnum.OK.getCode())) { - //成功=>分析结果 - boolean videoPassFlag = getVideoFlag(result.getResults()); - boolean voicePassFlag = getVoiceFlag(result.getAudioScanResults()); - if (videoPassFlag && voicePassFlag) { - videoResultDTO.getPassDataIds().add(result.getDataId()); - videoResultDTO.getPassTaskIds().add(result.getTaskId()); - } else { - videoResultDTO.getNoPassDataIds().add(result.getDataId()); - videoResultDTO.getNoPassTaskIds().add(result.getTaskId()); - } - } else { - //检测结果走丢了.... (*^▽^*) 默认失败 - videoResultDTO.getNoPassDataIds().add(result.getDataId()); - videoResultDTO.getNoPassTaskIds().add(result.getTaskId()); - } - }); - videoResultDTO.setDetails(resultList); - return videoResultDTO; - } - - /** - * @return boolean - * @author yinzuomei - * @description 视频检测结果判断 - **/ - private boolean getVideoFlag(List results) { - for(VideoScanOriginDetail videoRes:results){ - if (!SuggestionEnum.PASS.getCode().equals(videoRes.getSuggestion())) { - return false; - } - } - return true; - } - - /** - * @return boolean true:内容通过; 建议为内容违规或者需要人工审核的统一视为不通过,返回false - * @author yinzuomei - * @description 返回视频语音检测结果 - **/ - private boolean getVoiceFlag(List audioScanResults) { - if (CollectionUtils.isEmpty(audioScanResults)) { - return true; - } - for(VoiceAsyncScanResultDTO m:audioScanResults){ - //人工审核或者内容违规,统一视为不通过 - if (!SuggestionEnum.PASS.getCode().equals(m.getSuggestion())) { - return false; - } - } - return true; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java deleted file mode 100644 index 82036797e3..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.epmet.openapi.scan.support.param; - -import lombok.Data; - -import javax.validation.Valid; -import javax.validation.constraints.NotEmpty; -import java.io.Serializable; -import java.util.List; - -/** - * 审查参数 - * - * @author jianjun liu - * @date 2020-06-04 21:57 - **/ -@Data -public class ImgScanParam implements Serializable { - - private static final long serialVersionUID = 958801658335909745L; - /** - * 业务类型 - */ - private String bizType; - /** - * 场景 必填 - * - * @see com.epmet.openapi.scan.common.enu.ImgSceneEnum; - */ - private List scenes; - - /** - * 要检测的内容列表,必填 - * remark:一组任务列表中的taskId不能相同 - */ - @Valid - @NotEmpty(message = "任务列表不能为空") - private List tasks; - - /** - * 异步检测结果回调地址,执行异步审查内容时 必填 - */ - private String callback; - - /** - * 随机字符串,该值用于回调通知请求中的签名,使用callback时 必填 - */ - private String seed; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java deleted file mode 100644 index 487485b7fc..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.epmet.openapi.scan.support.param; - -import lombok.Data; - -import javax.validation.constraints.NotBlank; -import java.io.Serializable; - -/** - * 任务参数 - * - * @author jianjun liu - * @email liujianjun@yunzongnet.com - * @date 2020-06-04 22:13 - **/ -@Data -public class ImgTask implements Serializable { - - private static final long serialVersionUID = -747206284930578105L; - /** - * 要检测的数据id 非必填 - * - * */ - @NotBlank(message = "dataId不能为空") - private String dataId; - - /** - * 图片url 必填 - */ - @NotBlank(message = "图片URL不能为空") - private String url; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java deleted file mode 100644 index 2b05d34e20..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.epmet.openapi.scan.support.param; - -import lombok.Data; - -import javax.validation.Valid; -import javax.validation.constraints.NotEmpty; -import java.io.Serializable; -import java.util.List; - -/** - * 文本审查参数 - * - * @author jianjun liu - * @date 2020-06-05 11:17 - **/ -@Data -public class TextScanParam implements Serializable { - private static final long serialVersionUID = -3568903097975113166L; - - /** - * 业务类型 - */ - private String bizType; - /** - * 场景 必填 - * - * @see com.epmet.openapi.scan.common.enu.ImgSceneEnum; - */ - private List scenes; - - /** - * 要检测的内容列表,必填 - * remark:一组任务列表中的taskId不能相同 - */ - @Valid - @NotEmpty(message = "任务列表不能为空") - private List tasks; - - /** - * 异步检测结果回调地址,执行异步审查内容时 必填 - */ - private String callback; - - /** - * 随机字符串,该值用于回调通知请求中的签名,使用callback时 必填 - */ - private String seed; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextTask.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextTask.java deleted file mode 100644 index 08215e3e5b..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextTask.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.epmet.openapi.scan.support.param; - -import lombok.Data; -import org.hibernate.validator.constraints.Length; - -import javax.validation.constraints.NotBlank; -import java.io.Serializable; - -/** - * 任务参数 - * - * @author jianjun liu - * @email liujianjun@yunzongnet.com - * @date 2020-06-04 22:13 - **/ -@Data -public class TextTask implements Serializable { - - private static final long serialVersionUID = 6957195274696018630L; - /** - * 要检测的数据id 非必填 - * - * */ - @NotBlank(message = "dataId不能为空") - private String dataId; - - /** - * 文本内容 必填 最多不能超过10000 - */ - @NotBlank(message = "待检测文本不能为空") - @Length(max = 10000,message = "待检测文本最大为10000") - private String content; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceAsyncScanParam.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceAsyncScanParam.java deleted file mode 100644 index baa8e51be0..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceAsyncScanParam.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.epmet.openapi.scan.support.param; - -import lombok.Data; - -import javax.validation.Valid; -import javax.validation.constraints.NotEmpty; -import java.io.Serializable; -import java.util.List; - -/** - * 音频审查 入参 - * 参考文档:https://help.aliyun.com/document_detail/89630.html?spm=a2c4g.11186623.2.12.51a32dbfW6AdqV#reference-bcf-3nk-z2b - * @author yinzuomei@elink-cn.com - * @date 2020/12/9 9:07 - */ -@Data -public class VoiceAsyncScanParam implements Serializable { - private static final long serialVersionUID = 3408043673247901184L; - - /** - * 是否开启回调 - */ - private Boolean openCallBack; - - /** - * 不必填 - * 该字段用于标识您的业务场景。您可以通过内容安全控制台创建业务场景(具体操作,请参见自定义机审标准),或者提交工单联系我们帮助您创建业务场景。 - */ - private String bizType; - - /** - * 必填 - * 检测场景,取值:antispam。 - */ - private List scenes; - - /** - * 不必填 - * 是否为语音流(例如直播流)检测。取值: - * true:表示语音流检测。 - * false(默认):表示音频文件检测。 - */ - private Boolean live; - - /** - * 不必填 - * 是否为近线检测模式。 取值: - * true:表示近线检测模式。近线检测模式下,您提交的任务不保证能够实时处理,但是可以排队并在24小时内开始检测。 - * false(默认):表示实时检测模式。对于超过了并发路数限制的检测请求会直接拒绝。 - * 说明 该参数仅适用于音频文件检测,不适用于语音流检测。 - */ - private Boolean offline; - - /** - * 异步检测结果回调地址,执行异步审查内容时 必填 - */ - private String callback; - - /** - * 随机字符串,该值用于回调通知请求中的签名,使用callback时 必填 - */ - private String seed; - - @Valid - @NotEmpty(message = "任务列表不能为空") - private List tasks; - -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceTask.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceTask.java deleted file mode 100644 index 89f4333bba..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceTask.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.epmet.openapi.scan.support.param; - -import lombok.Data; - -import javax.validation.constraints.NotBlank; -import java.io.Serializable; - -/** - * 语音异步检测 对象 - * - * @author yinzuomei@elink-cn.com - * @date 2020/12/9 10:16 - */ -@Data -public class VoiceTask implements Serializable { - /** - * 不必填 - * 要检测的数据id 非必填 - * 检测对象对应的数据ID。 - * 由大小写英文字母、数字、下划线(_)、短划线(-)、英文句号(.)组成,不超过128个字符,可以用于唯一标识您的业务数据。 - * */ - @NotBlank(message = "dataId不能为空") - private String dataId; - - /** - * 必填 - * 需要检测的音频文件或语音流的下载地址。 - */ - @NotBlank(message = "音频URL不能为空") - private String url; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanParam.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanParam.java deleted file mode 100644 index c0315f8c17..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanParam.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.epmet.openapi.scan.support.param.video; - -import lombok.Data; - -import javax.validation.constraints.NotEmpty; -import java.io.Serializable; -import java.util.List; - -/** - * 视频审核-异步检测入参DTO - * - * @author yinzuomei@elink-cn.com - */ -@Data -public class VideoAsyncScanParam implements Serializable { - private static final long serialVersionUID = -7635290200099445362L; - - /** - * 是否开启回调 - */ - private Boolean openCallBack; - - /** - * 不必填 - * 该字段用于标识您的业务场景。您可以通过内容安全控制台创建业务场景(具体操作,请参见自定义机审标准),或者提交工单联系我们帮助您创建业务场景。 - */ - private String bizType; - - /** - * 不必填 - * 是否为语音流(例如直播流)检测。取值: - * true:表示语音流检测。 - * false(默认):表示音频文件检测。 - */ - private Boolean live; - - /** - * 不必填 - * 是否为近线检测模式。 取值: - * true:表示近线检测模式。近线检测模式下,您提交的任务不保证能够实时处理,但是可以排队并在24小时内开始检测。 - * false(默认):表示实时检测模式。对于超过了并发路数限制的检测请求会直接拒绝。 - * 说明 该参数仅适用于音频文件检测,不适用于语音流检测。 - */ - private Boolean offline; - - /** - * 必填 - * 指定视频检测场景。取值: - * porn:视频智能鉴黄 - * terrorism:视频暴恐涉政 - * live:视频不良场景 - * logo:视频logo - * ad:视频图文违规 - */ - private List scenes; - - /** - * 不必填 - * 指定视频语音检测场景,唯一取值:antispam,表示语音反垃圾。不传入该参数时仅检测视频图像内容;如果传入该参数,则在检测视频中图像的同时,对视频中语音进行检测。 - * 说明 如果需要检测视频语音,则不支持通过上传视频截帧序列的方式(即在task中传入frames)进行检测,您必须传入视频或视频流的URL地址(即在task中传入url)进行检测。 - */ - private List audioScenes; - - /** - * 异步检测结果回调地址,执行异步审查内容时 必填 - */ - private String callback; - - /** - * 随机字符串,该值用于回调通知请求中的签名,使用callback时 必填 - */ - private String seed; - - @NotEmpty(message = "检测对象不能为空") - private List tasks; -} \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanTask.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanTask.java deleted file mode 100644 index 38a4584d94..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanTask.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.epmet.openapi.scan.support.param.video; - -import lombok.Data; - -import javax.validation.constraints.NotBlank; -import java.io.Serializable; - -/** - * 视频审核-异步检测入参-检测对象 - * - * @author yinzuomei@elink-cn.com - */ -@Data -public class VideoAsyncScanTask implements Serializable { - /** - * 建议必填 - * 要检测的数据id 非必填 - * 检测对象对应的数据ID。 - * 由大小写英文字母、数字、下划线(_)、短划线(-)、英文句号(.)组成,不超过128个字符,可以用于唯一标识您的业务数据。 - * */ - @NotBlank(message = "dataId不能为空") - private String dataId; - - /** - * 必填 - * 待检测视频的URL。该字段不能和frames同时为空,也不能和frames同时有值。 - */ - @NotBlank(message = "音频URL不能为空") - private String url; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAsyncScanResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAsyncScanResult.java deleted file mode 100644 index d988cf7a88..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAsyncScanResult.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.epmet.openapi.scan.support.result; - -import lombok.Data; - -import java.util.List; - -/** - * 检测结果 - * - * @author jianjun liu - * @email liujianjun@yunzongnet.com - * @date 2020-06-05 10:52 - **/ -@Data -public class ImgAsyncScanResult { - /** - * 执行成功的任务Id集合 - */ - private List successTaskIds; - /** - * 执行失败的任务Id集合 - */ - private List failTaskIds; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ScanTaskResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ScanTaskResult.java deleted file mode 100644 index d358a570fa..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ScanTaskResult.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.epmet.openapi.scan.support.result; - -import lombok.Data; - -import java.io.Serializable; -import java.util.List; - -/** - * desc:文本检测返回结果 - * @author jianjun liu - * @email liujianjun@yunzongnet.com - * @date 2020-06-05 14:24 - **/ -@Data -public class ScanTaskResult implements Serializable { - - private static final long serialVersionUID = -7905091710384256911L; - private Integer code; - - - private String msg; - - - private String dataId; - - - private List results; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SceneDetailResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SceneDetailResult.java deleted file mode 100644 index 4023153d10..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SceneDetailResult.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.epmet.openapi.scan.support.result; - -import lombok.Data; - -/** - * desc:场景扫描结果 - * @author jianjun liu - * @date 2020-06-05 14:24 - **/ -@Data -public class SceneDetailResult { - /** - * 结果为该分类的概率 - */ - private Double rate; - - /** - * 建议用户执行的操作 - */ - private String suggestion; - - /** - * 场景 - */ - private String scene; - - /** - * 标签 - */ - private String label; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SyncScanResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SyncScanResult.java deleted file mode 100644 index 8dcb757f64..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SyncScanResult.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.epmet.openapi.scan.support.result; - -import lombok.Data; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -/** - * 检测结果 - * - * @author jianjun liu - * @date 2020-06-05 10:52 - **/ -@Data -public class SyncScanResult implements Serializable { - /** - * 执行成功的任务Id集合 - */ - private List successDataIds = new ArrayList<>(); - /** - * 执行失败的任务Id集合 - */ - private List failDataIds = new ArrayList<>(); - - /** - * desc:检测详情 - */ - private List details = new ArrayList<>(); - - /** - * 本地是否全部通过 - */ - private boolean isAllPass; - - public boolean isAllPass() { - if (failDataIds.isEmpty() && !successDataIds.isEmpty()) { - return true; - } - return isAllPass; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanDetailDTO.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanDetailDTO.java deleted file mode 100644 index 7e74caf5a6..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanDetailDTO.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.epmet.openapi.scan.support.result; - -import lombok.Data; - -import java.io.Serializable; - -/** - * 语音异步检测结果查询结果返参 -data-result-detail详情 - * 语音对应的文本详情。每一句文本对应一个元素,包含一个或者多个元素。关于每个元素的结构描述 - * - * @author yinzuomei@elink-cn.com - * @date 2020/12/9 11:11 - */ -@Data -public class VoiceAsyncScanDetailDTO implements Serializable { - private static final long serialVersionUID = -2664219492371705160L; - /** - * 句子开始的时间,单位:秒。 - */ - private Integer startTime; - - /** - * 句子结束的时间,单位:秒。 - */ - private Integer endTime; - - /** - * 语音转换成文本的结果。 - */ - private String text; - - /** - * 检测结果的分类。取值: - * normal:正常文本 - * spam:含垃圾信息 - * ad:广告 - * politics:涉政 - * terrorism:暴恐 - * abuse:辱骂 - * porn:色情 - * flood:灌水 - * contraband:违禁 - * meaningless:无意义 - * customized:自定义(例如命中自定义关键词) - */ - private String label; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResult.java deleted file mode 100644 index 1cbf3dab4a..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResult.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.epmet.openapi.scan.support.result; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import lombok.Data; - -import java.io.Serializable; -import java.util.List; - -/** - * 语音异步检测结果查询结果返参 - * - * @author yinzuomei@elink-cn.com - * @date 2020/12/9 10:56 - */ -@Data -public class VoiceAsyncScanResult implements Serializable { - private static final long serialVersionUID = 8702129292884498023L; - - /** - * 检测对象对应的数据ID。 - */ - private String dataId; - - /** - * 检测任务的ID - */ - private String taskId; - - /** - * 检测结果的分类。取值: - * normal:正常文本 - * spam:含垃圾信息 - * ad:广告 - * politics:涉政 - * terrorism:暴恐 - * abuse:辱骂 - * porn:色情 - * flood:灌水 - * contraband:违禁 - * meaningless:无意义 - * customized:自定义(例如命中自定义关键词) - */ - private String label; - - /** - * labelDesc是对label的说明,包含两种特殊说明: - * (1)如果检测任务失败labelDesc:智能检测任务失败,结果已失效,需要人工审核 - * (2)如果检测结果失效labelDesc:智能检测任务失败,需要人工审核 - */ - private String labelDesc; - - /** - * 建议您执行的后续操作。取值: - * pass:结果正常,无需进行其余操作。 - * review:结果不确定,需要进行人工审核。 - * block:结果违规,建议直接删除或者限制公开。 - */ - private String suggestion; - - - /** - * 错误码,和HTTP状态码一致。 - * 200:表示检测成功。 - * 280:表示处理中,需要继续轮询。 - * 其他:表示任务失败。 - * 更多信息,请参见公共错误码。 - */ - @JsonIgnore - private Integer code; - /** - * 错误描述信息。 - */ - @JsonIgnore - private String msg; - - /** - * 暂时没用,所以返回忽略 - */ - @JsonIgnore - private String url; - - /** - * 检测成功(code=200)时,返回的检测结果。该结果包含一个或多个元素,每个元素是个结构体,对应一个场景。关于每个元素的结构描述,请参见result。 - * 暂时不展示审核结果明细 - */ - @JsonIgnore - private List results; - -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResultDTO.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResultDTO.java deleted file mode 100644 index 34f3280a6f..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResultDTO.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.epmet.openapi.scan.support.result; - -import lombok.Data; - -import java.io.Serializable; -import java.util.List; - -/** - * 语音异步检测结果查询结果返参 -data-result详情 - * - * @author yinzuomei@elink-cn.com - * @date 2020/12/9 11:07 - */ -@Data -public class VoiceAsyncScanResultDTO implements Serializable { - private static final long serialVersionUID = 4602226363259983753L; - /** - * 检测场景,和调用请求中的场景对应。取值:antispam。 - */ - private String scene; - - /** - * 检测结果的分类。取值: - * normal:正常文本 - * spam:含垃圾信息 - * ad:广告 - * politics:涉政 - * terrorism:暴恐 - * abuse:辱骂 - * porn:色情 - * flood:灌水 - * contraband:违禁 - * meaningless:无意义 - * customized:自定义(例如命中自定义关键词) - */ - private String label; - - /** - * 建议您执行的后续操作。取值: - * pass:结果正常,无需进行其余操作。 - * review:结果不确定,需要进行人工审核。 - * block:结果违规,建议直接删除或者限制公开。 - */ - private String suggestion; - - /** - * 置信度分数,取值范围:0(表示置信度最低)~100(表示置信度最高)。 - * 如果suggestion为pass,则置信度越高,表示内容正常的可能性越高;如果suggestion为review或block,则置信度越高,表示内容违规的可能性越高。 - * 注意 该值仅作为参考,强烈建议您不要在业务中使用。建议您参考suggestion和label(或者部分接口返回的sublabel)结果用于内容违规判定。 - */ - private Float rate; - - /** - * 语音对应的文本详情。每一句文本对应一个元素,包含一个或者多个元素。关于每个元素的结构描述, - */ - private List details; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskDataDTO.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskDataDTO.java deleted file mode 100644 index ce43fec932..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskDataDTO.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.epmet.openapi.scan.support.result; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import lombok.Data; - -import java.io.Serializable; - -/** - * 语音异步检测,返回检测对象列表 - * - * @author yinzuomei@elink-cn.com - * @date 2020/12/9 16:38 - */ -@Data -public class VoiceAsyncScanTaskDataDTO implements Serializable { - /** - * 错误码,和HTTP状态码一致。 - * 更多信息,请参见公共错误码。 - */ - private Integer code; - /** - * 错误描述信息。 - */ - private String msg; - /** - * 检测对象对应的数据ID。 - */ - private String dataId; - - /** - * 检测任务的ID - */ - private String taskId; - - /** - * 暂时没用,所以返回忽略 - */ - @JsonIgnore - private String url; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskResult.java deleted file mode 100644 index 2dcbecc398..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskResult.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.epmet.openapi.scan.support.result; - -import lombok.Data; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -/** - * 语音异步检测,返参 - * - * @author yinzuomei@elink-cn.com - * @date 2020/12/9 9:23 - */ -@Data -public class VoiceAsyncScanTaskResult implements Serializable { - private static final long serialVersionUID = 8702129292884498023L; - /** - * 随机字符串,该值用于回调通知请求中的签名。 - */ - private String seed; - - /** - * 提交成功的失败对象 - */ - private List successTasks=new ArrayList<>(); - - /** - * 提交失败的检测对象 - */ - private List failTasks=new ArrayList<>(); - - /** - * 是否全部提交成功 - */ - private boolean isAllSuccess; - - public boolean isAllSuccess() { - if (failTasks.isEmpty() && !successTasks.isEmpty()) { - return true; - } - return isAllSuccess; - } - - -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskDataDTO.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskDataDTO.java deleted file mode 100644 index 1d559a31cd..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskDataDTO.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.epmet.openapi.scan.support.result.video; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import lombok.Data; - -import java.io.Serializable; - -/** - * 视频审核-异步检测任务提交返参详情 - * - * @author yinzuomei@elink-cn.com - * @date 2020/12/29 13:42 - */ -@Data -public class VideoAsyncScanTaskDataDTO implements Serializable { - private static final long serialVersionUID = 8430710131685814181L; - /** - * 错误码,和HTTP状态码一致。 - * 更多信息,请参见公共错误码。 - */ - private Integer code; - /** - * 错误描述信息。 - */ - private String msg; - /** - * 检测对象对应的数据ID。 - */ - private String dataId; - - /** - * 检测任务的ID - */ - private String taskId; - - /** - * 暂时没用,所以返回忽略 - */ - @JsonIgnore - private String url; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskResultDTO.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskResultDTO.java deleted file mode 100644 index 75ecd6e84f..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskResultDTO.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.epmet.openapi.scan.support.result.video; - -import lombok.Data; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -/** - * 视频审核-异步检测任务提交返参 - * - * @author yinzuomei@elink-cn.com - * @date 2020/12/29 13:38 - */ -@Data -public class VideoAsyncScanTaskResultDTO implements Serializable { - private static final long serialVersionUID = -467990806428860191L; - - /** - * 随机字符串,该值用于回调通知请求中的签名。 - */ - private String seed; - - /** - * 提交成功的失败对象 - */ - private List successTasks=new ArrayList<>(); - - /** - * 提交失败的检测对象 - */ - private List failTasks=new ArrayList<>(); - - /** - * 是否全部提交成功 - */ - private Boolean isAllSuccess; - - public boolean isAllSuccess() { - if (failTasks.isEmpty() && !successTasks.isEmpty()) { - return true; - } - return isAllSuccess; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoResultDTO.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoResultDTO.java deleted file mode 100644 index 0e781bf463..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoResultDTO.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.epmet.openapi.scan.support.result.video; - -import lombok.Data; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -/** - * 视频异步检测结果查询接口返参 - * 正在检测中的不返回,调用方继续轮询查询结果 - * @author yinzuomei@elink-cn.com - * @date 2020/12/29 15:37 - */ -@Data -public class VideoResultDTO implements Serializable { - private static final long serialVersionUID = -3451342817149956488L; - - /** - * 执行成功的任务Id集合 - * code=200,且所有语音+视频所有场景返回结果都为pass时则为成功 - */ - private List passDataIds = new ArrayList<>(); - /** - * 执行失败的任务Id集合 - */ - private List noPassDataIds = new ArrayList<>(); - - private List passTaskIds = new ArrayList<>(); - private List noPassTaskIds = new ArrayList<>(); - - /** - * desc:阿里内容审核API返回结果详情 - */ - private List details = new ArrayList<>(); - - /** - * 本地是否全部通过 - */ - private Boolean isAllPass; - - public boolean isAllPass() { - if (noPassTaskIds.isEmpty() && !passTaskIds.isEmpty()) { - return true; - } - return isAllPass; - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginDetail.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginDetail.java deleted file mode 100644 index 78916c1fe6..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginDetail.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.epmet.openapi.scan.support.result.video; - -import lombok.Data; - -import java.io.Serializable; - -/** - * 视频异步检测结果查询接口原生返参-视频检测结果 - * - * @author yinzuomei@elink-cn.com - * @date 2020/12/29 16:39 - */ -@Data -public class VideoScanOriginDetail implements Serializable { - private static final long serialVersionUID = 5547706236158849091L; - /** - * 视频检测场景,和调用请求中的场景对应。取值: - * porn:视频智能鉴黄 - * terrorism:视频暴恐涉政 - * live:视频不良场景 - * logo:视频logo - * ad:视频图文违规 - */ - private String scene; - - /** - * 视频检测结果的分类。不同检测场景的结果分类不同,具体如下: - * 视频智能鉴黄(porn)结果分类: - * normal:正常 - * porn:色情 - * 视频暴恐涉政(terrorism)结果分类: - * normal:正常 - * terrorism:暴恐涉政 - * 视频不良场景(live)结果分类: - * normal:正常 - * live:包含不良场景 - * 视频logo(logo)结果分类: - * normal:正常 - * logo:包含logo - * 视频图文违规(ad)结果分类: - * normal:正常 - * ad:包含广告或文字违规信息 - */ - private String label; - - /** - * 建议您执行的后续操作。取值: - * pass:结果正常,无需进行其余操作。 - * review:结果不确定,需要进行人工审核。 - * block:结果违规,建议直接删除或者限制公开。 - */ - private String suggestion; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginalResultDTO.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginalResultDTO.java deleted file mode 100644 index 8964d5fe00..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginalResultDTO.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.epmet.openapi.scan.support.result.video; - -import com.epmet.openapi.scan.support.result.VoiceAsyncScanResultDTO; -import lombok.Data; - -import java.io.Serializable; -import java.util.List; - -/** - * 视频异步检测结果查询接口原生返参 - * - * @author yinzuomei@elink-cn.com - * @date 2020/12/29 15:48 - */ -@Data -public class VideoScanOriginalResultDTO implements Serializable { - private static final long serialVersionUID = -1565008507757551616L; - - /** - * 错误码,和HTTP状态码一致。 - * 更多信息,请参见公共错误码。 - */ - private Integer code; - - private String codeDesc; - - /** - * 错误描述信息。 - */ - private String msg; - /** - * 检测对象对应的数据ID。 - */ - private String dataId; - - /** - * 检测任务的ID - */ - private String taskId; - - /** - * 返回结果,调用成功时(code=200),返回结果中包含一个或多个元素。每个元素是个结构体,具体结构描述,请参见result。 - * 说明 视频流检测场景中,code返回280表示在检测中,返回200表示检测完成。在检测中状态时,检测结果中包含从开始检测到当前时间的检测到结果。 - */ - private List results; - - /** - * 视频语音检测结果。具体结构描述,请参见audioScanResult。 - */ - private List audioScanResults; -} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/resources/bootstrap.yml b/epmet-openapi/epmet-openapi-scan/src/main/resources/bootstrap.yml deleted file mode 100644 index 0aa0583c97..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/resources/bootstrap.yml +++ /dev/null @@ -1,91 +0,0 @@ -server: - port: @server.port@ - version: @version@ - servlet: - context-path: /epmetscan - -spring: - main: - allow-bean-definition-overriding: true - application: - name: epmet-openapi-scan - #环境 dev|test|prod - profiles: - active: @spring.profiles.active@ - messages: - encoding: UTF-8 - basename: i18n/messages_common - jackson: - time-zone: GMT+8 - date-format: yyyy-MM-dd HH:mm:ss - redis: - database: @spring.redis.index@ - host: @spring.redis.host@ - port: @spring.redis.port@ - password: @spring.redis.password@ - timeout: 30s - cloud: - nacos: - discovery: - server-addr: @nacos.server-addr@ - #nacos的命名空间ID,默认是public - namespace: @nacos.discovery.namespace@ - #不把自己注册到注册中心的地址 - register-enabled: @nacos.register-enabled@ - ip: @nacos.ip@ - config: - enabled: @nacos.config-enabled@ - server-addr: @nacos.server-addr@ - namespace: @nacos.config.namespace@ - group: @nacos.config.group@ - file-extension: yaml -management: - endpoints: - web: - exposure: - include: "*" - endpoint: - health: - show-details: ALWAYS - -feign: - hystrix: - enabled: true - client: - config: - default: - loggerLevel: BASIC - okhttp: - enabled: true - - -hystrix: - command: - default: - execution: - isolation: - thread: - timeoutInMilliseconds: 60000 #缺省为1000 - -ribbon: - ReadTimeout: 300000 - ConnectTimeout: 300000 - -aliyun: - green: - accessKeyId: LTAI4G6Fv6uTzQbpsayATHq4 - accessKeySecret: QevMw1RYCwQUG3RSMPq1J6EAfmSblo - regionId: cn-shanghai - bizType: epmet_img_text - -dingTalk: - robot: - webHook: @dingTalk.robot.webHook@ - secret: @dingTalk.robot.secret@ - -# 停机选项 -shutdown: - graceful: - enable: true #是否开启优雅停机 - waitTimeSecs: 30 # 优雅停机等待时间,超过30秒,发出告警 - diff --git a/epmet-openapi/epmet-openapi-scan/src/main/resources/logback-spring.xml b/epmet-openapi/epmet-openapi-scan/src/main/resources/logback-spring.xml deleted file mode 100644 index 9d2ad51e14..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,169 +0,0 @@ - - - - - - - - - - - - ${appname} - - - - - - - - - debug - - - ${CONSOLE_LOG_PATTERN} - - UTF-8 - - - - - - - - ${log.path}/debug.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - - ${log.path}/debug-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 15 - - - - debug - ACCEPT - DENY - - - - - - - ${log.path}/info.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - - ${log.path}/info-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 15 - - - - info - ACCEPT - DENY - - - - - - - ${log.path}/warn.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - ${log.path}/warn-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 15 - - - - warn - ACCEPT - DENY - - - - - - - ${log.path}/error.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - ${log.path}/error-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 15 - - - - ERROR - ACCEPT - DENY - ${webHook} - ${secret} - ${appname} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/epmet-openapi/epmet-openapi-scan/src/main/resources/readme b/epmet-openapi/epmet-openapi-scan/src/main/resources/readme deleted file mode 100644 index 384fca6dfc..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/main/resources/readme +++ /dev/null @@ -1,7 +0,0 @@ -#访问openApi 需要向redis中 添加白名单 -sadd epmet:openapi:scan:whitelist "客户端ip地址" -#eg: -sadd epmet:openapi:scan:whitelist "\"192.168.1.1\"" - -#del -srem 'epmet:openapi:scan:whitelist' "\"116.179.32.197\"" "\"27.219.156.47\"" \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/src/test/java/BaseSample.java b/epmet-openapi/epmet-openapi-scan/src/test/java/BaseSample.java deleted file mode 100644 index 8c0774030d..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/test/java/BaseSample.java +++ /dev/null @@ -1,50 +0,0 @@ -import java.io.IOException; -import java.util.Properties; - -/** - * Created by liuhai.lh on 17/01/12. - */ -public class BaseSample { - - protected static String accessKeyId = "123"; - protected static String accessKeySecret = "456"; - - protected static String regionId = "cn-shanghai"; - - static { - Properties properties = new Properties(); - - try { - properties.load(BaseSample.class.getResourceAsStream("bootstrap.yml")); - accessKeyId = properties.getProperty("aliyun.green.accessKeyId"); - accessKeySecret = properties.getProperty("aliyun.green.accessKeySecret"); - regionId = properties.getProperty("aliyun.green.url"); - } catch(IOException e) { - e.printStackTrace(); - } - - } - protected static String getDomain(){ - if("cn-shanghai".equals(regionId)){ - return "green.cn-shanghai.aliyuncs.com"; - } - - if ("cn-beijing".equals(regionId)) { - return "green.cn-beijing.aliyuncs.com"; - } - - if ("ap-southeast-1".equals(regionId)) { - return "green.ap-southeast-1.aliyuncs.com"; - } - - if ("us-west-1".equals(regionId)) { - return "green.us-west-1.aliyuncs.com"; - } - - return "green.cn-shanghai.aliyuncs.com"; - } - protected static String getEndPointName(){ - return regionId; - } - -} diff --git a/epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanRequestSample.java b/epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanRequestSample.java deleted file mode 100644 index acba42e763..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanRequestSample.java +++ /dev/null @@ -1,95 +0,0 @@ -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.aliyuncs.DefaultAcsClient; -import com.aliyuncs.IAcsClient; -import com.aliyuncs.exceptions.ClientException; -import com.aliyuncs.exceptions.ServerException; -import com.aliyuncs.green.model.v20180509.ImageAsyncScanRequest; -import com.aliyuncs.http.FormatType; -import com.aliyuncs.http.HttpResponse; -import com.aliyuncs.profile.DefaultProfile; -import com.aliyuncs.profile.IClientProfile; -import com.epmet.openapi.scan.common.enu.RegionIdEnum; - -import java.util.*; - -/** - * Created by liuhai.lh on 2017/2/17. - * 图片异步检测接口 - * @author liuhai.lh - * @date 2017/02/17 - */ -public class ImageAsyncScanRequestSample extends BaseSample{ - - public static void main(String[] args) throws Exception { - //请替换成你自己的accessKeyId、accessKeySecret - IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret); - DefaultProfile.addEndpoint(getEndPointName(), regionId, "Green", RegionIdEnum.getDoMain(regionId)); - IAcsClient client = new DefaultAcsClient(profile); - - ImageAsyncScanRequest imageAsyncScanRequest = new ImageAsyncScanRequest(); - imageAsyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式 - imageAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法 - imageAsyncScanRequest.setEncoding("utf-8"); - imageAsyncScanRequest.setRegionId(regionId); - - - List> tasks = new ArrayList>(); - Map task1 = new LinkedHashMap(); - task1.put("dataId", UUID.randomUUID().toString()); - task1.put("url", "https://img.alicdn.com/tfs/TB1Xk_qvwmTBuNjy1XbXXaMrVXa-550-407.jpg"); - task1.put("time", new Date()); - - tasks.add(task1); - JSONObject data = new JSONObject(); - /** - * porn: 色情 - * terrorism: 暴恐 - * qrcode: 二维码 - * ad: 图片广告 - * ocr: 文字识别 - */ - data.put("scenes", Arrays.asList("porn", "ocr", "qrcode", "sface")); - data.put("tasks", tasks); - - imageAsyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON); - - /** - * 请务必设置超时时间 - */ - imageAsyncScanRequest.setConnectTimeout(3000); - imageAsyncScanRequest.setReadTimeout(6000); - - try { - HttpResponse httpResponse = client.doAction(imageAsyncScanRequest); - - if(httpResponse.isSuccess()){ - JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); - System.out.println(JSON.toJSONString(scrResponse, true)); - if (200 == scrResponse.getInteger("code")) { - JSONArray taskResults = scrResponse.getJSONArray("data"); - for (Object taskResult : taskResults) { - if(200 == ((JSONObject)taskResult).getInteger("code")){ - String taskId = ((JSONObject)taskResult).getString("taskId"); - // 将taskId 保存下来,间隔一段时间来轮询结果, 参照ImageAsyncScanResultsRequest - System.out.println("args = [" + taskId + "]"); - }else{ - System.out.println("task process fail:" + ((JSONObject)taskResult).getInteger("code")); - } - } - } else { - System.out.println("detect not success. code:" + scrResponse.getInteger("code")); - } - }else{ - System.out.println("response not success. status:" + httpResponse.getStatus()); - } - } catch (ServerException e) { - e.printStackTrace(); - } catch (ClientException e) { - e.printStackTrace(); - } catch (Exception e){ - e.printStackTrace(); - } - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanResultsSample.java b/epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanResultsSample.java deleted file mode 100644 index 27e0b6e233..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanResultsSample.java +++ /dev/null @@ -1,83 +0,0 @@ -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.aliyuncs.DefaultAcsClient; -import com.aliyuncs.IAcsClient; -import com.aliyuncs.exceptions.ClientException; -import com.aliyuncs.exceptions.ServerException; -import com.aliyuncs.green.model.v20180509.ImageAsyncScanResultsRequest; -import com.aliyuncs.http.FormatType; -import com.aliyuncs.http.HttpResponse; -import com.aliyuncs.profile.DefaultProfile; -import com.aliyuncs.profile.IClientProfile; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created by liuhai.lh on 2017/2/17. - * 获取图片异步检测结果接口 - * @author liuhai.lh - * @date 2017/02/17 - */ -public class ImageAsyncScanResultsSample extends BaseSample{ - - public static void main(String[] args) throws Exception { - //请替换成你自己的accessKeyId、accessKeySecret - IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret); - DefaultProfile.addEndpoint(getEndPointName(), regionId, "Green", getDomain()); - IAcsClient client = new DefaultAcsClient(profile); - - ImageAsyncScanResultsRequest imageAsyncScanResultsRequest = new ImageAsyncScanResultsRequest(); - imageAsyncScanResultsRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式 - imageAsyncScanResultsRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法 - imageAsyncScanResultsRequest.setEncoding("utf-8"); - imageAsyncScanResultsRequest.setRegionId(regionId); - - - List taskIds = new ArrayList(); - taskIds.add("img1hdP5Wn0QC@7wW0n$VX0R@-1p3mnZ"); - imageAsyncScanResultsRequest.setHttpContent(JSON.toJSONString(taskIds).getBytes("UTF-8"), "UTF-8", FormatType.JSON); - - /** - * 请务必设置超时时间 - */ - imageAsyncScanResultsRequest.setConnectTimeout(3000); - imageAsyncScanResultsRequest.setReadTimeout(6000); - - try { - HttpResponse httpResponse = client.doAction(imageAsyncScanResultsRequest); - - if(httpResponse.isSuccess()){ - JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); - System.out.println(JSON.toJSONString(scrResponse, true)); - if (200 == scrResponse.getInteger("code")) { - JSONArray taskResults = scrResponse.getJSONArray("data"); - for (Object taskResult : taskResults) { - if(200 == ((JSONObject)taskResult).getInteger("code")){ - JSONArray sceneResults = ((JSONObject)taskResult).getJSONArray("results"); - for (Object sceneResult : sceneResults) { - String scene = ((JSONObject)sceneResult).getString("scene"); - String suggestion = ((JSONObject)sceneResult).getString("suggestion"); - //根据scene和suggetion做相关的处理 - //do something - } - }else{ - System.out.println("task process fail:" + ((JSONObject)taskResult).getInteger("code")); - } - } - } else { - System.out.println("detect not success. code:" + scrResponse.getInteger("code")); - } - }else{ - System.out.println("response not success. status:" + httpResponse.getStatus()); - } - } catch (ServerException e) { - e.printStackTrace(); - } catch (ClientException e) { - e.printStackTrace(); - } catch (Exception e){ - e.printStackTrace(); - } - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/test/java/ImageSyncScanRequestSample.java b/epmet-openapi/epmet-openapi-scan/src/test/java/ImageSyncScanRequestSample.java deleted file mode 100644 index ec418154d9..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/test/java/ImageSyncScanRequestSample.java +++ /dev/null @@ -1,101 +0,0 @@ -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.aliyuncs.DefaultAcsClient; -import com.aliyuncs.IAcsClient; -import com.aliyuncs.exceptions.ClientException; -import com.aliyuncs.exceptions.ServerException; -import com.aliyuncs.green.model.v20180509.ImageSyncScanRequest; -import com.aliyuncs.http.FormatType; -import com.aliyuncs.http.HttpResponse; -import com.aliyuncs.profile.DefaultProfile; -import com.aliyuncs.profile.IClientProfile; - -import java.util.*; - -/** - * Created by liuhai.lh on 2017/2/17. - * 图片同步检测接口 - * @author liuhai.lh - * @date 2017/02/17 - */ -public class ImageSyncScanRequestSample extends BaseSample { - - - public static void main(String[] args) throws Exception { - //请替换成你自己的accessKeyId、accessKeySecret - IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret); - DefaultProfile.addEndpoint(getEndPointName(), regionId, "Green", getDomain()); - IAcsClient client = new DefaultAcsClient(profile); - - ImageSyncScanRequest imageSyncScanRequest = new ImageSyncScanRequest(); - imageSyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式 - imageSyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法 - imageSyncScanRequest.setEncoding("utf-8"); - imageSyncScanRequest.setRegionId(regionId); - - - List> tasks = new ArrayList>(); - Map task = new LinkedHashMap(); - task.put("dataId", UUID.randomUUID().toString()); - task.put("url", "http://f.hiphotos.baidu.com/image/pic/item/aa18972bd40735fa13899ac392510fb30f24084b.jpg"); - task.put("time", new Date()); - - tasks.add(task); - JSONObject data = new JSONObject(); - /** - * porn: 色情 - * terrorism: 暴恐 - * qrcode: 二维码 - * ad: 图片广告 - * ocr: 文字识别 - */ - data.put("scenes", Arrays.asList("porn","terrorism")); - data.put("tasks", tasks); - - imageSyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON); - - /** - * 请务必设置超时时间 - */ - imageSyncScanRequest.setConnectTimeout(3000); - imageSyncScanRequest.setReadTimeout(10000); - - try { - HttpResponse httpResponse = client.doAction(imageSyncScanRequest); - - if (httpResponse.isSuccess()) { - JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); - System.out.println(JSON.toJSONString(scrResponse, true)); - if (200 == scrResponse.getInteger("code")) { - JSONArray taskResults = scrResponse.getJSONArray("data"); - for (Object taskResult : taskResults) { - if(200 == ((JSONObject)taskResult).getInteger("code")){ - JSONArray sceneResults = ((JSONObject)taskResult).getJSONArray("results"); - for (Object sceneResult : sceneResults) { - String scene = ((JSONObject)sceneResult).getString("scene"); - String suggestion = ((JSONObject)sceneResult).getString("suggestion"); - //根据scene和suggetion做相关的处理 - //do something - System.out.println("args = [" + scene + "]"); - System.out.println("args = [" + suggestion + "]"); - } - }else{ - System.out.println("task process fail:" + ((JSONObject)taskResult).getInteger("code")); - } - } - } else { - System.out.println("detect not success. code:" + scrResponse.getInteger("code")); - } - } else { - System.out.println("response not success. status:" + httpResponse.getStatus()); - } - } catch (ServerException e) { - e.printStackTrace(); - } catch (ClientException e) { - e.printStackTrace(); - } catch (Exception e){ - e.printStackTrace(); - } - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanRequestSample.java b/epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanRequestSample.java deleted file mode 100644 index 617e6246d1..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanRequestSample.java +++ /dev/null @@ -1,90 +0,0 @@ -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.aliyuncs.DefaultAcsClient; -import com.aliyuncs.IAcsClient; -import com.aliyuncs.green.model.v20180509.VoiceAsyncScanRequest; -import com.aliyuncs.http.FormatType; -import com.aliyuncs.http.HttpResponse; -import com.aliyuncs.profile.DefaultProfile; -import com.aliyuncs.profile.IClientProfile; - -import java.util.*; - -/** - * 提交语音异步检测任务 demo - * - * @author yinzuomei@elink-cn.com - * @date 2020/12/8 21:51 - */ -public class VoiceAsyncScanRequestSample extends BaseSample { - - - - public static void main(String[] args) throws Exception { - - //请替换成您自己的AccessKey ID、AccessKey Secret。 - IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", - "LTAI4G6Fv6uTzQbpsayATHq4", //您自己的AccessKey ID - "QevMw1RYCwQUG3RSMPq1J6EAfmSblo");//您自己的AccessKey Secret - final IAcsClient client = new DefaultAcsClient(profile); - - VoiceAsyncScanRequest asyncScanRequest = new VoiceAsyncScanRequest(); //class different vs common - asyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定API返回格式。 - asyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法。 - asyncScanRequest.setRegionId("cn-shanghai"); - asyncScanRequest.setConnectTimeout(3000); - asyncScanRequest.setReadTimeout(6000); - - List> tasks = new ArrayList>(); - Map task1 = new LinkedHashMap(); - // 请将下面的地址修改为要检测的语音文件的地址。 - task1.put("dataId","voice1"); - task1.put("url", "https://elink-esua-epdc.oss-cn-qingdao.aliyuncs.com/epmet/test/20201208/6480bd6be9f14a458162218cea84dfa5.aac"); - - Map task2 = new LinkedHashMap(); - task2.put("dataId","voice2"); - task2.put("url", "https://elink-esua-epdc.oss-cn-qingdao.aliyuncs.com/epmet/test/20201208/b566d94fd7114ffb9a203e80c22ebb96.aac"); - - tasks.add(task1); - tasks.add(task2); - - JSONObject data = new JSONObject(); - - System.out.println("==========Task count:" + tasks.size()); - data.put("scenes", Arrays.asList("antispam")); - data.put("tasks", tasks); - // 如果是语音流检测,则修改为true。 - data.put("live", false); - asyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON); - System.out.println("接口入参:"+JSON.toJSONString(data, true)); - - try { - HttpResponse httpResponse = client.doAction(asyncScanRequest); - - if (httpResponse.isSuccess()) { - JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); - System.out.println("接口返参:"+JSON.toJSONString(scrResponse, true)); - if (200 == scrResponse.getInteger("code")) { - JSONArray taskResults = scrResponse.getJSONArray("data"); - for (Object taskResult : taskResults) { - Integer code = ((JSONObject) taskResult).getInteger("code"); - if (200 == code) { - final String taskId = ((JSONObject) taskResult).getString("taskId"); - System.out.println("submit async task success, taskId = [" + taskId + "]"); - } else { - System.out.println("task process fail: " + code); - } - } - } else { - System.out.println("detect not success. code: " + scrResponse.getInteger("code")); - } - } else { - System.out.println("response not success. status: " + httpResponse.getStatus()); - } - } catch (Exception e) { - e.printStackTrace(); - } - - } -} diff --git a/epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanResultsRequestSample.java b/epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanResultsRequestSample.java deleted file mode 100644 index 85d268f175..0000000000 --- a/epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanResultsRequestSample.java +++ /dev/null @@ -1,113 +0,0 @@ -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.aliyuncs.DefaultAcsClient; -import com.aliyuncs.IAcsClient; -import com.aliyuncs.green.model.v20180509.VoiceAsyncScanResultsRequest; -import com.aliyuncs.http.FormatType; -import com.aliyuncs.http.HttpResponse; -import com.aliyuncs.profile.DefaultProfile; -import com.aliyuncs.profile.IClientProfile; - -import java.util.*; - -/** - * 查询异步语音检测结果。 - * - * @author yinzuomei@elink-cn.com - * @date 2020/12/8 22:08 - */ -public class VoiceAsyncScanResultsRequestSample extends BaseSample { - - - public static void main(String[] args) throws Exception { - // 请替换成您自己的AccessKey ID、AccessKey Secret。 - IClientProfile profile = DefaultProfile - .getProfile("cn-shanghai", - "LTAI4G6Fv6uTzQbpsayATHq4", - "QevMw1RYCwQUG3RSMPq1J6EAfmSblo"); - final IAcsClient client = new DefaultAcsClient(profile); - //提交语音异步检测任务后返回的taskId - pollingScanResult(client, Arrays.asList("vc_f_7WZZ01BCH0q6ZnM3g1OKGG-1tAaZ7", "vc_f_6AKaBxy4HdG5bruQ0JwweV-1tAaJi")); - // pollingScanResult(client, "vc_f_6AKaBxy4HdG5bruQ0JwweV-1tAaJi"); - } - - public static void pollingScanResult(IAcsClient client, List taskIdList) throws InterruptedException { - int failCount = 0; - boolean stop = false; - do { - // 设置每10秒查询一次。 - Thread.sleep(10 * 1000); - JSONObject scanResult = getScanResult(client, taskIdList); - System.out.println("接口完整返参:"+JSON.toJSONString(scanResult, true)); - if (scanResult == null || 200 != scanResult.getInteger("code")) { - failCount++; - System.out.println("请求失败,get result fail, failCount=" + failCount); - if (scanResult != null) { - System.out.println("请求失败,错误信息errorMsg:" + scanResult.getString("msg")); - } - if (failCount > 20) { - break; - } - continue; - } - - JSONArray taskResults = scanResult.getJSONArray("data"); - if (taskResults.isEmpty()) { - System.out.println("请求成功,but data is empty"); - break; - } - System.out.println("data.size=" + taskResults.size()); - for (Object taskResult : taskResults) { - JSONObject result = (JSONObject) taskResult; - Integer code = result.getInteger("code"); - String taskId = result.getString("taskId"); - if (280 == code) { - System.out.println("taskId=" + taskId + ": processing status: " + result.getString("msg")); - } else if (200 == code) { - System.out.println("taskId=" + taskId + "请求成功,返参:" + JSON.toJSONString(taskResult, true)); - stop = true; - } else { - System.out.println("taskId=" + taskId + "请求失败,返参:" + JSON.toJSONString(taskResult, true)); - stop = true; - } - } - } while (!stop); - } - - private static JSONObject getScanResult(IAcsClient client, List taskIdList) { - VoiceAsyncScanResultsRequest getResultsRequest = new VoiceAsyncScanResultsRequest(); - getResultsRequest.setAcceptFormat(FormatType.JSON); // 指定API返回格式。 - getResultsRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法。 - getResultsRequest.setEncoding("utf-8"); - getResultsRequest.setRegionId("cn-shanghai"); - - - List> tasks = new ArrayList>(); - for (String taskId : taskIdList) { - Map task1 = new LinkedHashMap(); - task1.put("taskId", taskId); - tasks.add(task1); - } - - /** - * 请务必设置超时时间。 - */ - getResultsRequest.setConnectTimeout(3000); - getResultsRequest.setReadTimeout(6000); - - try { - getResultsRequest.setHttpContent(JSON.toJSONString(tasks).getBytes("UTF-8"), "UTF-8", FormatType.JSON); - - HttpResponse httpResponse = client.doAction(getResultsRequest); - if (httpResponse.isSuccess()) { - return JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); - } else { - System.out.println("response not success. status: " + httpResponse.getStatus()); - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } -} diff --git a/epmet-openapi/pom.xml b/epmet-openapi/pom.xml deleted file mode 100644 index fd15705343..0000000000 --- a/epmet-openapi/pom.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - epmet-cloud - com.epmet - 2.0.0 - - 4.0.0 - pom - - epmet-openapi - - epmet-openapi-scan - epmet-openapi-adv - - - \ No newline at end of file From 8de86b07164ed870463a92c08a19782cf3041b3a Mon Sep 17 00:00:00 2001 From: wxz Date: Fri, 26 Mar 2021 00:55:31 +0800 Subject: [PATCH 10/18] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=AE=8C=E4=BA=86openA?= =?UTF-8?q?pi=E5=8F=82=E6=95=B0=E6=A8=A1=E5=BC=8F=EF=BC=8C=E5=BE=85?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/openapi/HeaderFieldKeys.java | 7 ---- .../epmet/openapi/RequestBodyFieldKeys.java | 10 ----- .../com/epmet/openapi/RequestParamKeys.java | 11 ----- .../com/epmet/openapi/constant/AuthTypes.java | 8 ++++ .../openapi/constant/InClusterHeaderKeys.java | 10 +++++ .../openapi/constant/RequestParamKeys.java | 14 +++++++ .../sign/openapi/OpenApiSignUtils.java | 15 +++++-- epmet-gateway/pom.xml | 13 ++++-- .../auth/ExtAppFetchTokenAuthProcessor.java | 16 +++----- .../com/epmet/auth/ExternalAuthProcessor.java | 22 ++++++---- .../filter/CpAuthGatewayFilterFactory.java | 6 ++- .../common-service-server/pom.xml | 6 +-- .../epmet/dto/form/AccessTokenFormDTO.java | 14 ------- .../epmet-ext/epmet-ext-server/pom.xml | 11 +++-- .../aspect/OpenApiRequestCheckAspect.java | 41 +++++++++++++------ .../OpenApiAccessTokenController.java | 23 ++--------- .../impl/OpenApiAccessTokenServiceImpl.java | 2 +- 17 files changed, 121 insertions(+), 108 deletions(-) delete mode 100644 epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/HeaderFieldKeys.java delete mode 100644 epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/RequestBodyFieldKeys.java delete mode 100644 epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/RequestParamKeys.java create mode 100644 epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/AuthTypes.java create mode 100644 epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/InClusterHeaderKeys.java create mode 100644 epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/RequestParamKeys.java delete mode 100644 epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/AccessTokenFormDTO.java diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/HeaderFieldKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/HeaderFieldKeys.java deleted file mode 100644 index 9360c5f51f..0000000000 --- a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/HeaderFieldKeys.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.epmet.openapi; - -public interface HeaderFieldKeys { - - String APP_ID = "AppId"; - -} diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/RequestBodyFieldKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/RequestBodyFieldKeys.java deleted file mode 100644 index 3ce4555283..0000000000 --- a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/RequestBodyFieldKeys.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.epmet.openapi; - -/** - * 请求体字段key - */ -public interface RequestBodyFieldKeys { - - String APP_ID = "appId"; - -} diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/RequestParamKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/RequestParamKeys.java deleted file mode 100644 index a503713682..0000000000 --- a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/RequestParamKeys.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.epmet.openapi; - -/** - * url请求参数key - */ -public class RequestParamKeys { - - public static String APP_ID = "app_id"; - public static String AUTH_TYPE = "auth_type"; - -} diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/AuthTypes.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/AuthTypes.java new file mode 100644 index 0000000000..4f1c94af10 --- /dev/null +++ b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/AuthTypes.java @@ -0,0 +1,8 @@ +package com.epmet.openapi.constant; + +/** + * 认证方式 + */ +public interface AuthTypes { + String TAKE_TOKEN = "take_token"; +} diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/InClusterHeaderKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/InClusterHeaderKeys.java new file mode 100644 index 0000000000..e2d0b2ca18 --- /dev/null +++ b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/InClusterHeaderKeys.java @@ -0,0 +1,10 @@ +package com.epmet.openapi.constant; + +/** + * 集群内的Header key + */ +public interface InClusterHeaderKeys { + + String APP_ID = "AppId"; + +} diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/RequestParamKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/RequestParamKeys.java new file mode 100644 index 0000000000..b1d6bae806 --- /dev/null +++ b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/RequestParamKeys.java @@ -0,0 +1,14 @@ +package com.epmet.openapi.constant; + +/** + * url请求参数key + */ +public class RequestParamKeys { + + public static String APP_ID = "app_id"; + public static String AUTH_TYPE = "auth_type"; + public static String TIMESTAMP = "timestamp"; + public static String SIGN = "sign"; + public static String NONCE = "nonce"; + +} diff --git a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java index 9a64226174..785c2a0578 100644 --- a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java +++ b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java @@ -17,7 +17,7 @@ public class OpenApiSignUtils { */ public static String createSign(Map contentMap, String signKey) { String str2beSigned = mapToSignStr(contentMap); - str2beSigned = str2beSigned.concat("&signKey=").concat(signKey); + str2beSigned = str2beSigned.concat("&sign_key=").concat(signKey); return Md5Util.md5(str2beSigned); } @@ -68,15 +68,21 @@ public class OpenApiSignUtils { long now = System.currentTimeMillis(); System.out.println(now); + String uuid = UUID.randomUUID().toString(); + HashMap content = new HashMap<>(); - content.put("appId", "7d98b8af2d05752b4225709c4cfd4bd0"); + content.put("app_id", "7d98b8af2d05752b4225709c4cfd4bd0"); content.put("timestamp", String.valueOf(now)); - content.put("nonce", "aaa"); + content.put("nonce", uuid); + content.put("auth_type", "take_token"); String secret = "3209ee9f41704482be1a1fb5873a25376f2899191ca846119d44168316bc3e44"; String sign = createSign(content, secret); - System.out.println(sign); + + System.out.println("时间戳:" + now); + System.out.println("随机数:" + uuid); + System.out.println("签名:" + sign); } private static void generateGetOrgDetailSign() { @@ -90,6 +96,7 @@ public class OpenApiSignUtils { content.put("test", null); content.put("timestamp", String.valueOf(now)); content.put("nonce", uuid); + content.put("auth_type", "take_token"); String secret = "3209ee9f41704482be1a1fb5873a25376f2899191ca846119d44168316bc3e44"; diff --git a/epmet-gateway/pom.xml b/epmet-gateway/pom.xml index d901d0940e..8c9a652412 100644 --- a/epmet-gateway/pom.xml +++ b/epmet-gateway/pom.xml @@ -76,6 +76,11 @@ 2.0.0 compile + + com.epmet + epmet-commons-openapi + 2.0.0 + @@ -237,8 +242,8 @@ 0 - 192.168.1.130 - 6379 + 118.190.150.119 + 47379 123456 false @@ -309,8 +314,8 @@ lb://gov-project-server - lb://common-service-server - + + http://localhost:8103 lb://resi-home-server diff --git a/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java b/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java index 5954b2bd30..acc9f056ca 100644 --- a/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java +++ b/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java @@ -9,6 +9,8 @@ import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.SpringContextUtils; import com.epmet.feign.EpmetCommonServiceOpenFeignClient; +import com.epmet.openapi.constant.InClusterHeaderKeys; +import com.epmet.openapi.constant.RequestParamKeys; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; import org.apache.commons.lang3.StringUtils; @@ -28,12 +30,6 @@ public class ExtAppFetchTokenAuthProcessor extends ExtAppAuthProcessor { @Override public void auth(String appId, String token, Long ts, ServerWebExchange exchange) { - // 1.token过期校验 - if (StringUtils.isBlank(appId)) { - throw new RenException(EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getCode(), - EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getMsg()); - } - String secret = getSecret(appId); if (jwtTokenUtils.isTokenExpired(jwtTokenUtils.getExpiration(token, secret))) { @@ -47,7 +43,7 @@ public class ExtAppFetchTokenAuthProcessor extends ExtAppAuthProcessor { // 2. 获取claims Claims claims = jwtTokenUtils.getClaimByToken(token, secret); - String appIdInAccessToken = claims.get("appId", String.class); + String appIdInAccessToken = claims.get(RequestParamKeys.APP_ID, String.class); if (!appId.equals(appIdInAccessToken)) { // 参数列表的appId和token中封装的不一致 @@ -57,16 +53,16 @@ public class ExtAppFetchTokenAuthProcessor extends ExtAppAuthProcessor { // 3.将app_id放入header中 ServerHttpRequest.Builder mutate = exchange.getRequest().mutate(); - mutate.header("AppId", appId); + mutate.header(InClusterHeaderKeys.APP_ID, new String[]{appId}); exchange.mutate().request(mutate.build()).build(); } /** - * @Description 获取秘钥 * @return + * @Description 获取秘钥 * @author wxz * @date 2021.03.23 14:12 - */ + */ private String getSecret(String appId) { EpmetCommonServiceOpenFeignClient commonService = SpringContextUtils.getBean(EpmetCommonServiceOpenFeignClient.class); Result result = commonService.getSecret(appId); diff --git a/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java b/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java index 1b928ac295..bfd7da5de5 100644 --- a/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java +++ b/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java @@ -4,6 +4,8 @@ import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.exception.RenException; import com.epmet.filter.CpProperty; +import com.epmet.openapi.constant.AuthTypes; +import com.epmet.openapi.constant.RequestParamKeys; import com.epmet.utils.ServerHttpRequestUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -40,9 +42,6 @@ public class ExternalAuthProcessor extends AuthProcessor { public static final String APP_AUTH_TYPE_JWT = "jwt"; // 调用方生成md5 public static final String APP_AUTH_TYPE_MD5 = "md5"; - // 获取token方式 - public static final String APP_AUTH_TYPE_FETCH_TOKEN = "fetchToken"; - @Autowired private ExtAppJwtAuthProcessor jwtAuthProcessor; @@ -89,7 +88,7 @@ public class ExternalAuthProcessor extends AuthProcessor { String token = headers.getFirst(ACCESS_TOKEN_HEADER_KEY); String ts = headers.getFirst(APP_ID_TIMESTAMP_KEY); String customerId = headers.getFirst(APP_ID_CUSTOMER_ID_KEY); - String authType = headers.getFirst(APP_ID_AUTY_TYPE_KEY); + String authType = getAuthType(headers, request); logger.info("外部应用请求认证拦截Aspect执行,token:{}, ts:{}, customerId:{}, authType:{}", token, ts, customerId, authType); @@ -108,11 +107,10 @@ public class ExternalAuthProcessor extends AuthProcessor { throw new RenException(EpmetErrorCode.ERR401.getCode(), "请求头中的AccessToken和AppId不能为空"); } md5AuthProcessor.auth(appId, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange); - } else if (APP_AUTH_TYPE_FETCH_TOKEN.equals(authType)) { - String paramName = "app_id"; - String appId = ServerHttpRequestUtils.getRequestParam(request, paramName); + } else if (AuthTypes.TAKE_TOKEN.equals(authType)) { + String appId = ServerHttpRequestUtils.getRequestParam(request, RequestParamKeys.APP_ID); if (StringUtils.isBlank(appId)) { - throw new RenException(EpmetErrorCode.OPEN_API_PARAMS_MISSING.getCode(),"缺少参数".concat(paramName)); + throw new RenException(EpmetErrorCode.OPEN_API_PARAMS_MISSING.getCode(),"缺少参数".concat(RequestParamKeys.APP_ID)); } fetchTokenAuthProcessor.auth(appId, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange); } else { @@ -129,4 +127,12 @@ public class ExternalAuthProcessor extends AuthProcessor { return exchange; } + + private String getAuthType(HttpHeaders headers, ServerHttpRequest request) { + String authType = ServerHttpRequestUtils.getRequestParam(request, RequestParamKeys.AUTH_TYPE); + if (StringUtils.isBlank(authType)) { + authType = headers.getFirst(APP_ID_AUTY_TYPE_KEY); + } + return authType; + } } diff --git a/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java b/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java index c01c553b75..9e6d7ef077 100644 --- a/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java +++ b/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java @@ -10,6 +10,8 @@ import com.epmet.commons.tools.utils.IpUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.constant.AuthTypeConstant; import com.epmet.constant.TokenHeaderKeyConstant; +import com.epmet.openapi.constant.AuthTypes; +import com.epmet.openapi.constant.RequestParamKeys; import com.epmet.utils.ServerHttpRequestUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -112,8 +114,8 @@ public class CpAuthGatewayFilterFactory extends AbstractGatewayFilterFactory - + @@ -158,8 +158,8 @@ EpmEt-db-UsEr 0 - 192.168.1.130 - 6379 + 118.190.150.119 + 47379 123456 false diff --git a/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/AccessTokenFormDTO.java b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/AccessTokenFormDTO.java deleted file mode 100644 index 9fe569e75e..0000000000 --- a/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/AccessTokenFormDTO.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.epmet.dto.form; - -import com.epmet.dto.form.openapi.OpenApiBaseFormDTO; -import lombok.Data; - -import javax.validation.constraints.NotBlank; - -@Data -public class AccessTokenFormDTO extends OpenApiBaseFormDTO { - - // 应用id - @NotBlank(message = "AppId字段不能为空", groups = { GetAccessTokenGroup.class }) - private String appId; -} diff --git a/epmet-module/epmet-ext/epmet-ext-server/pom.xml b/epmet-module/epmet-ext/epmet-ext-server/pom.xml index d12766c5e9..e36faba1f1 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/pom.xml +++ b/epmet-module/epmet-ext/epmet-ext-server/pom.xml @@ -21,6 +21,11 @@ + + com.epmet + epmet-commons-openapi + 2.0.0 + com.epmet common-service-client @@ -239,14 +244,14 @@ - + epmet_third_user EpmEt-db-UsEr 0 - 192.168.1.130 - 6379 + 118.190.150.119 + 47379 123456 false diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java index 22f3280c25..10e5989d77 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java @@ -9,6 +9,7 @@ import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.feign.EpmetCommonServiceOpenFeignClient; +import com.epmet.openapi.constant.RequestParamKeys; import org.apache.commons.lang3.StringUtils; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; @@ -31,6 +32,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.Arrays; +import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -66,26 +68,41 @@ public class OpenApiRequestCheckAspect { Parameter[] parameters = method.getParameters(); HttpServletRequest request = getRequest(); - String appId = request.getHeader("AppId"); + Map argMap = new HashMap<>(); for (int i = 0; i < parameters.length; i++) { if (parameters[i].isAnnotationPresent(RequestBody.class)) { - Map argMap; try { argMap = ConvertUtils.entityToMap(args[i]); } catch (Exception e) { throw new RenException("验签参数转化发生异常"); } - argMap.put(""); - - if (!OpenApiSignUtils.checkSign(argMap, getSecret(appId))) { - // 验签失败 - throw new RenException(EpmetErrorCode.OPEN_API_SIGN_ERROR.getCode()); - } - checkRepeatRequest(argMap); + break; } } + + fillRequestParamsInfoArgMap(argMap, request); + if (!OpenApiSignUtils.checkSign(argMap, getSecret(argMap.get(RequestParamKeys.APP_ID)))) { + // 验签失败 + throw new RenException(EpmetErrorCode.OPEN_API_SIGN_ERROR.getCode()); + } + checkRepeatRequest(argMap); + } + + private void fillRequestParamsInfoArgMap(Map argMap, HttpServletRequest request) { + fillRequestParamsInfoArgMap(argMap, request, RequestParamKeys.APP_ID); + fillRequestParamsInfoArgMap(argMap, request, RequestParamKeys.AUTH_TYPE); + fillRequestParamsInfoArgMap(argMap, request, RequestParamKeys.NONCE); + fillRequestParamsInfoArgMap(argMap, request, RequestParamKeys.TIMESTAMP); + fillRequestParamsInfoArgMap(argMap, request, RequestParamKeys.SIGN); + } + + private void fillRequestParamsInfoArgMap(Map argMap, HttpServletRequest request, String paramName) { + String paramValue = request.getParameter(paramName); + if (StringUtils.isNotBlank(paramName)) { + argMap.put(paramName, paramValue); + } } /** @@ -93,7 +110,7 @@ public class OpenApiRequestCheckAspect { * @param argMap */ void checkRepeatRequest(Map argMap) { - String timestampStr = argMap.get("timestamp"); + String timestampStr = argMap.get(RequestParamKeys.TIMESTAMP); if (StringUtils.isBlank(timestampStr)) { throw new RenException(EpmetErrorCode.OPEN_API_PARAMS_MISSING.getCode()); } @@ -104,13 +121,13 @@ public class OpenApiRequestCheckAspect { // 只允许1分钟之内的请求,允许服务器之间时差为1分钟 throw new RenException(String.format("请求已过时,允许时差为%s ms", requestTimeDiff)); } - String nonce = argMap.get("nonce"); + String nonce = argMap.get(RequestParamKeys.NONCE); String nonceInCache = redisUtils.getString(RedisKeys.getOpenApiNonceKey(nonce)); if (StringUtils.isNotBlank(nonceInCache)) { throw new RenException("请求重复"); } //将nonce缓存到redis,有效期1分钟 - redisUtils.set(RedisKeys.getOpenApiNonceKey(nonce), "1", requestTimeDiff); + redisUtils.set(RedisKeys.getOpenApiNonceKey(nonce), System.currentTimeMillis(), requestTimeDiff); } /** diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java index c189e2fb3b..587dd99318 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java @@ -1,16 +1,11 @@ package com.epmet.controller; import com.epmet.annotation.OpenApiCheckSign; -import com.epmet.commons.security.sign.openapi.OpenApiSignUtils; -import com.epmet.commons.tools.exception.EpmetErrorCode; -import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; -import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; -import com.epmet.dto.form.AccessTokenFormDTO; import com.epmet.dto.form.openapi.OpenApiBaseFormDTO; import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.service.OpenApiAccessTokenService; @@ -18,13 +13,7 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.beans.IntrospectionException; -import java.lang.reflect.InvocationTargetException; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("open-api") @@ -49,12 +38,8 @@ public class OpenApiAccessTokenController { */ @OpenApiCheckSign @PostMapping("get-access-token") - public Result getAccessToken(@RequestBody AccessTokenFormDTO input) { - // 1.校验参数 - ValidatorUtils.validateEntity(input, OpenApiBaseFormDTO.GetAccessTokenGroup.class); - String appId = input.getAppId(); - - // 2.取secret + public Result getAccessToken(@RequestParam("app_id") String appId) { + // 1.取secret String secret = (String)redisUtils.get(RedisKeys.getExternalAppSecretKey(appId)); if (StringUtils.isBlank(secret)) { Result result = commonServiceOpenFeignClient.getSecret(appId); @@ -68,7 +53,7 @@ public class OpenApiAccessTokenController { redisUtils.set(RedisKeys.getExternalAppSecretKey(appId), secret); } - //4.生成token + //2.生成token String accessToken = openApiAccessTokenService.getAccessToken(appId, secret); return new Result().ok(accessToken); } diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java index 4cdee0c279..98409b0b36 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java @@ -30,7 +30,7 @@ public class OpenApiAccessTokenServiceImpl implements OpenApiAccessTokenService String token = jwtTokenUtils.createToken(claim, openApiConfig.getAccessTokenExpire(), secret); // 缓存token - redisUtils.set(RedisKeys.getOpenApiAccessTokenKey(token), appId, openApiConfig.getAccessTokenExpire()); + redisUtils.set(RedisKeys.getOpenApiAccessTokenKey(appId), token, openApiConfig.getAccessTokenExpire()); return token; } From e794248fd308ad45c6012614b30e9df814e768c9 Mon Sep 17 00:00:00 2001 From: wxz Date: Fri, 26 Mar 2021 09:17:12 +0800 Subject: [PATCH 11/18] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84db=E5=92=8Credis=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-gateway/pom.xml | 4 ++-- .../epmet-common-service/common-service-server/pom.xml | 6 +++--- epmet-module/epmet-ext/epmet-ext-server/pom.xml | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/epmet-gateway/pom.xml b/epmet-gateway/pom.xml index 8c9a652412..af02a2054c 100644 --- a/epmet-gateway/pom.xml +++ b/epmet-gateway/pom.xml @@ -242,8 +242,8 @@ 0 - 118.190.150.119 - 47379 + 192.168.1.130 + 6379 123456 false diff --git a/epmet-module/epmet-common-service/common-service-server/pom.xml b/epmet-module/epmet-common-service/common-service-server/pom.xml index 2c58b44a91..c863208d25 100644 --- a/epmet-module/epmet-common-service/common-service-server/pom.xml +++ b/epmet-module/epmet-common-service/common-service-server/pom.xml @@ -150,7 +150,7 @@ - + @@ -158,8 +158,8 @@ EpmEt-db-UsEr 0 - 118.190.150.119 - 47379 + 192.168.1.130 + 6379 123456 false diff --git a/epmet-module/epmet-ext/epmet-ext-server/pom.xml b/epmet-module/epmet-ext/epmet-ext-server/pom.xml index e36faba1f1..9eda7325be 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/pom.xml +++ b/epmet-module/epmet-ext/epmet-ext-server/pom.xml @@ -244,14 +244,14 @@ - + epmet_third_user EpmEt-db-UsEr 0 - 118.190.150.119 - 47379 + 192.168.1.130 + 6379 123456 false From 41c0a15f8fd1bedd682ffd23986de581588ae23e Mon Sep 17 00:00:00 2001 From: wxz Date: Fri, 26 Mar 2021 10:38:23 +0800 Subject: [PATCH 12/18] =?UTF-8?q?openApi=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/sign/openapi/OpenApiSignUtils.java | 1 + .../epmet/commons/tools/redis/RedisKeys.java | 4 ++-- ...r.java => ExtAppTakeTokenAuthProcessor.java} | 17 ++++++++++++----- .../com/epmet/auth/ExternalAuthProcessor.java | 4 ++-- .../epmet/aspect/OpenApiRequestCheckAspect.java | 13 +++++++------ .../impl/OpenApiAccessTokenServiceImpl.java | 3 ++- 6 files changed, 26 insertions(+), 16 deletions(-) rename epmet-gateway/src/main/java/com/epmet/auth/{ExtAppFetchTokenAuthProcessor.java => ExtAppTakeTokenAuthProcessor.java} (81%) diff --git a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java index 785c2a0578..ef3e31f6aa 100644 --- a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java +++ b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java @@ -94,6 +94,7 @@ public class OpenApiSignUtils { HashMap content = new HashMap<>(); content.put("orgId", "aaa"); content.put("test", null); + content.put("app_id", "7d98b8af2d05752b4225709c4cfd4bd0"); content.put("timestamp", String.valueOf(now)); content.put("nonce", uuid); content.put("auth_type", "take_token"); diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index dd5ca2e18a..d923bf5ba7 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -393,8 +393,8 @@ public class RedisKeys { * @author wxz * @date 2021.03.23 10:25 */ - public static String getOpenApiAccessTokenKey(String accessToken) { - return rootPrefix.concat("openapi:accesstoken:").concat(accessToken); + public static String getOpenApiAccessTokenKey(String appId) { + return rootPrefix.concat("openapi:accesstoken:").concat(appId); } /** diff --git a/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java b/epmet-gateway/src/main/java/com/epmet/auth/ExtAppTakeTokenAuthProcessor.java similarity index 81% rename from epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java rename to epmet-gateway/src/main/java/com/epmet/auth/ExtAppTakeTokenAuthProcessor.java index acc9f056ca..433b5ef01b 100644 --- a/epmet-gateway/src/main/java/com/epmet/auth/ExtAppFetchTokenAuthProcessor.java +++ b/epmet-gateway/src/main/java/com/epmet/auth/ExtAppTakeTokenAuthProcessor.java @@ -23,22 +23,29 @@ import org.springframework.web.server.ServerWebExchange; * 外部应用认证处理器:来平台token的方式 */ @Component -public class ExtAppFetchTokenAuthProcessor extends ExtAppAuthProcessor { +public class ExtAppTakeTokenAuthProcessor extends ExtAppAuthProcessor { @Autowired private JwtUtils jwtTokenUtils; + @Autowired + private RedisUtils redisUtils; + @Override public void auth(String appId, String token, Long ts, ServerWebExchange exchange) { String secret = getSecret(appId); - if (jwtTokenUtils.isTokenExpired(jwtTokenUtils.getExpiration(token, secret))) { + // 1.过期验证 + String accessTokenInCache = redisUtils.getString(RedisKeys.getOpenApiAccessTokenKey(appId)); + if (StringUtils.isBlank(accessTokenInCache) || + jwtTokenUtils.isTokenExpired(jwtTokenUtils.getExpiration(token, secret))) { + throw new RenException(EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getCode(), EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getMsg()); } // 2.验签 - // 验签暂时放到具体接口中 + // 验签暂时放到具体接口中,不放在gateway //openApiSignUtils.checkSign(); // 2. 获取claims @@ -47,8 +54,8 @@ public class ExtAppFetchTokenAuthProcessor extends ExtAppAuthProcessor { if (!appId.equals(appIdInAccessToken)) { // 参数列表的appId和token中封装的不一致 - throw new RenException(EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getCode(), - EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getMsg()); + throw new RenException(EpmetErrorCode.OPEN_API_PARAMS_APPID_DIFF.getCode(), + EpmetErrorCode.OPEN_API_PARAMS_APPID_DIFF.getMsg()); } // 3.将app_id放入header中 diff --git a/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java b/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java index bfd7da5de5..72fbfe5c9e 100644 --- a/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java +++ b/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java @@ -50,7 +50,7 @@ public class ExternalAuthProcessor extends AuthProcessor { private ExtAppMD5AuthProcessor md5AuthProcessor; @Autowired - private ExtAppFetchTokenAuthProcessor fetchTokenAuthProcessor; + private ExtAppTakeTokenAuthProcessor takeTokenAuthProcessor; private final AntPathMatcher antPathMatcher = new AntPathMatcher(); @@ -112,7 +112,7 @@ public class ExternalAuthProcessor extends AuthProcessor { if (StringUtils.isBlank(appId)) { throw new RenException(EpmetErrorCode.OPEN_API_PARAMS_MISSING.getCode(),"缺少参数".concat(RequestParamKeys.APP_ID)); } - fetchTokenAuthProcessor.auth(appId, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange); + takeTokenAuthProcessor.auth(appId, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange); } else { throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), "未知的外部认证类型"); } diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java index 10e5989d77..3ef87a5c04 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java @@ -26,15 +26,10 @@ import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; -import java.beans.IntrospectionException; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Parameter; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import java.util.Set; /** * OpenApi检查请求切面 @@ -90,6 +85,12 @@ public class OpenApiRequestCheckAspect { checkRepeatRequest(argMap); } + /** + * @Description 填充url请求参数到map中,用来签名 + * @return + * @author wxz + * @date 2021.03.26 10:13 + */ private void fillRequestParamsInfoArgMap(Map argMap, HttpServletRequest request) { fillRequestParamsInfoArgMap(argMap, request, RequestParamKeys.APP_ID); fillRequestParamsInfoArgMap(argMap, request, RequestParamKeys.AUTH_TYPE); @@ -116,7 +117,7 @@ public class OpenApiRequestCheckAspect { } long timestamp = Long.valueOf(timestampStr).longValue(); long now = System.currentTimeMillis(); - long requestTimeDiff = 60000; + long requestTimeDiff = 120000; if (Math.abs(now - timestamp) > requestTimeDiff) { // 只允许1分钟之内的请求,允许服务器之间时差为1分钟 throw new RenException(String.format("请求已过时,允许时差为%s ms", requestTimeDiff)); diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java index 98409b0b36..b00e5ca6d9 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java @@ -4,6 +4,7 @@ import com.epmet.commons.security.jwt.JwtUtils; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.config.OpenApiConfig; +import com.epmet.openapi.constant.RequestParamKeys; import com.epmet.service.OpenApiAccessTokenService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -25,7 +26,7 @@ public class OpenApiAccessTokenServiceImpl implements OpenApiAccessTokenService @Override public String getAccessToken(String appId, String secret) { HashMap claim = new HashMap<>(); - claim.put("appId", appId); + claim.put(RequestParamKeys.APP_ID, appId); String token = jwtTokenUtils.createToken(claim, openApiConfig.getAccessTokenExpire(), secret); From eec82464990ba18ba7d643a6e2e743d09af4b8ea Mon Sep 17 00:00:00 2001 From: wxz Date: Fri, 26 Mar 2021 14:08:31 +0800 Subject: [PATCH 13/18] =?UTF-8?q?=E8=8E=B7=E5=8F=96token=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E5=B0=86=E7=BB=93=E6=9E=9C=E5=B0=81=E8=A3=85=E6=88=90?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/commons/security/jwt/JwtUtils.java | 19 +++++++++++++++++++ .../sign/openapi/OpenApiSignUtils.java | 4 ++-- .../openapi/GetAccessTokenResultDTO.java | 12 ++++++++++++ .../OpenApiAccessTokenController.java | 7 ++++--- .../service/OpenApiAccessTokenService.java | 4 +++- .../impl/OpenApiAccessTokenServiceImpl.java | 15 +++++++++++---- 6 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/result/openapi/GetAccessTokenResultDTO.java diff --git a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtUtils.java b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtUtils.java index 23b738d623..8df0b6cd8f 100644 --- a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtUtils.java +++ b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtUtils.java @@ -78,6 +78,25 @@ public class JwtUtils { .compact(); } + /** + * @Description 创建Token + * @return Token + * @param claims 载荷信息 + * @param expireTime 过期时间 + * @param secret 秘钥 + * @author wxz + * @date 2021.03.26 13:33 + */ + public String createToken(Map claims, Date expireTime, String secret) { + return Jwts.builder() + .setHeaderParam("typ", "JWT") + .setClaims(claims) + .setIssuedAt(new Date()) + .setExpiration(expireTime) + .signWith(SignatureAlgorithm.HS512, secret) + .compact(); + } + /** * token是否过期 * diff --git a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java index ef3e31f6aa..f96a3777bb 100644 --- a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java +++ b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java @@ -60,8 +60,8 @@ public class OpenApiSignUtils { } public static void main(String[] args) { - //generateGetAccessTokenSign(); - generateGetOrgDetailSign(); + generateGetAccessTokenSign(); + //generateGetOrgDetailSign(); } private static void generateGetAccessTokenSign() { diff --git a/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/result/openapi/GetAccessTokenResultDTO.java b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/result/openapi/GetAccessTokenResultDTO.java new file mode 100644 index 0000000000..a913b25945 --- /dev/null +++ b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/result/openapi/GetAccessTokenResultDTO.java @@ -0,0 +1,12 @@ +package com.epmet.dto.result.openapi; + +import lombok.Data; + +@Data +public class GetAccessTokenResultDTO { + + private String accessToken; + + private Long expireTime; + +} diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java index 587dd99318..27c44ae532 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java @@ -7,6 +7,7 @@ import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.dto.form.openapi.OpenApiBaseFormDTO; +import com.epmet.dto.result.openapi.GetAccessTokenResultDTO; import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.service.OpenApiAccessTokenService; import org.apache.commons.lang3.StringUtils; @@ -38,7 +39,7 @@ public class OpenApiAccessTokenController { */ @OpenApiCheckSign @PostMapping("get-access-token") - public Result getAccessToken(@RequestParam("app_id") String appId) { + public Result getAccessToken(@RequestParam("app_id") String appId) { // 1.取secret String secret = (String)redisUtils.get(RedisKeys.getExternalAppSecretKey(appId)); if (StringUtils.isBlank(secret)) { @@ -54,8 +55,8 @@ public class OpenApiAccessTokenController { } //2.生成token - String accessToken = openApiAccessTokenService.getAccessToken(appId, secret); - return new Result().ok(accessToken); + GetAccessTokenResultDTO content = openApiAccessTokenService.getAccessToken(appId, secret); + return new Result().ok(content); } } diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/OpenApiAccessTokenService.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/OpenApiAccessTokenService.java index 56c3bd4630..2b6d362636 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/OpenApiAccessTokenService.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/OpenApiAccessTokenService.java @@ -1,5 +1,7 @@ package com.epmet.service; +import com.epmet.dto.result.openapi.GetAccessTokenResultDTO; + /** * access token的service */ @@ -11,5 +13,5 @@ public interface OpenApiAccessTokenService { * @author wxz * @date 2021.03.22 22:57 */ - String getAccessToken(String appId, String secret); + GetAccessTokenResultDTO getAccessToken(String appId, String secret); } diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java index b00e5ca6d9..fad64083db 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java @@ -4,11 +4,14 @@ import com.epmet.commons.security.jwt.JwtUtils; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.config.OpenApiConfig; +import com.epmet.dto.result.openapi.GetAccessTokenResultDTO; import com.epmet.openapi.constant.RequestParamKeys; import com.epmet.service.OpenApiAccessTokenService; +import org.joda.time.DateTime; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Date; import java.util.HashMap; @Service @@ -24,15 +27,19 @@ public class OpenApiAccessTokenServiceImpl implements OpenApiAccessTokenService private RedisUtils redisUtils; @Override - public String getAccessToken(String appId, String secret) { + public GetAccessTokenResultDTO getAccessToken(String appId, String secret) { HashMap claim = new HashMap<>(); claim.put(RequestParamKeys.APP_ID, appId); - String token = jwtTokenUtils.createToken(claim, openApiConfig.getAccessTokenExpire(), secret); - + Date expireTime = DateTime.now().plusSeconds(openApiConfig.getAccessTokenExpire()).toDate(); + String token = jwtTokenUtils.createToken(claim, expireTime, secret); // 缓存token redisUtils.set(RedisKeys.getOpenApiAccessTokenKey(appId), token, openApiConfig.getAccessTokenExpire()); - return token; + GetAccessTokenResultDTO content = new GetAccessTokenResultDTO(); + content.setAccessToken(token); + content.setExpireTime(expireTime.getTime()); + + return content; } } From 02d5a0c7cf141052aa751164b142a6e64317a378 Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 30 Mar 2021 09:22:35 +0800 Subject: [PATCH 14/18] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Aaccess=20token?= =?UTF-8?q?=E6=9C=89=E6=95=88=E6=9C=9F=E9=85=8D=E7=BD=AEde=E5=8D=95?= =?UTF-8?q?=E4=BD=8D=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet-ext/epmet-ext-server/src/main/resources/bootstrap.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/resources/bootstrap.yml b/epmet-module/epmet-ext/epmet-ext-server/src/main/resources/bootstrap.yml index 71e2a5ff55..881881db27 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/resources/bootstrap.yml +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/resources/bootstrap.yml @@ -114,4 +114,4 @@ shutdown: # 对外开放接口配置 openApi: accessToken: - expire: 7200000 + expire: 7200 From 98806364b496c1b3f337f89cfbcc36968e63a7c0 Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 30 Mar 2021 14:50:32 +0800 Subject: [PATCH 15/18] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Ajwt=E8=BF=87?= =?UTF-8?q?=E6=9C=9F=E4=B9=8B=E5=90=8E=EF=BC=8C=E5=8F=96=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E4=B8=BA=E7=A9=BA=EF=BC=8C=E9=80=A0=E6=88=90?= =?UTF-8?q?=E7=9A=84=E7=A9=BA=E6=8C=87=E9=92=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/sign/openapi/OpenApiSignUtils.java | 7 ++++--- .../epmet/auth/ExtAppTakeTokenAuthProcessor.java | 7 ++++++- .../com/epmet/aspect/OpenApiRequestCheckAspect.java | 13 +++++++++---- .../controller/OpenApiAccessTokenController.java | 2 -- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java index f96a3777bb..8551289868 100644 --- a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java +++ b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java @@ -61,14 +61,15 @@ public class OpenApiSignUtils { public static void main(String[] args) { generateGetAccessTokenSign(); - //generateGetOrgDetailSign(); + System.out.println("=============="); + generateGetOrgDetailSign(); } private static void generateGetAccessTokenSign() { long now = System.currentTimeMillis(); System.out.println(now); - String uuid = UUID.randomUUID().toString(); + String uuid = UUID.randomUUID().toString().replace("-", ""); HashMap content = new HashMap<>(); content.put("app_id", "7d98b8af2d05752b4225709c4cfd4bd0"); @@ -87,7 +88,7 @@ public class OpenApiSignUtils { private static void generateGetOrgDetailSign() { long now = System.currentTimeMillis(); - String uuid = UUID.randomUUID().toString(); + String uuid = UUID.randomUUID().toString().replace("-", "");; System.out.println("时间戳:" + now); System.out.println("随机数:" + uuid); diff --git a/epmet-gateway/src/main/java/com/epmet/auth/ExtAppTakeTokenAuthProcessor.java b/epmet-gateway/src/main/java/com/epmet/auth/ExtAppTakeTokenAuthProcessor.java index 433b5ef01b..6b527dc074 100644 --- a/epmet-gateway/src/main/java/com/epmet/auth/ExtAppTakeTokenAuthProcessor.java +++ b/epmet-gateway/src/main/java/com/epmet/auth/ExtAppTakeTokenAuthProcessor.java @@ -19,6 +19,8 @@ import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.stereotype.Component; import org.springframework.web.server.ServerWebExchange; +import java.util.Date; + /** * 外部应用认证处理器:来平台token的方式 */ @@ -37,8 +39,11 @@ public class ExtAppTakeTokenAuthProcessor extends ExtAppAuthProcessor { // 1.过期验证 String accessTokenInCache = redisUtils.getString(RedisKeys.getOpenApiAccessTokenKey(appId)); + Date expiration = jwtTokenUtils.getExpiration(token, secret); if (StringUtils.isBlank(accessTokenInCache) || - jwtTokenUtils.isTokenExpired(jwtTokenUtils.getExpiration(token, secret))) { + expiration == null || + jwtTokenUtils.isTokenExpired(expiration) + ) { throw new RenException(EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getCode(), EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getMsg()); diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java index 3ef87a5c04..6661ac747d 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java @@ -47,6 +47,11 @@ public class OpenApiRequestCheckAspect { @Autowired private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; + //请求时差单位:s + long requestTimeSecDiff = 120; + //请求时差,单位:ms + long requestTimeMillSecDiff = requestTimeSecDiff * 1000;//单位:ms + private static final Logger log = LoggerFactory.getLogger(DataFilterAspect.class); /** @@ -117,10 +122,10 @@ public class OpenApiRequestCheckAspect { } long timestamp = Long.valueOf(timestampStr).longValue(); long now = System.currentTimeMillis(); - long requestTimeDiff = 120000; - if (Math.abs(now - timestamp) > requestTimeDiff) { + + if (Math.abs(now - timestamp) > requestTimeMillSecDiff) { // 只允许1分钟之内的请求,允许服务器之间时差为1分钟 - throw new RenException(String.format("请求已过时,允许时差为%s ms", requestTimeDiff)); + throw new RenException(String.format("请求已过时,允许时差为%s s", requestTimeSecDiff)); } String nonce = argMap.get(RequestParamKeys.NONCE); String nonceInCache = redisUtils.getString(RedisKeys.getOpenApiNonceKey(nonce)); @@ -128,7 +133,7 @@ public class OpenApiRequestCheckAspect { throw new RenException("请求重复"); } //将nonce缓存到redis,有效期1分钟 - redisUtils.set(RedisKeys.getOpenApiNonceKey(nonce), System.currentTimeMillis(), requestTimeDiff); + redisUtils.set(RedisKeys.getOpenApiNonceKey(nonce), System.currentTimeMillis(), requestTimeSecDiff); } /** diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java index 27c44ae532..5f24502bfa 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java @@ -5,8 +5,6 @@ import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.utils.Result; -import com.epmet.commons.tools.validator.ValidatorUtils; -import com.epmet.dto.form.openapi.OpenApiBaseFormDTO; import com.epmet.dto.result.openapi.GetAccessTokenResultDTO; import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.service.OpenApiAccessTokenService; From 8e54b66bfd33a548f5983a89a2b3c89271a74977 Mon Sep 17 00:00:00 2001 From: wxz Date: Thu, 1 Apr 2021 00:09:22 +0800 Subject: [PATCH 16/18] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9Aopenapi?= =?UTF-8?q?=E6=9C=AA=E4=BC=A0=E9=80=92token=EF=BC=8C=E5=88=99=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=AF=B7=E6=B1=82=E6=9C=AA=E8=AE=A4=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/commons/tools/exception/EpmetErrorCode.java | 9 +++++---- .../main/java/com/epmet/auth/ExternalAuthProcessor.java | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index f83a55d32f..bb16d73456 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -146,10 +146,11 @@ public enum EpmetErrorCode { TOPIC_IS_CLOSED(9008,"该话题已关闭,无法转为议题"), // open api异常 - OPEN_API_SIGN_ERROR(9100, "签名错误"), - OPEN_API_TOKEN_EXPIRED(9101, "Token过期"), - OPEN_API_PARAMS_MISSING(9102, "参数不完整"), - OPEN_API_PARAMS_APPID_DIFF(9103, "app_id不一致"); // app_id在请求参数中和在token中不一致 + OPEN_API_UNAUTHENTICATED(9100, "请求未认证"), + OPEN_API_TOKEN_EXPIRED(9102, "Token过期"), + OPEN_API_PARAMS_MISSING(9103, "参数不完整"), + OPEN_API_SIGN_ERROR(9104, "签名错误"), + OPEN_API_PARAMS_APPID_DIFF(9105, "app_id不一致"); // app_id在请求参数中和在token中不一致 private int code; private String msg; diff --git a/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java b/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java index 72fbfe5c9e..d21ec692c5 100644 --- a/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java +++ b/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java @@ -108,9 +108,12 @@ public class ExternalAuthProcessor extends AuthProcessor { } md5AuthProcessor.auth(appId, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange); } else if (AuthTypes.TAKE_TOKEN.equals(authType)) { + if (StringUtils.isBlank(token)) { + throw new RenException(EpmetErrorCode.OPEN_API_UNAUTHENTICATED.getCode()); + } String appId = ServerHttpRequestUtils.getRequestParam(request, RequestParamKeys.APP_ID); if (StringUtils.isBlank(appId)) { - throw new RenException(EpmetErrorCode.OPEN_API_PARAMS_MISSING.getCode(),"缺少参数".concat(RequestParamKeys.APP_ID)); + throw new RenException(EpmetErrorCode.OPEN_API_PARAMS_MISSING.getCode(),"缺少参数:".concat(RequestParamKeys.APP_ID)); } takeTokenAuthProcessor.auth(appId, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange); } else { From e27fbc3c1ab1337bb0e4b3d272c297f502797a21 Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 13 Apr 2021 13:48:17 +0800 Subject: [PATCH 17/18] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9AopenApi?= =?UTF-8?q?=E9=AA=8C=E7=AD=BE=E9=83=A8=E5=88=86=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/security/sign/openapi/OpenApiSignUtils.java | 5 +++-- .../com/epmet/commons/tools/exception/EpmetErrorCode.java | 4 +++- .../java/com/epmet/aspect/OpenApiRequestCheckAspect.java | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java index 8551289868..1de1b04f73 100644 --- a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java +++ b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java @@ -93,8 +93,9 @@ public class OpenApiSignUtils { System.out.println("随机数:" + uuid); HashMap content = new HashMap<>(); - content.put("orgId", "aaa"); - content.put("test", null); + //content.put("orgId", "aaa"); + //content.put("test", null); + content.put("gridId", "12128e0f614f1c00a058ea9a107033b2"); content.put("app_id", "7d98b8af2d05752b4225709c4cfd4bd0"); content.put("timestamp", String.valueOf(now)); content.put("nonce", uuid); diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index 26834d4458..5673b272f1 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -156,7 +156,9 @@ public enum EpmetErrorCode { OPEN_API_TOKEN_EXPIRED(10102, "Token过期"), OPEN_API_PARAMS_MISSING(10103, "参数不完整"), OPEN_API_SIGN_ERROR(10104, "签名错误"), - OPEN_API_PARAMS_APPID_DIFF(10105, "app_id不一致"); // app_id在请求参数中和在token中不一致 + OPEN_API_PARAMS_APPID_DIFF(10105, "app_id不一致"), // app_id在请求参数中和在token中不一致 + OPEN_API_REQUEST_EXPIRED(10106, "请求过期"), + OPEN_API_REQUEST_REPEAT(10107, "请求重复"); private int code; private String msg; diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java index 6661ac747d..c6f23cc779 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java @@ -125,12 +125,13 @@ public class OpenApiRequestCheckAspect { if (Math.abs(now - timestamp) > requestTimeMillSecDiff) { // 只允许1分钟之内的请求,允许服务器之间时差为1分钟 - throw new RenException(String.format("请求已过时,允许时差为%s s", requestTimeSecDiff)); + throw new RenException(EpmetErrorCode.OPEN_API_REQUEST_EXPIRED.getCode(), + String.format("请求已过期,允许时差为%s s", requestTimeSecDiff)); } String nonce = argMap.get(RequestParamKeys.NONCE); String nonceInCache = redisUtils.getString(RedisKeys.getOpenApiNonceKey(nonce)); if (StringUtils.isNotBlank(nonceInCache)) { - throw new RenException("请求重复"); + throw new RenException(EpmetErrorCode.OPEN_API_REQUEST_REPEAT.getCode()); } //将nonce缓存到redis,有效期1分钟 redisUtils.set(RedisKeys.getOpenApiNonceKey(nonce), System.currentTimeMillis(), requestTimeSecDiff); From 5186720b1d20d2adbadc906e97c1187e5d2e010b Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 13 Apr 2021 15:18:59 +0800 Subject: [PATCH 18/18] =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=AF=AF=E5=88=A0=E7=9A=84=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet-openapi-adv-client/pom.xml | 16 + .../epmet-openapi-adv-server/Dockerfile | 11 + .../deploy/docker-compose-dev.yml | 18 + .../deploy/docker-compose-prod.yml | 18 + .../deploy/docker-compose-test.yml | 18 + .../epmet-openapi-adv-server/pom.xml | 227 ++++++ .../java/com/epmet/adv/AdvApplication.java | 15 + .../epmet/adv/aspect/RequestLogAspect.java | 40 + .../epmet/adv/config/ModuleConfigImpl.java | 26 + .../adv/controller/AdvVideoController.java | 28 + .../java/com/epmet/adv/dao/AdvVedioDao.java | 33 + .../com/epmet/adv/entity/AdvVedioEntity.java | 56 ++ .../epmet/adv/service/AdvVedioService.java | 7 + .../adv/service/impl/AdvVedioServiceImpl.java | 18 + .../src/main/resources/bootstrap.yml | 140 ++++ .../db/migration/V0.0.1__createAdvVedio.sql | 18 + .../src/main/resources/logback-spring.xml | 169 ++++ .../src/main/resources/mapper/AdvVedioDao.xml | 35 + epmet-openapi/epmet-openapi-adv/pom.xml | 21 + epmet-openapi/epmet-openapi-scan/Dockerfile | 11 + .../deploy/docker-compose-dev.yml | 18 + .../deploy/docker-compose-prod.yml | 18 + .../deploy/docker-compose-test.yml | 18 + epmet-openapi/epmet-openapi-scan/pom.xml | 208 +++++ .../epmet/openapi/scan/ScanApplication.java | 30 + .../openapi/scan/aspect/RequestLogAspect.java | 40 + .../scan/common/constant/SysConstant.java | 30 + .../scan/common/enu/CommonErrorCodeEnum.java | 68 ++ .../openapi/scan/common/enu/ImgSceneEnum.java | 47 ++ .../openapi/scan/common/enu/LabelEnum.java | 66 ++ .../openapi/scan/common/enu/RegionIdEnum.java | 49 ++ .../scan/common/enu/SuggestionEnum.java | 48 ++ .../scan/common/enu/SysResponseEnum.java | 46 ++ .../scan/common/enu/TextSceneEnum.java | 46 ++ .../scan/common/enu/VideoSceneEnum.java | 50 ++ .../scan/common/enu/VoiceSceneEnum.java | 47 ++ .../exception/ExecuteHttpException.java | 29 + .../openapi/scan/common/redis/RedisKeys.java | 38 + .../scan/common/util/HttpClientManager.java | 171 ++++ .../scan/common/util/IAcsClientUtil.java | 67 ++ .../openapi/scan/common/util/MapUtil.java | 55 ++ .../openapi/scan/config/ModuleConfigImpl.java | 26 + .../openapi/scan/config/WebAppConfig.java | 31 + .../scan/controller/BackDoorController.java | 32 + .../scan/controller/ScanController.java | 116 +++ .../interceptor/ScanApiAuthInterceptor.java | 60 ++ .../scan/service/impl/ScanService.java | 69 ++ .../scan/service/impl/ScanServiceImpl.java | 734 ++++++++++++++++++ .../scan/support/param/ImgScanParam.java | 48 ++ .../openapi/scan/support/param/ImgTask.java | 31 + .../scan/support/param/TextScanParam.java | 48 ++ .../openapi/scan/support/param/TextTask.java | 33 + .../support/param/VoiceAsyncScanParam.java | 68 ++ .../openapi/scan/support/param/VoiceTask.java | 31 + .../param/video/VideoAsyncScanParam.java | 76 ++ .../param/video/VideoAsyncScanTask.java | 30 + .../support/result/ImgAsyncScanResult.java | 24 + .../scan/support/result/ScanTaskResult.java | 28 + .../support/result/SceneDetailResult.java | 31 + .../scan/support/result/SyncScanResult.java | 42 + .../result/VoiceAsyncScanDetailDTO.java | 47 ++ .../support/result/VoiceAsyncScanResult.java | 89 +++ .../result/VoiceAsyncScanResultDTO.java | 57 ++ .../result/VoiceAsyncScanTaskDataDTO.java | 40 + .../result/VoiceAsyncScanTaskResult.java | 46 ++ .../video/VideoAsyncScanTaskDataDTO.java | 41 + .../video/VideoAsyncScanTaskResultDTO.java | 45 ++ .../support/result/video/VideoResultDTO.java | 48 ++ .../result/video/VideoScanOriginDetail.java | 53 ++ .../video/VideoScanOriginalResultDTO.java | 51 ++ .../src/main/resources/bootstrap.yml | 91 +++ .../src/main/resources/logback-spring.xml | 169 ++++ .../src/main/resources/readme | 7 + .../src/test/java/BaseSample.java | 50 ++ .../java/ImageAsyncScanRequestSample.java | 95 +++ .../java/ImageAsyncScanResultsSample.java | 83 ++ .../test/java/ImageSyncScanRequestSample.java | 101 +++ .../java/VoiceAsyncScanRequestSample.java | 90 +++ .../VoiceAsyncScanResultsRequestSample.java | 113 +++ epmet-openapi/pom.xml | 19 + 80 files changed, 5007 insertions(+) create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-client/pom.xml create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/Dockerfile create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-dev.yml create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-prod.yml create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-test.yml create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/pom.xml create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/AdvApplication.java create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/aspect/RequestLogAspect.java create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/config/ModuleConfigImpl.java create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/controller/AdvVideoController.java create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/dao/AdvVedioDao.java create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/entity/AdvVedioEntity.java create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/AdvVedioService.java create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/impl/AdvVedioServiceImpl.java create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/bootstrap.yml create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/db/migration/V0.0.1__createAdvVedio.sql create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/logback-spring.xml create mode 100644 epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/mapper/AdvVedioDao.xml create mode 100644 epmet-openapi/epmet-openapi-adv/pom.xml create mode 100644 epmet-openapi/epmet-openapi-scan/Dockerfile create mode 100644 epmet-openapi/epmet-openapi-scan/deploy/docker-compose-dev.yml create mode 100644 epmet-openapi/epmet-openapi-scan/deploy/docker-compose-prod.yml create mode 100644 epmet-openapi/epmet-openapi-scan/deploy/docker-compose-test.yml create mode 100644 epmet-openapi/epmet-openapi-scan/pom.xml create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/ScanApplication.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/aspect/RequestLogAspect.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/CommonErrorCodeEnum.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/ImgSceneEnum.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/LabelEnum.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/RegionIdEnum.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SuggestionEnum.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/TextSceneEnum.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VideoSceneEnum.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VoiceSceneEnum.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExecuteHttpException.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/redis/RedisKeys.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/HttpClientManager.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/IAcsClientUtil.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/MapUtil.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/ModuleConfigImpl.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/WebAppConfig.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/BackDoorController.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiAuthInterceptor.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanService.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextTask.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceAsyncScanParam.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceTask.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanParam.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanTask.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAsyncScanResult.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ScanTaskResult.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SceneDetailResult.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SyncScanResult.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanDetailDTO.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResult.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResultDTO.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskDataDTO.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskResult.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskDataDTO.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskResultDTO.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoResultDTO.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginDetail.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginalResultDTO.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/resources/bootstrap.yml create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/resources/logback-spring.xml create mode 100644 epmet-openapi/epmet-openapi-scan/src/main/resources/readme create mode 100644 epmet-openapi/epmet-openapi-scan/src/test/java/BaseSample.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanRequestSample.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanResultsSample.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/test/java/ImageSyncScanRequestSample.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanRequestSample.java create mode 100644 epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanResultsRequestSample.java create mode 100644 epmet-openapi/pom.xml diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-client/pom.xml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-client/pom.xml new file mode 100644 index 0000000000..5c57808384 --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-client/pom.xml @@ -0,0 +1,16 @@ + + + + epmet-openapi-adv + com.epmet + 2.0.0 + ../pom.xml + + 4.0.0 + + epmet-openapi-adv-client + + + \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/Dockerfile b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/Dockerfile new file mode 100644 index 0000000000..d15b865820 --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/Dockerfile @@ -0,0 +1,11 @@ +FROM java:8 + +RUN export LANG="zh_CN.UTF-8" +RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +RUN echo 'Asia/Shanghai' > /etc/timezone + +COPY ./target/*.jar ./epmet-openapi-adv.jar + +EXPOSE 8115 + +ENTRYPOINT ["sh", "-c", "exec $RUN_INSTRUCT"] \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-dev.yml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-dev.yml new file mode 100644 index 0000000000..55c505363d --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-dev.yml @@ -0,0 +1,18 @@ +version: "3.7" +services: + epmet-openapi-adv-server: + container_name: epmet-openapi-adv-server-dev + image: 192.168.1.130:10080/epmet-cloud-dev/epmet-openapi-adv-server:version_placeholder + ports: + - "8015:8015" + network_mode: host # 不会创建新的网络 + volumes: + - "/opt/epmet-cloud-logs/dev:/logs" + environment: + RUN_INSTRUCT: "java -Xms32m -Xmx200m -jar ./epmet-openapi-adv.jar" + restart: "unless-stopped" + deploy: + resources: + limits: + cpus: '0.1' + memory: 300M \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-prod.yml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-prod.yml new file mode 100644 index 0000000000..b5a13e04e3 --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-prod.yml @@ -0,0 +1,18 @@ +version: "3.7" +services: + epmet-openapi-adv-server: + container_name: epmet-openapi-adv-server-prod + image: registry-vpc.cn-qingdao.aliyuncs.com/epmet-cloud-master/epmet-openapi-adv-server:0.3.3 + ports: + - "8015:8015" + network_mode: host # 不会创建新的网络 + volumes: + - "/opt/epmet-cloud-logs/prod:/logs" + environment: + RUN_INSTRUCT: "java -Xms256m -Xmx512m -jar ./epmet-openapi-adv.jar" + restart: "unless-stopped" + deploy: + resources: + limits: + cpus: '0.1' + memory: 600M \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-test.yml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-test.yml new file mode 100644 index 0000000000..45d536cb2f --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/deploy/docker-compose-test.yml @@ -0,0 +1,18 @@ +version: "3.7" +services: + epmet-openapi-adv-server: + container_name: epmet-openapi-adv-server-test + image: registry-vpc.cn-qingdao.aliyuncs.com/epmet-cloud-release/epmet-openapi-adv-server:version_placeholder + ports: + - "8015:8015" + network_mode: host # 不会创建新的网络 + volumes: + - "/opt/epmet-cloud-logs/test:/logs" + environment: + RUN_INSTRUCT: "java -Xms32m -Xmx200m -jar ./epmet-openapi-adv.jar" + restart: "unless-stopped" + deploy: + resources: + limits: + cpus: '0.1' + memory: 300M \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/pom.xml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/pom.xml new file mode 100644 index 0000000000..8dd1602e70 --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/pom.xml @@ -0,0 +1,227 @@ + + + + 0.3.3 + + epmet-openapi-adv + com.epmet + 2.0.0 + ../pom.xml + + 4.0.0 + + epmet-openapi-adv-server + + + + com.epmet + epmet-commons-mybatis + 2.0.0 + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework + spring-context-support + + + org.springframework.boot + spring-boot-starter-actuator + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + io.github.openfeign + feign-httpclient + 10.3.0 + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + ${project.basedir}/src/main/java + + + true + ${basedir}/src/main/resources + + + + + + + dev + + 8115 + dev + + + + + + epmet_adv_user + EpmEt-db-UsEr + + 0 + 192.168.1.130 + 6379 + 123456 + + true + 192.168.1.130:8848 + 6ceab336-d004-4acf-89c6-e121d06f4988 + + + false + + + false + + + https://oapi.dingtalk.com/robot/send?access_token=90782b119f82a5b6bb8e0f819b6a77bbc2102b53aa2d7d2e24fa10b66d580b1c + + SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 + + + + + local + + true + + + 8115 + local + + + + + + epmet_adv_user + EpmEt-db-UsEr + + 0 + 118.190.150.119 + 47379 + 123456 + + false + 192.168.1.130:8848 + 6ceab336-d004-4acf-89c6-e121d06f4988 + + + false + + + false + + + https://oapi.dingtalk.com/robot/send?access_token=90782b119f82a5b6bb8e0f819b6a77bbc2102b53aa2d7d2e24fa10b66d580b1c + + SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 + + https://epmet-dev.elinkservice.cn/api/epmetscan/api + + + + test + + + 8115 + test + + + + + + epmet + elink@833066 + + 0 + r-m5eoz5b6tkx09y6bpz.redis.rds.aliyuncs.com + 6379 + EpmEtrEdIs!q@w + + true + 192.168.10.150:8848 + 67e3c350-533e-4d7c-9f8f-faf1b4aa82ae + + + false + + + true + + + https://oapi.dingtalk.com/robot/send?access_token=90782b119f82a5b6bb8e0f819b6a77bbc2102b53aa2d7d2e24fa10b66d580b1c + + SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 + + + + + prod + + 8115 + prod + + + + + + epmet_adv_user + EpmEt-db-UsEr + + 0 + r-m5ez3n1j0qc3ykq2ut.redis.rds.aliyuncs.com + 6379 + EpmEtclOUdrEdIs!Q2w + + true + 192.168.11.180:8848 + bd205d23-e696-47be-b995-916313f86e99 + + + false + + + true + + + + https://oapi.dingtalk.com/robot/send?access_token=a5f66c3374b1642fe2142dbf56d5997e280172d4e8f2b546c9423a68c82ece6c + + SEC95f4f40b533ad379ea6a6d1af6dd37029383cfe1b7cd96dfac2678be2c1c3ed1 + + + + + + \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/AdvApplication.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/AdvApplication.java new file mode 100644 index 0000000000..61c5d3b4b8 --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/AdvApplication.java @@ -0,0 +1,15 @@ +package com.epmet; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +public class AdvApplication { + public static void main(String[] args) { + SpringApplication.run(AdvApplication.class, args); + } +} diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/aspect/RequestLogAspect.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/aspect/RequestLogAspect.java new file mode 100644 index 0000000000..e06fdc2c95 --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/aspect/RequestLogAspect.java @@ -0,0 +1,40 @@ +package com.epmet.adv.aspect; + +import com.epmet.commons.tools.aspect.BaseRequestLogAspect; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; + +/** + * 日志/异常处理切面实现,调用父类方法完成日志记录和异常处理。 + */ +@Aspect +@Component +@Order(0) +public class RequestLogAspect extends BaseRequestLogAspect { + + @Override + @Around(value = "execution(* com.epmet.adv.controller.*Controller*.*(..)) ") + public Object proceed(ProceedingJoinPoint point) throws Throwable { + return super.proceed(point, getRequest()); + } + + /** + * 获取Request对象 + * + * @return + */ + private HttpServletRequest getRequest() { + RequestAttributes ra = RequestContextHolder.getRequestAttributes(); + ServletRequestAttributes sra = (ServletRequestAttributes) ra; + return sra.getRequest(); + } + +} diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/config/ModuleConfigImpl.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/config/ModuleConfigImpl.java new file mode 100644 index 0000000000..8d88549b66 --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/config/ModuleConfigImpl.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + * + * https://www.renren.io + * + * 版权所有,侵权必究! + */ + +package com.epmet.adv.config; + +import com.epmet.commons.tools.config.ModuleConfig; +import org.springframework.stereotype.Service; + +/** + * 模块配置信息 + * + * @author Mark sunlightcs@gmail.com + * @since 1.0.0 + */ +@Service +public class ModuleConfigImpl implements ModuleConfig { + @Override + public String getName() { + return "adv"; + } +} diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/controller/AdvVideoController.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/controller/AdvVideoController.java new file mode 100644 index 0000000000..5c032ad562 --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/controller/AdvVideoController.java @@ -0,0 +1,28 @@ +package com.epmet.adv.controller; + +import com.epmet.adv.entity.AdvVedioEntity; +import com.epmet.adv.service.AdvVedioService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; + +@Controller +@RequestMapping("video") +public class AdvVideoController { + + @Autowired + private AdvVedioService advVedioService; + + @GetMapping("company-adv") + public String toVedio() throws IOException { + AdvVedioEntity enableAdvVedioEntity = advVedioService.getEnableAdvVedioEntity(); + String redirectUrl = enableAdvVedioEntity != null ? enableAdvVedioEntity.getPath() : "404"; + return String.format("redirect:%s", redirectUrl); + //response.sendRedirect("www.baidu.com"); + } + +} diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/dao/AdvVedioDao.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/dao/AdvVedioDao.java new file mode 100644 index 0000000000..c14da09d52 --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/dao/AdvVedioDao.java @@ -0,0 +1,33 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.adv.dao; + +import com.epmet.adv.entity.AdvVedioEntity; +import com.epmet.commons.mybatis.dao.BaseDao; +import org.apache.ibatis.annotations.Mapper; + +/** + * 宣传视频 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-12-30 + */ +@Mapper +public interface AdvVedioDao extends BaseDao { + AdvVedioEntity getEnableAdvVedioEntity(); +} \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/entity/AdvVedioEntity.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/entity/AdvVedioEntity.java new file mode 100644 index 0000000000..a25c6ea77e --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/entity/AdvVedioEntity.java @@ -0,0 +1,56 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.adv.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 宣传视频 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-12-30 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("adv_vedio") +public class AdvVedioEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 存储路径 + */ + private String path; + + /** + * 存储类型。aliyun_oss,local + */ + private String storeType; + + /** + * 是否启用 + */ + private Integer enable; + +} diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/AdvVedioService.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/AdvVedioService.java new file mode 100644 index 0000000000..38091ee496 --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/AdvVedioService.java @@ -0,0 +1,7 @@ +package com.epmet.adv.service; + +import com.epmet.adv.entity.AdvVedioEntity; + +public interface AdvVedioService { + AdvVedioEntity getEnableAdvVedioEntity(); +} diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/impl/AdvVedioServiceImpl.java b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/impl/AdvVedioServiceImpl.java new file mode 100644 index 0000000000..cecc710c39 --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/java/com/epmet/adv/service/impl/AdvVedioServiceImpl.java @@ -0,0 +1,18 @@ +package com.epmet.adv.service.impl; + +import com.epmet.adv.dao.AdvVedioDao; +import com.epmet.adv.entity.AdvVedioEntity; +import com.epmet.adv.service.AdvVedioService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class AdvVedioServiceImpl implements AdvVedioService { + @Autowired + private AdvVedioDao advVedioDao; + + public AdvVedioEntity getEnableAdvVedioEntity() { + return advVedioDao.getEnableAdvVedioEntity(); + } + +} diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/bootstrap.yml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/bootstrap.yml new file mode 100644 index 0000000000..0bd40dcca7 --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/bootstrap.yml @@ -0,0 +1,140 @@ +server: + port: @server.port@ + version: @version@ + servlet: + context-path: /adv + +spring: + main: + allow-bean-definition-overriding: true + application: + name: epmet-openapi-adv-server + #环境 dev|test|prod + profiles: + active: @spring.profiles.active@ + messages: + encoding: UTF-8 + basename: i18n/messages_common + jackson: + time-zone: GMT+8 + date-format: yyyy-MM-dd HH:mm:ss + redis: + database: @spring.redis.index@ + host: @spring.redis.host@ + port: @spring.redis.port@ + password: @spring.redis.password@ + timeout: 30s + datasource: + druid: + #MySQL + driver-class-name: com.mysql.cj.jdbc.Driver + url: @spring.datasource.druid.url@ + username: @spring.datasource.druid.username@ + password: @spring.datasource.druid.password@ + initial-size: 10 + max-active: 100 + min-idle: 10 + max-wait: 60000 + pool-prepared-statements: true + max-pool-prepared-statement-per-connection-size: 20 + time-between-eviction-runs-millis: 60000 + min-evictable-idle-time-millis: 300000 + #Oracle需要打开注释 + #validation-query: SELECT 1 FROM DUAL + test-while-idle: true + test-on-borrow: false + test-on-return: false + filter: + stat: + log-slow-sql: true + slow-sql-millis: 1000 + merge-sql: false + wall: + config: + multi-statement-allow: true + # 数据迁移工具flyway + flyway: + enabled: @spring.flyway.enabled@ + locations: classpath:db/migration + url: @spring.datasource.druid.url@ + user: @spring.datasource.druid.username@ + password: @spring.datasource.druid.password@ + baseline-on-migrate: true + baseline-version: 0 + cloud: + nacos: + discovery: + server-addr: @nacos.server-addr@ + #nacos的命名空间ID,默认是public + namespace: @nacos.discovery.namespace@ + #不把自己注册到注册中心的地址 + register-enabled: @nacos.register-enabled@ + ip: @nacos.ip@ + config: + enabled: @nacos.config-enabled@ + server-addr: @nacos.server-addr@ + namespace: @nacos.config.namespace@ + group: @nacos.config.group@ + file-extension: yaml +management: + endpoints: + web: + exposure: + include: "*" + endpoint: + health: + show-details: ALWAYS + +mybatis-plus: + mapper-locations: classpath:/mapper/**/*.xml + #实体扫描,多个package用逗号或者分号分隔 + typeAliasesPackage: com.epmet.entity + global-config: + #数据库相关配置 + db-config: + #主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID"; + id-type: ID_WORKER + #字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断" + field-strategy: NOT_NULL + #驼峰下划线转换 + column-underline: true + banner: false + #原生配置 + configuration: + map-underscore-to-camel-case: true + cache-enabled: false + call-setters-on-nulls: true + jdbc-type-for-null: 'null' + +feign: + hystrix: + enabled: true + client: + config: + default: + loggerLevel: BASIC + okhttp: + enabled: true + + +hystrix: + command: + default: + execution: + isolation: + thread: + timeoutInMilliseconds: 60000 #缺省为1000 + +ribbon: + ReadTimeout: 300000 + ConnectTimeout: 300000 + +#pageHelper分页插件 +pagehelper: + helper-dialect: mysql + reasonable: false #分页合理化配置,例如输入页码为-1,则自动转化为最小页码1 + +dingTalk: + robot: + webHook: @dingTalk.robot.webHook@ + secret: @dingTalk.robot.secret@ diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/db/migration/V0.0.1__createAdvVedio.sql b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/db/migration/V0.0.1__createAdvVedio.sql new file mode 100644 index 0000000000..007c12b55f --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/db/migration/V0.0.1__createAdvVedio.sql @@ -0,0 +1,18 @@ +-- create database epmet_adv default character set utf8mb4; + +-- CREATE USER epmet_adv_user@'%' IDENTIFIED BY 'EpmEt-db-UsEr'; +-- GRANT ALL ON `epmet_adv%`.* TO 'epmet_adv_user'@'%'; +-- flush privileges; + +CREATE TABLE `adv_vedio` ( + `ID` varchar(64) NOT NULL COMMENT 'id' primary key , + `PATH` varchar(255) NOT NULL COMMENT '存储路径', + `STORE_TYPE` varchar(30) NOT NULL COMMENT '存储类型。aliyun_oss,local', + `ENABLE` tinyint(1) NOT NULL COMMENT '是否启用', + `REVISION` int(11) DEFAULT NULL COMMENT '乐观锁', + `DEL_FLAG` int(11) unsigned DEFAULT NULL COMMENT '删除标识 0:未删除 1:删除', + `CREATED_BY` varchar(32) DEFAULT NULL COMMENT '创建者', + `CREATED_TIME` datetime DEFAULT NULL COMMENT '创建时间', + `UPDATED_BY` varchar(32) DEFAULT NULL COMMENT '更新者', + `UPDATED_TIME` datetime DEFAULT NULL COMMENT '更新时间' +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='宣传视频' \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/logback-spring.xml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/logback-spring.xml new file mode 100644 index 0000000000..06a21d317c --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/logback-spring.xml @@ -0,0 +1,169 @@ + + + + + + + + + + + + ${appname} + + + + + + + + + debug + + + ${CONSOLE_LOG_PATTERN} + + UTF-8 + + + + + + + + ${log.path}/debug.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${log.path}/debug-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + debug + ACCEPT + DENY + + + + + + + ${log.path}/info.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${log.path}/info-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + info + ACCEPT + DENY + + + + + + + ${log.path}/warn.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${log.path}/warn-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + warn + ACCEPT + DENY + + + + + + + ${log.path}/error.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${log.path}/error-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + ERROR + ACCEPT + DENY + ${webHook} + ${secret} + ${appname} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/mapper/AdvVedioDao.xml b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/mapper/AdvVedioDao.xml new file mode 100644 index 0000000000..92a4993b9f --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/epmet-openapi-adv-server/src/main/resources/mapper/AdvVedioDao.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-adv/pom.xml b/epmet-openapi/epmet-openapi-adv/pom.xml new file mode 100644 index 0000000000..13490687d1 --- /dev/null +++ b/epmet-openapi/epmet-openapi-adv/pom.xml @@ -0,0 +1,21 @@ + + + + epmet-openapi + com.epmet + 2.0.0 + + pom + 4.0.0 + + epmet-openapi-adv + + + epmet-openapi-adv-client + epmet-openapi-adv-server + + + + \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/Dockerfile b/epmet-openapi/epmet-openapi-scan/Dockerfile new file mode 100644 index 0000000000..868fc70ac1 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/Dockerfile @@ -0,0 +1,11 @@ +FROM java:8 + +RUN export LANG="zh_CN.UTF-8" +RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +RUN echo 'Asia/Shanghai' > /etc/timezone + +COPY ./target/*.jar ./epmet-openapi-scan.jar + +EXPOSE 8107 + +ENTRYPOINT ["sh", "-c", "exec $RUN_INSTRUCT"] \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-dev.yml b/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-dev.yml new file mode 100644 index 0000000000..4e86ab5e89 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-dev.yml @@ -0,0 +1,18 @@ +version: "3.7" +services: + epmet-openapi-scan: + container_name: epmet-openapi-scan-dev + image: 192.168.1.130:10080/epmet-cloud-dev/epmet-openapi-scan:version_placeholder + ports: + - "8107:8107" + network_mode: host # 不会创建新的网络 + volumes: + - "/opt/epmet-cloud-logs/dev:/logs" + environment: + RUN_INSTRUCT: "java -Xms32m -Xmx200m -jar ./epmet-openapi-scan.jar" + restart: "unless-stopped" + deploy: + resources: + limits: + cpus: '0.1' + memory: 300M \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-prod.yml b/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-prod.yml new file mode 100644 index 0000000000..69873777e7 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-prod.yml @@ -0,0 +1,18 @@ +version: "3.7" +services: + epmet-openapi-scan: + container_name: epmet-openapi-scan-prod + image: registry-vpc.cn-qingdao.aliyuncs.com/epmet-cloud-master/epmet-openapi-scan:0.3.24 + ports: + - "8107:8107" + network_mode: host # 不会创建新的网络 + volumes: + - "/opt/epmet-cloud-logs/prod:/logs" + environment: + RUN_INSTRUCT: "java -Xms256m -Xmx512m -jar ./epmet-openapi-scan.jar" + restart: "unless-stopped" + deploy: + resources: + limits: + cpus: '0.1' + memory: 600M \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-test.yml b/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-test.yml new file mode 100644 index 0000000000..49ce30a8c1 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/deploy/docker-compose-test.yml @@ -0,0 +1,18 @@ +version: "3.7" +services: + epmet-openapi-scan: + container_name: epmet-openapi-scan-test + image: registry-vpc.cn-qingdao.aliyuncs.com/epmet-cloud-release/epmet-openapi-scan:version_placeholder + ports: + - "8107:8107" + network_mode: host # 不会创建新的网络 + volumes: + - "/opt/epmet-cloud-logs/test:/logs" + environment: + RUN_INSTRUCT: "java -Xms32m -Xmx200m -jar ./epmet-openapi-scan.jar" + restart: "unless-stopped" + deploy: + resources: + limits: + cpus: '0.1' + memory: 300M \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/pom.xml b/epmet-openapi/epmet-openapi-scan/pom.xml new file mode 100644 index 0000000000..b80b8a843e --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/pom.xml @@ -0,0 +1,208 @@ + + + + 4.0.0 + 0.3.24 + epmet-openapi-scan + jar + + + epmet-openapi + com.epmet + 2.0.0 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework + spring-context-support + + + org.springframework.boot + spring-boot-starter-actuator + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + com.epmet + epmet-commons-tools + 2.0.0 + + + + com.aliyun + aliyun-java-sdk-core + 4.1.1 + + + com.aliyun + aliyun-java-sdk-green + 3.5.1 + + + + org.apache.httpcomponents + httpclient + 4.5.2 + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + ${project.basedir}/src/main/java + + + true + ${basedir}/src/main/resources + + + + + + + dev + + 8107 + dev + + + + 0 + 192.168.1.130 + 6379 + 123456 + + true + 192.168.1.130:8848 + 6ceab336-d004-4acf-89c6-e121d06f4988 + + + false + + + + https://oapi.dingtalk.com/robot/send?access_token=90782b119f82a5b6bb8e0f819b6a77bbc2102b53aa2d7d2e24fa10b66d580b1c + + SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 + + + + + local + + true + + + 8107 + dev + + + + 0 + 192.168.1.130 + 6379 + 123456 + + false + 192.168.1.130:8848 + 6ceab336-d004-4acf-89c6-e121d06f4988 + + + false + + + + https://oapi.dingtalk.com/robot/send?access_token=90782b119f82a5b6bb8e0f819b6a77bbc2102b53aa2d7d2e24fa10b66d580b1c + + SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 + + + + + test + + 8107 + test + + + 0 + r-m5eoz5b6tkx09y6bpz.redis.rds.aliyuncs.com + 6379 + EpmEtrEdIs!q@w + + true + 192.168.10.150:8848 + 67e3c350-533e-4d7c-9f8f-faf1b4aa82ae + + + false + + + + https://oapi.dingtalk.com/robot/send?access_token=90782b119f82a5b6bb8e0f819b6a77bbc2102b53aa2d7d2e24fa10b66d580b1c + + SEC080aac67ff78e79fdaba132aa51e3fb3f6060dec99492feaac82cabf9f8b6a19 + + + + + + prod + + + 8107 + prod + + + 0 + r-m5ez3n1j0qc3ykq2ut.redis.rds.aliyuncs.com + 6379 + EpmEtclOUdrEdIs!Q2w + + true + 192.168.11.180:8848 + bd205d23-e696-47be-b995-916313f86e99 + + + false + + + + + + https://oapi.dingtalk.com/robot/send?access_token=a5f66c3374b1642fe2142dbf56d5997e280172d4e8f2b546c9423a68c82ece6c + + SEC95f4f40b533ad379ea6a6d1af6dd37029383cfe1b7cd96dfac2678be2c1c3ed1 + + + + + + \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/ScanApplication.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/ScanApplication.java new file mode 100644 index 0000000000..38f55211d2 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/ScanApplication.java @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + * + * https://www.renren.io + * + * 版权所有,侵权必究! + */ + +package com.epmet.openapi.scan; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +/** + * 管理后台 + * + * @author Mark sunlightcs@gmail.com + * @since 1.0.0 + */ + +@SpringBootApplication +@ComponentScan(basePackages = "com.epmet") +public class ScanApplication { + + public static void main(String[] args) { + SpringApplication.run(ScanApplication.class, args); + } + +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/aspect/RequestLogAspect.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/aspect/RequestLogAspect.java new file mode 100644 index 0000000000..ae6960a52d --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/aspect/RequestLogAspect.java @@ -0,0 +1,40 @@ +package com.epmet.openapi.scan.aspect; + +import com.epmet.commons.tools.aspect.BaseRequestLogAspect; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; + +/** + * 日志/异常处理切面实现,调用父类方法完成日志记录和异常处理。 + */ +@Aspect +@Component +@Order(0) +public class RequestLogAspect extends BaseRequestLogAspect { + + @Override + @Around(value = "execution(* com.epmet.openapi.scan.controller.*Controller*.*(..)) ") + public Object proceed(ProceedingJoinPoint point) throws Throwable { + return super.proceed(point, getRequest()); + } + + /** + * 获取Request对象 + * + * @return + */ + private HttpServletRequest getRequest() { + RequestAttributes ra = RequestContextHolder.getRequestAttributes(); + ServletRequestAttributes sra = (ServletRequestAttributes) ra; + return sra.getRequest(); + } + +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java new file mode 100644 index 0000000000..387294c23b --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java @@ -0,0 +1,30 @@ +package com.epmet.openapi.scan.common.constant; + +/** + * 系统常量 + * + * @author jianjun liu + * @date 2020-06-05 10:42 + **/ +public class SysConstant { + + public static final String UTF8 = "utf-8"; + /** + * 文本审核最大任务数 + */ + public static final Integer MAX_TASK_SIZE = 100; + + /** + * 图片审核最大任务数 + */ + public static final Integer MAX_SCAN_IMG_TASK_SIZE = 10; + + public static final String CODE = "code"; + public static final String DATA = "data"; + + + /** + * 任务正在执行中,建议您等待一段时间(例如5s)后再查询结果。 + */ + public static final int PROCESSING=280; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/CommonErrorCodeEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/CommonErrorCodeEnum.java new file mode 100644 index 0000000000..8ebed5781f --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/CommonErrorCodeEnum.java @@ -0,0 +1,68 @@ +package com.epmet.openapi.scan.common.enu; + +import com.epmet.commons.tools.constant.StrConstant; + +/** + * 公共错误码 + * + * @author yinzuomei@elink-cn.com + * @date 2021/1/10 19:43 + */ +public enum CommonErrorCodeEnum { + OK(200, "请求成功。"), + PROCESSING(280, "任务正在执行中,建议您等待一段时间(例如5s)后再查询结果。"), + BAD_REQUEST(400, "请求有误,通常由于请求参数不正确导致,请仔细检查请求参数。"), + NOT_ALLOWED(401, "请求失败,通常是由于使用了不安全的图片、视频、语音链接地址。"), + FORBIDDEN(403, "请求访问失败,通常由于您的图片、视频、语音链接无法访问导致,请确认公网是否可访问,并且无防盗链策略。"), + NOT_FOUND(404, "待检测内容未找到,通常是由于您的图片、视频、语音内容无法下载导致,请确认内容可通过公网访问到。"), + DOWNLOAD_FAILED(480, "下载失败,请确认待检测内容的大小、分辨率(如果有)在API的限制范围内。"), + GENERAL_ERROR(500, "一般是服务端临时出错。建议重试,若持续返回该错误码,请通过工单联系我们。"), + DB_FAILED(580, "数据库操作失败。建议重试,若持续返回该错误码,请通过工单联系我们。"), + TIMEOUT(581, "超时。建议重试,若持续返回该错误码,请通过工单联系我们。"), + CACHE_FAILED(585, "缓存出错。建议重试,若持续返回该错误码,请通过工单联系我们。"), + ALGO_FAILED(586, "算法出错。请通过工单联系我们。"), + MQ_FAILED(587, "中间件出错。请通过工单联系我们。"), + EXCEED_QUOTA(588, "请求频率超出配额。默认配额:图片检测50张/秒,视频检测20路/秒,语音检测20路/秒,文本检测100条/秒。如果需要调整配额,请通过工单联系我们。"), + TOO_LARGE(589, "待检测内容过大,请确保检测的内容在API的限制范围内。建议重试,若持续返回该错误码,请通过工单联系我们。"), + BAD_FORMAT(590, "待检测内容格式错误,请确保检测的内容在API的限制范围内。"), + CONNECTION_POOL_FULL(591, "连接池满。请通过工单联系我们。"), + DOWNLOAD_TIMEOUT(592, "下载超时,下载时间限制为3s,请确保检测的内容大小在API的限制范围内。"), + EXPIRED(594, "任务过期,如taskId过期。"), + CATCH_FRAME_FAILED(595, "截帧失败,请通过工单联系我们。"), + PERMISSION_DENY(596, "账号未授权、账号欠费、账号未开通、账号被禁等原因,具体可以参考返回的msg。"); + + + private Integer code; + private String desc; + + CommonErrorCodeEnum(Integer code, String desc) { + this.code = code; + this.desc = desc; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + public static String getErrorMsg(Integer value) { + CommonErrorCodeEnum[] codeEnums = values(); + for (CommonErrorCodeEnum commonErrorCodeEnum : codeEnums) { + if (commonErrorCodeEnum.getCode().equals(value)) { + return commonErrorCodeEnum.getDesc(); + } + } + return StrConstant.EPMETY_STR; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/ImgSceneEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/ImgSceneEnum.java new file mode 100644 index 0000000000..cfb8d77ac2 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/ImgSceneEnum.java @@ -0,0 +1,47 @@ +package com.epmet.openapi.scan.common.enu; + +import java.util.ArrayList; +import java.util.List; + +/** + * desc:图片检测场景 + * @author jianjun liu + * @date 2020-06-04 21:39 + **/ +public enum ImgSceneEnum { + PORN("porn", "图片智能鉴黄"), + TERRORISM("terrorism", "图片暴恐涉政识别"); + + private String code; + private String desc; + + ImgSceneEnum(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public static List getImgSceneList() { + List result = new ArrayList<>(); + ImgSceneEnum[] values = ImgSceneEnum.values(); + for (ImgSceneEnum v : values) { + result.add(v.getCode()); + } + return result; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/LabelEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/LabelEnum.java new file mode 100644 index 0000000000..7ad96f3171 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/LabelEnum.java @@ -0,0 +1,66 @@ +package com.epmet.openapi.scan.common.enu; + +import java.util.ArrayList; +import java.util.List; + +/** + * 阿里检测结果的分类字典 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/18 14:04 + */ +public enum LabelEnum { + NORMAL("normal", "正常文本"), + SPAM("spam", "含垃圾信息"), + AD("ad", "广告"), + POLITICS("politics","涉政"), + TERRORISM("terrorism","暴恐"), + ABUSE("abuse","辱骂"), + PORN("porn","色情"), + FLOOD("flood","灌水"), + CONTRABAND("contraband","违禁"), + MEANINGLESS("meaningless","无意义"), + CUSTOMIZED("customized","自定义"); + + private String code; + private String desc; + + LabelEnum(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public static List getLabelEnumList() { + List result = new ArrayList<>(); + LabelEnum[] values = LabelEnum.values(); + for (LabelEnum v : values) { + result.add(v.getCode()); + } + return result; + } + + public static String getDesc(String code) { + LabelEnum[] businessModeEnums = values(); + for (LabelEnum labelEnum : businessModeEnums) { + if (labelEnum.getCode().equals(code)) { + return labelEnum.getDesc(); + } + } + return ""; + } + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/RegionIdEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/RegionIdEnum.java new file mode 100644 index 0000000000..e1dbd5897b --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/RegionIdEnum.java @@ -0,0 +1,49 @@ +package com.epmet.openapi.scan.common.enu; + +/** + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-04 21:39 + **/ +public enum RegionIdEnum { + SHANG_HAI("cn-shanghai","green.cn-shanghai.aliyuncs.com"), + BEI_JING("cn-beijing","green.cn-beijing.aliyuncs.com"), + AP_SOUTHEAST_1("ap-southeast-1","green.ap-southeast-1.aliyuncs.com"), + US_WEST_1("us-west-1","green.us-west-1.aliyuncs.com"); + + private String regionId; + private String domain; + RegionIdEnum(String regionId, String domain){ + this.regionId = regionId; + this.domain = domain; + } + + public static String getDoMain(String regionId){ + if (regionId == null) { + return SHANG_HAI.getDomain(); + } + RegionIdEnum[] values = RegionIdEnum.values(); + for (RegionIdEnum v : values) { + if (regionId.equals(v.getDomain())) { + return v.getDomain(); + } + } + return SHANG_HAI.getDomain(); + } + + public String getRegionId() { + return regionId; + } + + public void setRegionId(String regionId) { + this.regionId = regionId; + } + + public String getDomain() { + return domain; + } + + public void setDomain(String domain) { + this.domain = domain; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SuggestionEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SuggestionEnum.java new file mode 100644 index 0000000000..3881508341 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SuggestionEnum.java @@ -0,0 +1,48 @@ +package com.epmet.openapi.scan.common.enu; + +import java.util.ArrayList; +import java.util.List; + +/** + * desc:检测建议 + * @author jianjun liu + * @date 2020-06-04 21:39 + **/ +public enum SuggestionEnum { + PASS("pass", "正常"), + REVIEW("review", "需要人工审核"), + BLOCK("block", "内容违规"); + + private String code; + private String desc; + + SuggestionEnum(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public static List getImgSceneList() { + List result = new ArrayList<>(); + SuggestionEnum[] values = SuggestionEnum.values(); + for (SuggestionEnum v : values) { + result.add(v.getCode()); + } + return result; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java new file mode 100644 index 0000000000..f906186333 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java @@ -0,0 +1,46 @@ +package com.epmet.openapi.scan.common.enu; + +/** + * @author jianjun liu + * @date 2020-06-04 21:39 + **/ +public enum SysResponseEnum { + /** + * + * 业务代码枚举类 + * + * 编码样式:【CCCBBOOXX】 + * 编码示例说明: + * CCC 中心编码&业务系统 (110-内容扫描服务中心服务) + * BB 业务类型(00-默认 ) + * OO 操作类型(00-默认) + * XX 具体编码(00-成功,01-失败,02-参数错误,10-异常 99-系统错误) + * + */ + /*通用枚举 */ + EXCEPTION(10001,"系统异常"), + THIRD_PLATFORM_SERVER_ERROR(10002,"第三方检测服务异常,请稍候重试"), + THIRD_PLATFORM_RESP_STATUS_ERROR(10003,"第三方检测服务响应异常,请稍候重试"), + THIRD_PLATFORM_RESP_CODE_ERROR(10004,"第三方检测服务检测异常,请稍候重试"), + + + /*审核内容 业务 01*/ + SCAN_TASK_LIST_PARAM_ERROR(110010001,"任务列表长度超过限制"), + SCAN_PARAM_ERROR(110010002,"参数格式不正确"), + ; + + private Integer code; + private String msg; + SysResponseEnum(Integer code, String msg){ + this.code = code; + this.msg = msg; + } + + public Integer getCode() { + return code; + } + + public String getMsg() { + return msg; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/TextSceneEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/TextSceneEnum.java new file mode 100644 index 0000000000..263d6e25ed --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/TextSceneEnum.java @@ -0,0 +1,46 @@ +package com.epmet.openapi.scan.common.enu; + +import java.util.ArrayList; +import java.util.List; + +/** + * desc:文本检测场景 + * @author jianjun liu + * @date 2020-06-04 21:39 + **/ +public enum TextSceneEnum { + ANTISPAM("antispam", "文本垃圾内容检测"); + + private String code; + private String desc; + + TextSceneEnum(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public static List getTextSceneList() { + List result = new ArrayList<>(); + TextSceneEnum[] values = TextSceneEnum.values(); + for (TextSceneEnum v : values) { + result.add(v.getCode()); + } + return result; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VideoSceneEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VideoSceneEnum.java new file mode 100644 index 0000000000..864d137dd2 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VideoSceneEnum.java @@ -0,0 +1,50 @@ +package com.epmet.openapi.scan.common.enu; + +import java.util.ArrayList; +import java.util.List; + +/** + * desc:视频检测场景 + * @author yinzuomei@elink-cn.com + * @date 2020/12/29 13:47 + **/ +public enum VideoSceneEnum { + PORN("porn", "视频智能鉴黄"), + TERRORISM("terrorism", "视频暴恐涉政"), + LIVE("live","视频不良场景"), + LOGO("logo","视频logo"), + AD("ad","视频图文违规"); + + private String code; + private String desc; + + VideoSceneEnum(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public static List getVideoSceneList() { + List result = new ArrayList<>(); + VideoSceneEnum[] values = VideoSceneEnum.values(); + for (VideoSceneEnum v : values) { + result.add(v.getCode()); + } + return result; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VoiceSceneEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VoiceSceneEnum.java new file mode 100644 index 0000000000..777b92f0d7 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/VoiceSceneEnum.java @@ -0,0 +1,47 @@ +package com.epmet.openapi.scan.common.enu; + +import java.util.ArrayList; +import java.util.List; + +/** + * 语音异步检测场景 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/9 10:12 + */ +public enum VoiceSceneEnum { + ANTISPAM("antispam", "检测场景,取值:antispam"); + + private String code; + private String desc; + + VoiceSceneEnum(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public static List getVoiceSceneList() { + List result = new ArrayList<>(); + VoiceSceneEnum[] values = VoiceSceneEnum.values(); + for (VoiceSceneEnum v : values) { + result.add(v.getCode()); + } + return result; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExecuteHttpException.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExecuteHttpException.java new file mode 100644 index 0000000000..a5694da79c --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExecuteHttpException.java @@ -0,0 +1,29 @@ +package com.epmet.openapi.scan.common.exception; + +import com.epmet.openapi.scan.common.enu.SysResponseEnum; + +/** + * @author jianjun liu + * @date 2020-06-05 10:31 + **/ +public class ExecuteHttpException extends RuntimeException { + private int code; + private String msg; + + public ExecuteHttpException(String msg) { + this(SysResponseEnum.EXCEPTION.getCode(), msg); + } + + public ExecuteHttpException(int code, String msg) { + this.code = code; + this.msg = msg; + } + + public int getCode() { + return code; + } + + public String getMsg() { + return msg; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/redis/RedisKeys.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/redis/RedisKeys.java new file mode 100644 index 0000000000..2939bd62eb --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/redis/RedisKeys.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + *

+ * https://www.renren.io + *

+ * 版权所有,侵权必究! + */ + +package com.epmet.openapi.scan.common.redis; + +/** + * @author Mark sunlightcs@gmail.com + * @since 1.0.0 + */ +public class RedisKeys { + + /** + * 党群e事通redis前缀 + */ + private static String rootPrefix = "epmet:"; + + /** + * desc:白名单Key + * @return + */ + public static String getWhiteList () { + return rootPrefix.concat("openapi:scan:whitelist"); + } + + /** + * desc: 语音检测任务,异步回调,需要根据taskId获取存储seed的Key + * @param taskId 提交检测任务API接口返回的taskId eg:1001 + * @return epmet:openapi:scan:voice:seed:1001 + */ + public static String getVoiceScanSeedKey(String taskId){ + return rootPrefix.concat("openapi:scan:voice:seed:").concat(taskId); + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/HttpClientManager.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/HttpClientManager.java new file mode 100644 index 0000000000..7ca0302331 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/HttpClientManager.java @@ -0,0 +1,171 @@ +package com.epmet.openapi.scan.common.util; + +import com.alibaba.fastjson.JSON; +import com.epmet.commons.tools.utils.Result; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.apache.http.HttpStatus; +import org.apache.http.NameValuePair; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; +import org.springframework.util.CollectionUtils; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * desc: http 工具类 + * date: 2020/6/4 22:27 + * + * @author: jianjun liu + */ +@Slf4j +public class HttpClientManager { + private static int connectionTimeout = 3000;// 连接超时时间,毫秒 + private static int soTimeout = 10000;// 读取数据超时时间,毫秒 + /** + * HttpClient对象 + */ + private static CloseableHttpClient httpclient = HttpClients.custom().disableAutomaticRetries().build(); + + /*** 超时设置 ****/ + private static RequestConfig requestConfig = RequestConfig.custom() + .setSocketTimeout(soTimeout) + .setConnectTimeout(connectionTimeout) + .build();//设置请求和传输超时时间 + + public static HttpClientManager getInstance() { + return SingleClass.instance; + } + + private static class SingleClass { + private final static HttpClientManager instance = new HttpClientManager(); + } + + /** + * desc: 发送json post 请求 + * param: url,jsonStrParam + * return: Result + * date: 2019/2/21 9:12 + * + * @author: jianjun liu + */ + public Result sendPost(String url, Map paramsMap) { + + try { + HttpPost httppost = new HttpPost(url); + httppost.setConfig(requestConfig); + httppost.addHeader("Content-Type", "application/x-www-form-urlencoded charset=utf-8"); + + List list = new ArrayList(); + for (String key : paramsMap.keySet()) { + list.add(new BasicNameValuePair(key, String.valueOf(paramsMap.get(key)))); + } + UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(list, "utf-8"); + httppost.setEntity(urlEncodedFormEntity); + + return execute(httppost); + } catch (Exception e) { + e.printStackTrace(); + log.error("send exception", e); + return new Result().error(8000, e.getMessage()); + } + + } + + /** + * desc: 发送json post 请求 + * param: url,jsonStrParam + * return: Result + * date: 2019/2/21 9:12 + * + * @author: jianjun liu + */ + public Result sendPostByJSON(String url, String jsonStrParam) { + + try { + HttpPost httppost = new HttpPost(url); + httppost.setConfig(requestConfig); + httppost.addHeader("Content-Type", "application/json; charset=utf-8"); + if (StringUtils.isNotEmpty(jsonStrParam)) { + StringEntity se = new StringEntity(jsonStrParam, "utf-8"); + httppost.setEntity(se); + } + return execute(httppost); + } catch (Exception e) { + e.printStackTrace(); + log.error("send exception", e); + return new Result().error(8000, e.getMessage()); + } + + } + + /** + * desc: 发送get请求 + * param:url, params + * return: Result + * date: 2019/2/21 9:16 + * + * @author: jianjun liu + */ + public Result sendGet(String url, Map params) { + + try { + URIBuilder builder = new URIBuilder(url); + if (!CollectionUtils.isEmpty(params)) { + Set set = params.keySet(); + for (String key : set) { + builder.setParameter(key, params.get(key) == null ? "" : String.valueOf(params.get(key))); + } + } + HttpGet httpGet = new HttpGet(builder.build()); + httpGet.setConfig(requestConfig); + return execute(httpGet); + } catch (Exception e) { + log.error("sendGet exception", e); + return new Result().error(8000, e.getMessage()); + } + } + + private Result execute(HttpRequestBase httpMethod) { + CloseableHttpResponse response = null; + try { + response = httpclient.execute(httpMethod); + log.debug("http send response:{}", JSON.toJSONString(response)); + if (response != null && response.getStatusLine() != null) { + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + String result = EntityUtils.toString(response.getEntity()); + return new Result().ok(result); + } else { + log.warn("execute http method fail,httpStatus:{0}", response.getStatusLine().getStatusCode()); + } + } + } catch (Exception e) { + log.error("execute exception", e); + } finally { + httpMethod.releaseConnection(); + try { + if (response != null) { + response.close(); + } + } catch (IOException e) { + } + } + return new Result().error(8000, "系统异常"); + } +} + + diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/IAcsClientUtil.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/IAcsClientUtil.java new file mode 100644 index 0000000000..c0c8362727 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/IAcsClientUtil.java @@ -0,0 +1,67 @@ +package com.epmet.openapi.scan.common.util; + +/** + * @author jianjun liu + * @date 2020-06-05 10:03 + **/ + +import com.aliyuncs.DefaultAcsClient; +import com.aliyuncs.IAcsClient; +import com.aliyuncs.exceptions.ClientException; +import com.aliyuncs.profile.DefaultProfile; +import com.aliyuncs.profile.IClientProfile; +import com.epmet.openapi.scan.common.enu.RegionIdEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; + +@Slf4j +@Component +public class IAcsClientUtil { + private static String accessKeyId; + private static String secret; + private static String product = "Green"; + + private static String regionId; + private static String endpointName = ""; + + private static IClientProfile profile; + + + @PostConstruct + private void initProFile() { + profile = DefaultProfile.getProfile(regionId, accessKeyId, secret); + try { + DefaultProfile.addEndpoint(endpointName, regionId, product, RegionIdEnum.getDoMain(regionId)); + } catch (ClientException e) { + log.error("initProFile exception", e.getMessage()); + } + } + + + public static IAcsClient getIAcsClient() { + return new DefaultAcsClient(profile); + } + + @Value("${aliyun.green.accessKeyId}") + public void setAccessKeyId(String accessKeyId) { + IAcsClientUtil.accessKeyId = accessKeyId; + } + + @Value("${aliyun.green.accessKeySecret}") + public void setSecret(String secret) { + IAcsClientUtil.secret = secret; + } + + @Value("${aliyun.green.regionId}") + public void setRegionId(String regionId) { + IAcsClientUtil.regionId = regionId; + } + + @Value("${aliyun.green.regionId}") + public void setEndpointName(String endpointName) { + IAcsClientUtil.endpointName = endpointName; + } +} \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/MapUtil.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/MapUtil.java new file mode 100644 index 0000000000..e98dbfd7a2 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/MapUtil.java @@ -0,0 +1,55 @@ +package com.epmet.openapi.scan.common.util; + +import org.apache.commons.lang3.StringUtils; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author jianjun liu + * @date 2020-06-05 16:44 + **/ +public class MapUtil { + /** + * 将url参数转换成map + * + * @param param aa=11&bb=22&cc=33 + * @return + */ + public static Map getUrlParams(String param) { + Map map = new HashMap<>(0); + if (StringUtils.isBlank(param)) { + return map; + } + String[] params = param.split("&"); + for (int i = 0; i < params.length; i++) { + String[] p = params[i].split("="); + if (p.length == 2) { + map.put(p[0], p[1]); + } + } + return map; + } + + /** + * 将map转换成url + * + * @param map + * @return + */ + public static String getUrlParamsByMap(Map map) { + if (map == null) { + return ""; + } + StringBuffer sb = new StringBuffer(); + for (Map.Entry entry : map.entrySet()) { + sb.append(entry.getKey() + "=" + entry.getValue()); + sb.append("&"); + } + String s = sb.toString(); + if (s.endsWith("&")) { + s = StringUtils.substringBeforeLast(s, "&"); + } + return s; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/ModuleConfigImpl.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/ModuleConfigImpl.java new file mode 100644 index 0000000000..68532b7819 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/ModuleConfigImpl.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + * + * https://www.renren.io + * + * 版权所有,侵权必究! + */ + +package com.epmet.openapi.scan.config; + +import com.epmet.commons.tools.config.ModuleConfig; +import org.springframework.stereotype.Service; + +/** + * 模块配置信息 + * + * @author Mark sunlightcs@gmail.com + * @since 1.0.0 + */ +@Service +public class ModuleConfigImpl implements ModuleConfig { + @Override + public String getName() { + return "epmetscan"; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/WebAppConfig.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/WebAppConfig.java new file mode 100644 index 0000000000..c955a7f555 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/WebAppConfig.java @@ -0,0 +1,31 @@ +package com.epmet.openapi.scan.config; + +import com.epmet.openapi.scan.interceptor.ScanApiAuthInterceptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-08 14:30 + **/ + + @Configuration + public class WebAppConfig implements WebMvcConfigurer{ + @Autowired + private ScanApiAuthInterceptor scanApiAuthInterceptor; + + // 多个拦截器组成一个拦截器链 + // addPathPatterns 用于添加拦截规则 + // excludePathPatterns 用户排除拦截 + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(scanApiAuthInterceptor)//添加拦截器 + .addPathPatterns("/**") //拦截所有请求 + .excludePathPatterns("/opback/**");//对应的不拦截的请求 + } + } + diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/BackDoorController.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/BackDoorController.java new file mode 100644 index 0000000000..433ff1b06d --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/BackDoorController.java @@ -0,0 +1,32 @@ +package com.epmet.openapi.scan.controller; + +import com.alibaba.fastjson.JSON; +import com.epmet.openapi.scan.common.redis.RedisKeys; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.SetOperations; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Set; + +/** + * @author jianjun liu + * @date 2020-06-04 20:39 + **/ +@RestController +@RequestMapping("opback") +public class BackDoorController { + @Autowired + private RedisTemplate redisTemplate; + + @RequestMapping("addWhite") + public String addWhite(@RequestParam String ip) { + SetOperations setOperations = redisTemplate.opsForSet(); + String whiteList = RedisKeys.getWhiteList(); + Long add = setOperations.add(whiteList, ip); + Set members = setOperations.members(whiteList); + return "ip:" + ip + "添加" + (add > 0 ? "成功" : "失败") + ",当前所有列表:" + JSON.toJSONString(members); + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java new file mode 100644 index 0000000000..cee27d28b8 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java @@ -0,0 +1,116 @@ +package com.epmet.openapi.scan.controller; + +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.openapi.scan.common.constant.SysConstant; +import com.epmet.openapi.scan.common.enu.SysResponseEnum; +import com.epmet.openapi.scan.service.impl.ScanService; +import com.epmet.openapi.scan.support.param.ImgScanParam; +import com.epmet.openapi.scan.support.param.TextScanParam; +import com.epmet.openapi.scan.support.param.VoiceAsyncScanParam; +import com.epmet.openapi.scan.support.param.video.VideoAsyncScanParam; +import com.epmet.openapi.scan.support.result.ImgAsyncScanResult; +import com.epmet.openapi.scan.support.result.SyncScanResult; +import com.epmet.openapi.scan.support.result.VoiceAsyncScanResult; +import com.epmet.openapi.scan.support.result.VoiceAsyncScanTaskResult; +import com.epmet.openapi.scan.support.result.video.VideoAsyncScanTaskResultDTO; +import com.epmet.openapi.scan.support.result.video.VideoResultDTO; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-05 10:39 + **/ +@RestController +@RequestMapping("api") +public class ScanController { + + @Autowired + private ScanService scanService; + + /** + * desc:图片同步检测接口 + * + * @param param + * @return + */ + @RequestMapping("imgSyncScan") + public Result ImgSyncScan(@RequestBody ImgScanParam param) { + ValidatorUtils.validateEntity(param); + return scanService.sendSyncImgScan(param); + } + + /** + * desc:文本同步检测接口 + * + * @param param + * @return + */ + @RequestMapping("textSyncScan") + public Result textSyncScan(@RequestBody TextScanParam param) { + ValidatorUtils.validateEntity(param); + return scanService.sendTextScan(param); + } + + //@RequestMapping("imgAsyncScan") + public Result ImgAsyncScan(@RequestBody ImgScanParam param) { + return null;//scanService.sendASyncImgScan(param); + } + + + /** + * @description 语音异步检测 + * @Date 2020/12/9 9:14 + **/ + @PostMapping("voiceAsyncScan") + public Result voiceAsyncScan(@RequestBody VoiceAsyncScanParam param){ + ValidatorUtils.validateEntity(param); + return scanService.sendVoiceAsyncScan(param); + } + + /** + * @param taskIds 要查询的异步检测任务的taskId列表。数组中的元素个数不超过100个 + * @author yinzuomei + * @description 语音异步检测结果查询 + * @Date 2020/12/9 11:16 + **/ + @PostMapping("voiceResults") + public Result> voiceResults(@RequestBody List taskIds){ + return scanService.voiceResults(taskIds); + } + + /** + * @author yinzuomei + * @description 视频检测-异步检测 + **/ + @PostMapping("videoAsyncScan") + public Result videoAsyncScan(@RequestBody VideoAsyncScanParam param) { + ValidatorUtils.validateEntity(param); + return scanService.videoAsyncScan(param); + } + + /** + * @author yinzuomei + * @description 视频异步检测结果查询接口 + **/ + @PostMapping("videoResults") + public Result videoResults(@RequestBody List taskIds) { + if (CollectionUtils.isEmpty(taskIds)) { + return new Result<>(); + } + //检测对象不能为空,且最多支持100个元素 + if (org.springframework.util.CollectionUtils.isEmpty(taskIds) || taskIds.size() > SysConstant.MAX_TASK_SIZE) { + return new Result().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), + SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg().concat(SysConstant.MAX_TASK_SIZE.toString())); + } + return scanService.videoResults(taskIds); + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiAuthInterceptor.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiAuthInterceptor.java new file mode 100644 index 0000000000..6ce851a45e --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiAuthInterceptor.java @@ -0,0 +1,60 @@ +package com.epmet.openapi.scan.interceptor; + +import com.alibaba.fastjson.JSON; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.utils.IpUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.openapi.scan.common.redis.RedisKeys; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.SetOperations; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerInterceptor; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * @author jianjun liu + * @date 2020-06-05 16:36 + **/ +@Component +public class ScanApiAuthInterceptor implements HandlerInterceptor { + private static final Logger log = LoggerFactory.getLogger(ScanApiAuthInterceptor.class); + @Autowired + private RedisTemplate redisTemplate; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + String ip = IpUtils.getIpAddr(request); + SetOperations setOperations = redisTemplate.opsForSet(); + if (!setOperations.isMember(RedisKeys.getWhiteList(), ip)) { + log.warn("preHandle ip:{} is not in whitelist", ip); + String result = JSON.toJSONString(new Result<>().error(EpmetErrorCode.ERR401.getCode(), EpmetErrorCode.ERR401.getMsg())); + responseJson(response, result); + return false; + } + return true; + } + + private void responseJson(HttpServletResponse response, String json) throws Exception { + PrintWriter writer = null; + response.setCharacterEncoding("UTF-8"); + response.setContentType("text/json; charset=utf-8"); + try { + writer = response.getWriter(); + writer.print(json); + } catch (IOException e) { + log.error(e.toString()); + } finally { + if (writer != null) { + writer.close(); + } + } + } + +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanService.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanService.java new file mode 100644 index 0000000000..4a3e734893 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanService.java @@ -0,0 +1,69 @@ +package com.epmet.openapi.scan.service.impl; + +import com.epmet.commons.tools.utils.Result; +import com.epmet.openapi.scan.support.param.ImgScanParam; +import com.epmet.openapi.scan.support.param.TextScanParam; +import com.epmet.openapi.scan.support.param.VoiceAsyncScanParam; +import com.epmet.openapi.scan.support.param.video.VideoAsyncScanParam; +import com.epmet.openapi.scan.support.result.SyncScanResult; +import com.epmet.openapi.scan.support.result.VoiceAsyncScanResult; +import com.epmet.openapi.scan.support.result.VoiceAsyncScanTaskResult; +import com.epmet.openapi.scan.support.result.video.VideoAsyncScanTaskResultDTO; +import com.epmet.openapi.scan.support.result.video.VideoResultDTO; + +import java.util.List; + +/** + * desc:内容扫描接口 + * + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-05 13:12 + **/ +public interface ScanService { + /** + * desc:扫描文本内容 同步 + * @param textScanParam + * @return ImgAsyncScanResult + */ + public Result sendTextScan(TextScanParam textScanParam); + + + /** + * desc:扫描图片内容 同步 + * @param imgScanParam + * @return + */ + public Result sendSyncImgScan(ImgScanParam imgScanParam); + + /** + * 语音异步检测 + * + * @param param + * @return com.epmet.openapi.scan.support.result.VoiceAsyncScanTaskResult + */ + Result sendVoiceAsyncScan(VoiceAsyncScanParam param); + + /** + * 语音异步检测结果查询 + * + * @param taskIds 要查询的异步检测任务的taskId列表。数组中的元素个数不超过100个 + * @return com.epmet.openapi.scan.support.result.VoiceAsyncScanResult + */ + Result> voiceResults(List taskIds); + + /** + * desc:视频检测-异步检测 + * @param videoAsyncScanParam + * @return 异步检测)返回数据:taskId<=>dataId + */ + Result videoAsyncScan(VideoAsyncScanParam videoAsyncScanParam); + + /** + * @param taskIds + * @author yinzuomei + * @description 视频异步检测结果查询接口 + * @Date 2020/12/29 16:10 + **/ + Result videoResults(List taskIds); +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java new file mode 100644 index 0000000000..44dd0da3de --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java @@ -0,0 +1,734 @@ +package com.epmet.openapi.scan.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.aliyuncs.AcsRequest; +import com.aliyuncs.green.model.v20180509.*; +import com.aliyuncs.http.FormatType; +import com.aliyuncs.http.HttpResponse; +import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.aliyuncs.http.MethodType; +import com.epmet.commons.tools.utils.Result; +import com.epmet.openapi.scan.common.constant.SysConstant; +import com.epmet.openapi.scan.common.enu.*; +import com.epmet.openapi.scan.common.exception.ExecuteHttpException; +import com.epmet.openapi.scan.common.redis.RedisKeys; +import com.epmet.openapi.scan.common.util.IAcsClientUtil; +import com.epmet.openapi.scan.support.param.*; +import com.epmet.openapi.scan.support.param.video.VideoAsyncScanParam; +import com.epmet.openapi.scan.support.param.video.VideoAsyncScanTask; +import com.epmet.openapi.scan.support.result.*; +import com.epmet.openapi.scan.support.result.video.*; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.ListUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpStatus; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-05 13:16 + **/ +@Slf4j +@Service +public class ScanServiceImpl implements ScanService { + @Value("${aliyun.green.regionId}") + private String regionId; + @Value("${aliyun.green.bizType}") + private String bizType; + @Autowired + private RedisTemplate redisTemplate; + @Override + public Result sendTextScan(TextScanParam textScanParam) { + //默认参数 + // 鉴黄 暴恐涉政 + textScanParam.setScenes(TextSceneEnum.getTextSceneList()); + textScanParam.setBizType(bizType); + + List textTasks = textScanParam.getTasks(); + if (CollectionUtils.isEmpty(textTasks) || textTasks.size() > SysConstant.MAX_TASK_SIZE) { + return new Result().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg().concat(SysConstant.MAX_TASK_SIZE.toString())); + } + + TextScanRequest textScanRequest = getTextScanRequest(); + + try { + textScanRequest.setHttpContent(JSON.toJSONString(textScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); + } catch (UnsupportedEncodingException e) { + log.error("sendTextScan parse param exception", e); + return new Result().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); + } + + try { + SyncScanResult textScanResult = executeSyncText(textScanRequest); + return new Result().ok(textScanResult); + } catch (ExecuteHttpException e) { + log.error("sendTextScan execute Exception", e); + return new Result().error(e.getCode(), e.getMsg()); + } + } + + private TextScanRequest getTextScanRequest() { + TextScanRequest textScanRequest = new TextScanRequest(); + textScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式 + textScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法 + textScanRequest.setEncoding(SysConstant.UTF8); + textScanRequest.setRegionId(regionId); + textScanRequest.setConnectTimeout(3000); + textScanRequest.setReadTimeout(6000); + return textScanRequest; + } + + @Override + public Result sendSyncImgScan(ImgScanParam imgScanParam) { + //默认参数 + // 鉴黄 暴恐涉政 + imgScanParam.setScenes(ImgSceneEnum.getImgSceneList()); + imgScanParam.setBizType(bizType); + + List imgTasks = imgScanParam.getTasks(); + if (CollectionUtils.isEmpty(imgTasks) || imgTasks.size() > SysConstant.MAX_TASK_SIZE) { + return new Result().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg().concat(SysConstant.MAX_TASK_SIZE.toString())); + } + if (imgTasks.size() <= SysConstant.MAX_SCAN_IMG_TASK_SIZE) { + return doScanImg(imgScanParam); + } + log.info("sendSyncImgScan tasks size:{} over 10", imgTasks.size()); + List> partition = ListUtils.partition(imgTasks, SysConstant.MAX_SCAN_IMG_TASK_SIZE); + SyncScanResult finalResult = new SyncScanResult(); + for (List tasks : partition) { + ImgScanParam scanParam = new ImgScanParam(); + scanParam.setBizType(imgScanParam.getBizType()); + scanParam.setScenes(imgScanParam.getScenes()); + scanParam.setTasks(tasks); + scanParam.setCallback(imgScanParam.getCallback()); + scanParam.setSeed(imgScanParam.getSeed()); + Result partResult = doScanImg(scanParam); + try { + Thread.sleep(5L); + } catch (InterruptedException e) { + log.error("sendSyncImgScan InterruptedException"); + } + if (partResult.success()) { + SyncScanResult data = partResult.getData(); + finalResult.getSuccessDataIds().addAll(data.getSuccessDataIds()); + finalResult.getFailDataIds().addAll(data.getFailDataIds()); + finalResult.getDetails().addAll(data.getDetails()); + } else { + return partResult; + } + } + return new Result().ok(finalResult); + + + } + + private Result doScanImg(ImgScanParam imgScanParam) { + ImageSyncScanRequest imageSyncScanRequest = getImgScanRequest(); + try { + imageSyncScanRequest.setHttpContent(JSON.toJSONString(imgScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); + } catch (UnsupportedEncodingException e) { + log.error("sendSyncImgScan parse param exception", e); + return new Result().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); + } + + try { + SyncScanResult scanResult = executeSyncImg(imageSyncScanRequest); + return new Result().ok(scanResult); + } catch (ExecuteHttpException e) { + log.error("sendImgScan execute exception,param:{},fail msg:{}", JSON.toJSONString(imgScanParam), e.getMsg()); + return new Result().error(e.getCode(), e.getMsg()); + } + } + + private ImageSyncScanRequest getImgScanRequest() { + ImageSyncScanRequest imageSyncScanRequest = new ImageSyncScanRequest(); + imageSyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式 + imageSyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法 + imageSyncScanRequest.setEncoding(SysConstant.UTF8); + imageSyncScanRequest.setRegionId(regionId); + imageSyncScanRequest.setConnectTimeout(3000); + imageSyncScanRequest.setReadTimeout(6000); + return imageSyncScanRequest; + } + + public SyncScanResult executeSyncText(AcsRequest textScanRequest) { + SyncScanResult result = new SyncScanResult(); + try { + HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(textScanRequest); + + if (httpResponse.isSuccess()) { + JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), SysConstant.UTF8)); + if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { + //任务 列表 + List scanTaskResults = scrResponse.getJSONArray(SysConstant.DATA).toJavaList(ScanTaskResult.class); + for (ScanTaskResult taskResult : scanTaskResults) { + result.getDetails().add(taskResult); + //又根据场景不同 + if (HttpStatus.SC_OK != taskResult.getCode()) { + if (!result.getFailDataIds().contains(taskResult.getDataId())) { + result.getFailDataIds().add(taskResult.getDataId()); + log.warn("executeSyncText task process fail:code:{},result:{}", taskResult.getCode(), JSON.toJSONString(taskResult)); + } + continue; + } + //如果是多个场景 则为对个 BaseScanResult + List sceneResults = taskResult.getResults(); + //是文本检测 目前就一种场景 + boolean isSuccess = true; + for (SceneDetailResult sceneResult : sceneResults) { + String suggestion = sceneResult.getSuggestion(); + if (SuggestionEnum.BLOCK.getCode().equals(suggestion)) { + isSuccess = false; + break; + } + } + if (isSuccess) { + result.getSuccessDataIds().add(taskResult.getDataId()); + } else { + log.warn("executeSyncText dataId:{} block:{}", taskResult.getDataId(), JSON.toJSONString(taskResult.getResults())); + result.getFailDataIds().add(taskResult.getDataId()); + } + } + return result; + } else { + log.warn("executeSyncText response not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); + } + } else { + log.warn("executeSyncText response status is not success. httpResponse:{}", JSON.toJSONString(httpResponse)); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); + } + } catch (Exception e) { + log.error("executeSyncText exception IAcsClientUtil do action exception", e); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getMsg()); + } + } + + private SyncScanResult executeSyncImg(AcsRequest request) { + SyncScanResult result = new SyncScanResult(); + try { + HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(request); + if (httpResponse.isSuccess()) { + JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), SysConstant.UTF8)); + if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { + JSONArray taskResults = scrResponse.getJSONArray(SysConstant.DATA); + List scanTaskResults = taskResults.toJavaList(ScanTaskResult.class); + for (ScanTaskResult taskResult : scanTaskResults) { + result.getDetails().add(taskResult); + if (HttpStatus.SC_OK != taskResult.getCode()) { + if (!result.getFailDataIds().contains(taskResult.getDataId())) { + result.getFailDataIds().add(taskResult.getDataId()); + log.warn("executeSyncImg detect not success. code:{},result:{}", taskResult.getCode(), JSON.toJSONString(taskResult)); + } + continue; + } + //如果是多个场景 则为对个 BaseScanResult + List sceneResults = taskResult.getResults(); + + boolean isSuccess = true; + for (SceneDetailResult sceneResult : sceneResults) { + String suggestion = sceneResult.getSuggestion(); + if (SuggestionEnum.BLOCK.getCode().equals(suggestion)) { + isSuccess = false; + break; + } + } + if (isSuccess) { + result.getSuccessDataIds().add(taskResult.getDataId()); + } else { + log.warn("executeSyncImg dataId:{} block:{}", taskResult.getDataId(), JSON.toJSONString(taskResult.getResults())); + result.getFailDataIds().add(taskResult.getDataId()); + } + } + return result; + } else { + log.warn("executeSyncImg detect not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); + } + } else { + log.warn("executeSyncImg response status is not success. httpResponse:{}", JSON.toJSONString(httpResponse)); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); + } + } catch (Exception e) { + log.error("executeSyncImg exception IAcsClientUtil do action exception", e); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getMsg()); + } + } + + /** + * @author yinzuomei + * @description 语音异步检测 + * @Date 2020/12/9 10:02 + */ + @Override + public Result sendVoiceAsyncScan(VoiceAsyncScanParam voiceAsyncScanParam) { + //检测对象不能为空,且最多支持100个元素 + List voiceTasks = voiceAsyncScanParam.getTasks(); + if (CollectionUtils.isEmpty(voiceTasks) || voiceTasks.size() > SysConstant.MAX_TASK_SIZE) { + return new Result().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), + SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg().concat(SysConstant.MAX_TASK_SIZE.toString())); + } + + //默认参数 + voiceAsyncScanParam.setScenes(VoiceSceneEnum.getVoiceSceneList()); + voiceAsyncScanParam.setBizType(bizType); + // 如果是语音流检测,则修改为true。现在默认为音频文件检测false + voiceAsyncScanParam.setLive(false); + voiceAsyncScanParam.setSeed(UUID.randomUUID().toString().replace("-", "")); + + VoiceAsyncScanRequest voiceAsyncScanRequest=getVoiceAsyncScanRequest(); + + try { + voiceAsyncScanRequest.setHttpContent(JSON.toJSONString(voiceAsyncScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); + } catch (UnsupportedEncodingException e) { + log.error("sendVoiceAsyncScan parse param exception", e); + return new Result().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); + } + log.info("语音异步检测入参:"+JSON.toJSONString(voiceAsyncScanParam,true)); + List taskList; + try { + taskList = executeSyncVoice(voiceAsyncScanRequest); + log.info("语音异步检测返参taskList:"+JSON.toJSONString(taskList,true)); + } catch (ExecuteHttpException e) { + log.error("sendVoiceAsyncScan execute Exception", e); + return new Result().error(e.getCode(), e.getMsg()); + } + //成功返回 + VoiceAsyncScanTaskResult resultDto=new VoiceAsyncScanTaskResult(); + resultDto.setSeed(voiceAsyncScanParam.getSeed()); + List successList = new ArrayList<>(); + List failedList = new ArrayList<>(); + taskList.forEach(taskDetail -> { + if (HttpStatus.SC_OK == taskDetail.getCode()) { + successList.add(taskDetail); + } else { + failedList.add(taskDetail); + } + }); + resultDto.setSuccessTasks(successList); + resultDto.setFailTasks(failedList); + resultDto.setAllSuccess(resultDto.isAllSuccess()); + if (StringUtils.isNotBlank(voiceAsyncScanParam.getCallback())) { + // 存储seed和 任务id、dataId的关系 用于回调鉴权 + log.info("need to save seed and taskId、dataId的关系"); + ValueOperations valueOperations=redisTemplate.opsForValue(); + taskList.forEach(task -> { + String seedKey = RedisKeys.getVoiceScanSeedKey(task.getTaskId()); + valueOperations.set(seedKey,voiceAsyncScanParam.getSeed()); + }); + } + return new Result().ok(resultDto); + } + + /** + * @param + * @author yinzuomei + * @description 构造语音异步检测请求对象 + * @Date 2020/12/9 10:44 + **/ + private VoiceAsyncScanRequest getVoiceAsyncScanRequest() { + VoiceAsyncScanRequest voiceAsyncScanRequest = new VoiceAsyncScanRequest(); + // 指定api返回格式 + voiceAsyncScanRequest.setAcceptFormat(FormatType.JSON); + // 指定请求方法 + voiceAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); + voiceAsyncScanRequest.setEncoding(SysConstant.UTF8); + voiceAsyncScanRequest.setRegionId(regionId); + voiceAsyncScanRequest.setConnectTimeout(3000); + voiceAsyncScanRequest.setReadTimeout(6000); + return voiceAsyncScanRequest; + } + + /** + * @param voiceAsyncScanRequest + * @author yinzuomei + * @description 解析返参 + * @Date 2020/12/9 10:44 + **/ + private List executeSyncVoice(AcsRequest voiceAsyncScanRequest) { + try { + HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(voiceAsyncScanRequest); + + if (httpResponse.isSuccess()) { + + JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); + //后面注释掉此日志 + log.info("VoiceAsyncScanRequest原生接口返参:" + JSON.toJSONString(scrResponse, true)); + + if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { + + //获取data列表 + JSONArray dataResults = scrResponse.getJSONArray(SysConstant.DATA); + List resultList = dataResults.toJavaList(VoiceAsyncScanTaskDataDTO.class); + //成功返回 + return resultList; + + } else { + + log.warn("executeSyncVoice detect not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getCode(), + SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); + } + + } else { + log.warn("executeSyncVoice response status is not success. httpResponse:{}", JSON.toJSONString(httpResponse)); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getCode(), + SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); + } + + } catch (Exception e) { + log.error("executeSyncVoice exception IAcsClientUtil do action exception", e); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getMsg()); + } + } + + + /** + * @param taskIds 要查询的异步检测任务的taskId列表。数组中的元素个数不超过100个 + * @author yinzuomei + * @description 语音异步检测结果查询 + * @Date 2020/12/9 11:17 + **/ + @Override + public Result> voiceResults(List taskIds) { + //检测对象不能为空,且最多支持100个元素 + if (CollectionUtils.isEmpty(taskIds) || taskIds.size() > SysConstant.MAX_TASK_SIZE) { + return new Result>().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), + SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg().concat(SysConstant.MAX_TASK_SIZE.toString())); + } + + VoiceAsyncScanResultsRequest request=getVoiceAsyncScanResultsRequest(); + try { + request.setHttpContent(JSON.toJSONString(taskIds).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); + } catch (UnsupportedEncodingException e) { + log.error("voiceResults parse param exception", e); + return new Result>().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); + } + + // log.info("语音异步检测结果查询入参:"+JSON.toJSONString(taskIds,true)); + + try { + HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(request); + if (httpResponse.isSuccess()) { + + JSONObject scrResponse=JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); + //后面注释掉此返参 + log.info("VoiceAsyncScanResultsRequest原生接口返参:"+JSON.toJSONString(scrResponse, true)); + if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { + //获取data列表 + JSONArray dataResults = scrResponse.getJSONArray(SysConstant.DATA); + List resultList = dataResults.toJavaList(VoiceAsyncScanResult.class); + List resultData=processVoiceAsyncScanResult(resultList); + //成功返回 + return new Result>().ok(resultData); + + }else{ + + log.warn("voiceResults detect not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getCode(), + SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); + } + + } else { + log.warn("语音异步检测结果查询预警 getVoiceAsyncScanResult response status is not success. httpResponse:{}", JSON.toJSONString(httpResponse)); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getCode(), + SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); + } + } catch (Exception e) { + log.error("voiceResults exception IAcsClientUtil do action exception", e); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getMsg()); + } + + } + + private List processVoiceAsyncScanResult(List resultList) { + List list = new ArrayList<>(); + for (VoiceAsyncScanResult voiceAsyncScanResult : resultList) { + if (SysConstant.PROCESSING == voiceAsyncScanResult.getCode()) { + //280:表示处理中,需要继续轮询 + continue; + } + VoiceAsyncScanResult dto = ConvertUtils.sourceToTarget(voiceAsyncScanResult, VoiceAsyncScanResult.class); + if (HttpStatus.SC_OK == voiceAsyncScanResult.getCode()) { + if (!CollectionUtils.isEmpty(voiceAsyncScanResult.getResults()) && voiceAsyncScanResult.getResults().size() > NumConstant.ZERO) { + //目前只有一个检测场景,所以只判断返回来的第一个场景 + VoiceAsyncScanResultDTO voiceAsyncScanResultDTO = voiceAsyncScanResult.getResults().get(NumConstant.ZERO); + if (null != voiceAsyncScanResultDTO) { + dto.setLabel(voiceAsyncScanResultDTO.getLabel()); + dto.setLabelDesc(LabelEnum.getDesc(voiceAsyncScanResultDTO.getLabel())); + dto.setSuggestion(voiceAsyncScanResultDTO.getSuggestion()); + } + } + } else if(HttpStatus.SC_NOT_FOUND == voiceAsyncScanResult.getCode()) { + dto.setSuggestion(SuggestionEnum.REVIEW.getCode()); + dto.setLabel(NumConstant.EMPTY_STR); + dto.setLabelDesc("智能检测任务失败,结果已失效," + SuggestionEnum.REVIEW.getDesc()); + }else{ + //其他:表示任务失败 + dto.setSuggestion(SuggestionEnum.REVIEW.getCode()); + dto.setLabel(NumConstant.EMPTY_STR); + dto.setLabelDesc("智能检测任务失败," + SuggestionEnum.REVIEW.getDesc()); + } + list.add(dto); + } + return list; + } + + private VoiceAsyncScanResultsRequest getVoiceAsyncScanResultsRequest(){ + VoiceAsyncScanResultsRequest getResultsRequest = new VoiceAsyncScanResultsRequest(); + // 指定API返回格式。 + getResultsRequest.setAcceptFormat(FormatType.JSON); + // 指定请求方法。 + getResultsRequest.setMethod(com.aliyuncs.http.MethodType.POST); + getResultsRequest.setEncoding(SysConstant.UTF8); + getResultsRequest.setRegionId(regionId); + /** + * 请务必设置超时时间。 + */ + getResultsRequest.setConnectTimeout(3000); + getResultsRequest.setReadTimeout(6000); + return getResultsRequest; + } + + /** + * desc:视频检测-异步检测 + * + * @param videoAsyncScanParam + * @return + */ + @Override + public Result videoAsyncScan(VideoAsyncScanParam videoAsyncScanParam) { + //一次至多提交100个检测对象 + List videoTasks = videoAsyncScanParam.getTasks(); + if (CollectionUtils.isEmpty(videoTasks) || videoTasks.size() > SysConstant.MAX_TASK_SIZE) { + return new Result().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg().concat(SysConstant.MAX_TASK_SIZE.toString())); + } + //默认参数赋值 + videoAsyncScanParam.setScenes(VideoSceneEnum.getVideoSceneList()); + videoAsyncScanParam.setBizType(bizType); + videoAsyncScanParam.setAudioScenes(VoiceSceneEnum.getVoiceSceneList()); + videoAsyncScanParam.setSeed(UUID.randomUUID().toString().replace("-", "")); + //API文档没写限制多少最大多少,应该与图片一致 + if (videoTasks.size() <= SysConstant.MAX_SCAN_IMG_TASK_SIZE) { + return doScanVideo(videoAsyncScanParam); + } + log.info("videoAsyncScan tasks size:{} over 10", videoTasks.size()); + //分组调用,一次提交10个 + List> partition = ListUtils.partition(videoTasks, SysConstant.MAX_SCAN_IMG_TASK_SIZE); + VideoAsyncScanTaskResultDTO finalResult = new VideoAsyncScanTaskResultDTO(); + for (List tasks : partition) { + VideoAsyncScanParam videParam = new VideoAsyncScanParam(); + videParam.setBizType(videoAsyncScanParam.getBizType()); + videParam.setScenes(videoAsyncScanParam.getScenes()); + videParam.setTasks(tasks); + videParam.setCallback(videoAsyncScanParam.getCallback()); + videParam.setSeed(videoAsyncScanParam.getSeed()); + videParam.setAudioScenes(videoAsyncScanParam.getAudioScenes()); + Result partResult = doScanVideo(videParam); + try { + Thread.sleep(5L); + } catch (InterruptedException e) { + log.error("videoAsyncScan InterruptedException"); + } + if (partResult.success()) { + VideoAsyncScanTaskResultDTO data = partResult.getData(); + finalResult.setSeed(data.getSeed()); + finalResult.getSuccessTasks().addAll(data.getSuccessTasks()); + finalResult.getFailTasks().addAll(data.getFailTasks()); + } else { + return partResult; + } + } + return new Result().ok(finalResult); + } + + private Result doScanVideo(VideoAsyncScanParam videoAsyncScanParam) { + VideoAsyncScanRequest videoAsyncScanRequest = getVideoAsyncScanRequest(); + try { + videoAsyncScanRequest.setHttpContent(JSON.toJSONString(videoAsyncScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); + } catch (UnsupportedEncodingException e) { + log.error("doScanVideo parse param exception", e); + return new Result().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); + } + + try { + VideoAsyncScanTaskResultDTO scanResult = executeAsyncVideo(videoAsyncScanRequest); + scanResult.setSeed(videoAsyncScanParam.getSeed()); + return new Result().ok(scanResult); + } catch (ExecuteHttpException e) { + log.error("doScanVideo execute exception,param:{},fail msg:{}", JSON.toJSONString(videoAsyncScanParam), e.getMsg()); + return new Result().error(e.getCode(), e.getMsg()); + } + } + + private VideoAsyncScanRequest getVideoAsyncScanRequest() { + VideoAsyncScanRequest videoAsyncScanRequest = new VideoAsyncScanRequest(); + videoAsyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定API返回格式。 + videoAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法。 + /** + * 请务必设置超时时间。 + */ + videoAsyncScanRequest.setConnectTimeout(3000); + videoAsyncScanRequest.setReadTimeout(6000); + return videoAsyncScanRequest; + } + + private VideoAsyncScanTaskResultDTO executeAsyncVideo(VideoAsyncScanRequest videoAsyncScanRequest) { + try { + HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(videoAsyncScanRequest); + if (httpResponse.isSuccess()) { + JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); + if (HttpStatus.SC_OK == scrResponse.getInteger(SysConstant.CODE)) { + //获取data列表 + JSONArray dataResults = scrResponse.getJSONArray(SysConstant.DATA); + List dataList = dataResults.toJavaList(VideoAsyncScanTaskDataDTO.class); + VideoAsyncScanTaskResultDTO result=new VideoAsyncScanTaskResultDTO(); + dataList.forEach(data->{ + if (HttpStatus.SC_OK == data.getCode()) { + result.getSuccessTasks().add(data); + } else { + result.getFailTasks().add(data); + } + }); + return result; + } else { + log.warn("executeAsyncVideo detect not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getCode(), + SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); + } + } else { + log.warn("executeAsyncVideo response status is not success. httpResponse:{}", JSON.toJSONString(httpResponse)); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getCode(), + SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); + } + } catch (Exception e) { + log.error("executeAsyncVideo exception IAcsClientUtil do action exception", e); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getMsg()); + } + } + + /** + * @param taskIds + * @author yinzuomei + * @description 视频异步检测结果查询接口 + * @Date 2020/12/29 16:10 + **/ + @Override + public Result videoResults(List taskIds) { + VideoAsyncScanResultsRequest videoAsyncScanResultsRequest = new VideoAsyncScanResultsRequest(); + videoAsyncScanResultsRequest.setAcceptFormat(FormatType.JSON); + videoAsyncScanResultsRequest.setMethod(com.aliyuncs.http.MethodType.POST); + videoAsyncScanResultsRequest.setConnectTimeout(3000); + videoAsyncScanResultsRequest.setReadTimeout(6000); + try { + videoAsyncScanResultsRequest.setHttpContent(JSON.toJSONString(taskIds).getBytes("UTF-8"), "UTF-8", FormatType.JSON); + } catch (UnsupportedEncodingException e) { + log.error("videoResults parse param exception", e); + return new Result().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); + } + try { + HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(videoAsyncScanResultsRequest); + if (httpResponse.isSuccess()) { + JSONObject responseObject = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); + log.info("查询视频检测结果返参"+JSON.toJSONString(responseObject)); + if (HttpStatus.SC_OK == responseObject.getInteger(SysConstant.CODE)) { + //获取data列表 + JSONArray dataResults = responseObject.getJSONArray(SysConstant.DATA); + List resultList = dataResults.toJavaList(VideoScanOriginalResultDTO.class); + //解析数据 + VideoResultDTO resultDTO = processVideoResults(resultList); + //成功返回 + return new Result().ok(resultDTO); + } else { + log.warn("查询视频检测结果,接口返回code=" + responseObject.getInteger(SysConstant.CODE)); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getCode(), + SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); + } + } else { + log.warn("查询视频检测结果,API返回失败"); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getCode(), + SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); + } + } catch (Exception e) { + log.error("videoResults exception ", e); + throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getMsg()); + } + } + + /** + * @author yinzuomei + * @description + **/ + private VideoResultDTO processVideoResults(List resultList) { + VideoResultDTO videoResultDTO = new VideoResultDTO(); + resultList.forEach(result -> { + result.setCodeDesc(CommonErrorCodeEnum.getErrorMsg(result.getCode())); + if (result.getCode().equals(CommonErrorCodeEnum.PROCESSING.getCode())) { + //任务正在检测中,继续轮询 + } else if (result.getCode().equals(CommonErrorCodeEnum.OK.getCode())) { + //成功=>分析结果 + boolean videoPassFlag = getVideoFlag(result.getResults()); + boolean voicePassFlag = getVoiceFlag(result.getAudioScanResults()); + if (videoPassFlag && voicePassFlag) { + videoResultDTO.getPassDataIds().add(result.getDataId()); + videoResultDTO.getPassTaskIds().add(result.getTaskId()); + } else { + videoResultDTO.getNoPassDataIds().add(result.getDataId()); + videoResultDTO.getNoPassTaskIds().add(result.getTaskId()); + } + } else { + //检测结果走丢了.... (*^▽^*) 默认失败 + videoResultDTO.getNoPassDataIds().add(result.getDataId()); + videoResultDTO.getNoPassTaskIds().add(result.getTaskId()); + } + }); + videoResultDTO.setDetails(resultList); + return videoResultDTO; + } + + /** + * @return boolean + * @author yinzuomei + * @description 视频检测结果判断 + **/ + private boolean getVideoFlag(List results) { + for(VideoScanOriginDetail videoRes:results){ + if (!SuggestionEnum.PASS.getCode().equals(videoRes.getSuggestion())) { + return false; + } + } + return true; + } + + /** + * @return boolean true:内容通过; 建议为内容违规或者需要人工审核的统一视为不通过,返回false + * @author yinzuomei + * @description 返回视频语音检测结果 + **/ + private boolean getVoiceFlag(List audioScanResults) { + if (CollectionUtils.isEmpty(audioScanResults)) { + return true; + } + for(VoiceAsyncScanResultDTO m:audioScanResults){ + //人工审核或者内容违规,统一视为不通过 + if (!SuggestionEnum.PASS.getCode().equals(m.getSuggestion())) { + return false; + } + } + return true; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java new file mode 100644 index 0000000000..82036797e3 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java @@ -0,0 +1,48 @@ +package com.epmet.openapi.scan.support.param; + +import lombok.Data; + +import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; +import java.io.Serializable; +import java.util.List; + +/** + * 审查参数 + * + * @author jianjun liu + * @date 2020-06-04 21:57 + **/ +@Data +public class ImgScanParam implements Serializable { + + private static final long serialVersionUID = 958801658335909745L; + /** + * 业务类型 + */ + private String bizType; + /** + * 场景 必填 + * + * @see com.epmet.openapi.scan.common.enu.ImgSceneEnum; + */ + private List scenes; + + /** + * 要检测的内容列表,必填 + * remark:一组任务列表中的taskId不能相同 + */ + @Valid + @NotEmpty(message = "任务列表不能为空") + private List tasks; + + /** + * 异步检测结果回调地址,执行异步审查内容时 必填 + */ + private String callback; + + /** + * 随机字符串,该值用于回调通知请求中的签名,使用callback时 必填 + */ + private String seed; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java new file mode 100644 index 0000000000..487485b7fc --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java @@ -0,0 +1,31 @@ +package com.epmet.openapi.scan.support.param; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * 任务参数 + * + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-04 22:13 + **/ +@Data +public class ImgTask implements Serializable { + + private static final long serialVersionUID = -747206284930578105L; + /** + * 要检测的数据id 非必填 + * + * */ + @NotBlank(message = "dataId不能为空") + private String dataId; + + /** + * 图片url 必填 + */ + @NotBlank(message = "图片URL不能为空") + private String url; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java new file mode 100644 index 0000000000..2b05d34e20 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java @@ -0,0 +1,48 @@ +package com.epmet.openapi.scan.support.param; + +import lombok.Data; + +import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; +import java.io.Serializable; +import java.util.List; + +/** + * 文本审查参数 + * + * @author jianjun liu + * @date 2020-06-05 11:17 + **/ +@Data +public class TextScanParam implements Serializable { + private static final long serialVersionUID = -3568903097975113166L; + + /** + * 业务类型 + */ + private String bizType; + /** + * 场景 必填 + * + * @see com.epmet.openapi.scan.common.enu.ImgSceneEnum; + */ + private List scenes; + + /** + * 要检测的内容列表,必填 + * remark:一组任务列表中的taskId不能相同 + */ + @Valid + @NotEmpty(message = "任务列表不能为空") + private List tasks; + + /** + * 异步检测结果回调地址,执行异步审查内容时 必填 + */ + private String callback; + + /** + * 随机字符串,该值用于回调通知请求中的签名,使用callback时 必填 + */ + private String seed; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextTask.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextTask.java new file mode 100644 index 0000000000..08215e3e5b --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextTask.java @@ -0,0 +1,33 @@ +package com.epmet.openapi.scan.support.param; + +import lombok.Data; +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * 任务参数 + * + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-04 22:13 + **/ +@Data +public class TextTask implements Serializable { + + private static final long serialVersionUID = 6957195274696018630L; + /** + * 要检测的数据id 非必填 + * + * */ + @NotBlank(message = "dataId不能为空") + private String dataId; + + /** + * 文本内容 必填 最多不能超过10000 + */ + @NotBlank(message = "待检测文本不能为空") + @Length(max = 10000,message = "待检测文本最大为10000") + private String content; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceAsyncScanParam.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceAsyncScanParam.java new file mode 100644 index 0000000000..baa8e51be0 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceAsyncScanParam.java @@ -0,0 +1,68 @@ +package com.epmet.openapi.scan.support.param; + +import lombok.Data; + +import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; +import java.io.Serializable; +import java.util.List; + +/** + * 音频审查 入参 + * 参考文档:https://help.aliyun.com/document_detail/89630.html?spm=a2c4g.11186623.2.12.51a32dbfW6AdqV#reference-bcf-3nk-z2b + * @author yinzuomei@elink-cn.com + * @date 2020/12/9 9:07 + */ +@Data +public class VoiceAsyncScanParam implements Serializable { + private static final long serialVersionUID = 3408043673247901184L; + + /** + * 是否开启回调 + */ + private Boolean openCallBack; + + /** + * 不必填 + * 该字段用于标识您的业务场景。您可以通过内容安全控制台创建业务场景(具体操作,请参见自定义机审标准),或者提交工单联系我们帮助您创建业务场景。 + */ + private String bizType; + + /** + * 必填 + * 检测场景,取值:antispam。 + */ + private List scenes; + + /** + * 不必填 + * 是否为语音流(例如直播流)检测。取值: + * true:表示语音流检测。 + * false(默认):表示音频文件检测。 + */ + private Boolean live; + + /** + * 不必填 + * 是否为近线检测模式。 取值: + * true:表示近线检测模式。近线检测模式下,您提交的任务不保证能够实时处理,但是可以排队并在24小时内开始检测。 + * false(默认):表示实时检测模式。对于超过了并发路数限制的检测请求会直接拒绝。 + * 说明 该参数仅适用于音频文件检测,不适用于语音流检测。 + */ + private Boolean offline; + + /** + * 异步检测结果回调地址,执行异步审查内容时 必填 + */ + private String callback; + + /** + * 随机字符串,该值用于回调通知请求中的签名,使用callback时 必填 + */ + private String seed; + + @Valid + @NotEmpty(message = "任务列表不能为空") + private List tasks; + +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceTask.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceTask.java new file mode 100644 index 0000000000..89f4333bba --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceTask.java @@ -0,0 +1,31 @@ +package com.epmet.openapi.scan.support.param; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * 语音异步检测 对象 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/9 10:16 + */ +@Data +public class VoiceTask implements Serializable { + /** + * 不必填 + * 要检测的数据id 非必填 + * 检测对象对应的数据ID。 + * 由大小写英文字母、数字、下划线(_)、短划线(-)、英文句号(.)组成,不超过128个字符,可以用于唯一标识您的业务数据。 + * */ + @NotBlank(message = "dataId不能为空") + private String dataId; + + /** + * 必填 + * 需要检测的音频文件或语音流的下载地址。 + */ + @NotBlank(message = "音频URL不能为空") + private String url; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanParam.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanParam.java new file mode 100644 index 0000000000..c0315f8c17 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanParam.java @@ -0,0 +1,76 @@ +package com.epmet.openapi.scan.support.param.video; + +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import java.io.Serializable; +import java.util.List; + +/** + * 视频审核-异步检测入参DTO + * + * @author yinzuomei@elink-cn.com + */ +@Data +public class VideoAsyncScanParam implements Serializable { + private static final long serialVersionUID = -7635290200099445362L; + + /** + * 是否开启回调 + */ + private Boolean openCallBack; + + /** + * 不必填 + * 该字段用于标识您的业务场景。您可以通过内容安全控制台创建业务场景(具体操作,请参见自定义机审标准),或者提交工单联系我们帮助您创建业务场景。 + */ + private String bizType; + + /** + * 不必填 + * 是否为语音流(例如直播流)检测。取值: + * true:表示语音流检测。 + * false(默认):表示音频文件检测。 + */ + private Boolean live; + + /** + * 不必填 + * 是否为近线检测模式。 取值: + * true:表示近线检测模式。近线检测模式下,您提交的任务不保证能够实时处理,但是可以排队并在24小时内开始检测。 + * false(默认):表示实时检测模式。对于超过了并发路数限制的检测请求会直接拒绝。 + * 说明 该参数仅适用于音频文件检测,不适用于语音流检测。 + */ + private Boolean offline; + + /** + * 必填 + * 指定视频检测场景。取值: + * porn:视频智能鉴黄 + * terrorism:视频暴恐涉政 + * live:视频不良场景 + * logo:视频logo + * ad:视频图文违规 + */ + private List scenes; + + /** + * 不必填 + * 指定视频语音检测场景,唯一取值:antispam,表示语音反垃圾。不传入该参数时仅检测视频图像内容;如果传入该参数,则在检测视频中图像的同时,对视频中语音进行检测。 + * 说明 如果需要检测视频语音,则不支持通过上传视频截帧序列的方式(即在task中传入frames)进行检测,您必须传入视频或视频流的URL地址(即在task中传入url)进行检测。 + */ + private List audioScenes; + + /** + * 异步检测结果回调地址,执行异步审查内容时 必填 + */ + private String callback; + + /** + * 随机字符串,该值用于回调通知请求中的签名,使用callback时 必填 + */ + private String seed; + + @NotEmpty(message = "检测对象不能为空") + private List tasks; +} \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanTask.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanTask.java new file mode 100644 index 0000000000..38a4584d94 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/video/VideoAsyncScanTask.java @@ -0,0 +1,30 @@ +package com.epmet.openapi.scan.support.param.video; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * 视频审核-异步检测入参-检测对象 + * + * @author yinzuomei@elink-cn.com + */ +@Data +public class VideoAsyncScanTask implements Serializable { + /** + * 建议必填 + * 要检测的数据id 非必填 + * 检测对象对应的数据ID。 + * 由大小写英文字母、数字、下划线(_)、短划线(-)、英文句号(.)组成,不超过128个字符,可以用于唯一标识您的业务数据。 + * */ + @NotBlank(message = "dataId不能为空") + private String dataId; + + /** + * 必填 + * 待检测视频的URL。该字段不能和frames同时为空,也不能和frames同时有值。 + */ + @NotBlank(message = "音频URL不能为空") + private String url; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAsyncScanResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAsyncScanResult.java new file mode 100644 index 0000000000..d988cf7a88 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAsyncScanResult.java @@ -0,0 +1,24 @@ +package com.epmet.openapi.scan.support.result; + +import lombok.Data; + +import java.util.List; + +/** + * 检测结果 + * + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-05 10:52 + **/ +@Data +public class ImgAsyncScanResult { + /** + * 执行成功的任务Id集合 + */ + private List successTaskIds; + /** + * 执行失败的任务Id集合 + */ + private List failTaskIds; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ScanTaskResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ScanTaskResult.java new file mode 100644 index 0000000000..d358a570fa --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ScanTaskResult.java @@ -0,0 +1,28 @@ +package com.epmet.openapi.scan.support.result; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * desc:文本检测返回结果 + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-05 14:24 + **/ +@Data +public class ScanTaskResult implements Serializable { + + private static final long serialVersionUID = -7905091710384256911L; + private Integer code; + + + private String msg; + + + private String dataId; + + + private List results; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SceneDetailResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SceneDetailResult.java new file mode 100644 index 0000000000..4023153d10 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SceneDetailResult.java @@ -0,0 +1,31 @@ +package com.epmet.openapi.scan.support.result; + +import lombok.Data; + +/** + * desc:场景扫描结果 + * @author jianjun liu + * @date 2020-06-05 14:24 + **/ +@Data +public class SceneDetailResult { + /** + * 结果为该分类的概率 + */ + private Double rate; + + /** + * 建议用户执行的操作 + */ + private String suggestion; + + /** + * 场景 + */ + private String scene; + + /** + * 标签 + */ + private String label; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SyncScanResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SyncScanResult.java new file mode 100644 index 0000000000..8dcb757f64 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SyncScanResult.java @@ -0,0 +1,42 @@ +package com.epmet.openapi.scan.support.result; + +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * 检测结果 + * + * @author jianjun liu + * @date 2020-06-05 10:52 + **/ +@Data +public class SyncScanResult implements Serializable { + /** + * 执行成功的任务Id集合 + */ + private List successDataIds = new ArrayList<>(); + /** + * 执行失败的任务Id集合 + */ + private List failDataIds = new ArrayList<>(); + + /** + * desc:检测详情 + */ + private List details = new ArrayList<>(); + + /** + * 本地是否全部通过 + */ + private boolean isAllPass; + + public boolean isAllPass() { + if (failDataIds.isEmpty() && !successDataIds.isEmpty()) { + return true; + } + return isAllPass; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanDetailDTO.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanDetailDTO.java new file mode 100644 index 0000000000..7e74caf5a6 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanDetailDTO.java @@ -0,0 +1,47 @@ +package com.epmet.openapi.scan.support.result; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 语音异步检测结果查询结果返参 -data-result-detail详情 + * 语音对应的文本详情。每一句文本对应一个元素,包含一个或者多个元素。关于每个元素的结构描述 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/9 11:11 + */ +@Data +public class VoiceAsyncScanDetailDTO implements Serializable { + private static final long serialVersionUID = -2664219492371705160L; + /** + * 句子开始的时间,单位:秒。 + */ + private Integer startTime; + + /** + * 句子结束的时间,单位:秒。 + */ + private Integer endTime; + + /** + * 语音转换成文本的结果。 + */ + private String text; + + /** + * 检测结果的分类。取值: + * normal:正常文本 + * spam:含垃圾信息 + * ad:广告 + * politics:涉政 + * terrorism:暴恐 + * abuse:辱骂 + * porn:色情 + * flood:灌水 + * contraband:违禁 + * meaningless:无意义 + * customized:自定义(例如命中自定义关键词) + */ + private String label; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResult.java new file mode 100644 index 0000000000..1cbf3dab4a --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResult.java @@ -0,0 +1,89 @@ +package com.epmet.openapi.scan.support.result; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 语音异步检测结果查询结果返参 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/9 10:56 + */ +@Data +public class VoiceAsyncScanResult implements Serializable { + private static final long serialVersionUID = 8702129292884498023L; + + /** + * 检测对象对应的数据ID。 + */ + private String dataId; + + /** + * 检测任务的ID + */ + private String taskId; + + /** + * 检测结果的分类。取值: + * normal:正常文本 + * spam:含垃圾信息 + * ad:广告 + * politics:涉政 + * terrorism:暴恐 + * abuse:辱骂 + * porn:色情 + * flood:灌水 + * contraband:违禁 + * meaningless:无意义 + * customized:自定义(例如命中自定义关键词) + */ + private String label; + + /** + * labelDesc是对label的说明,包含两种特殊说明: + * (1)如果检测任务失败labelDesc:智能检测任务失败,结果已失效,需要人工审核 + * (2)如果检测结果失效labelDesc:智能检测任务失败,需要人工审核 + */ + private String labelDesc; + + /** + * 建议您执行的后续操作。取值: + * pass:结果正常,无需进行其余操作。 + * review:结果不确定,需要进行人工审核。 + * block:结果违规,建议直接删除或者限制公开。 + */ + private String suggestion; + + + /** + * 错误码,和HTTP状态码一致。 + * 200:表示检测成功。 + * 280:表示处理中,需要继续轮询。 + * 其他:表示任务失败。 + * 更多信息,请参见公共错误码。 + */ + @JsonIgnore + private Integer code; + /** + * 错误描述信息。 + */ + @JsonIgnore + private String msg; + + /** + * 暂时没用,所以返回忽略 + */ + @JsonIgnore + private String url; + + /** + * 检测成功(code=200)时,返回的检测结果。该结果包含一个或多个元素,每个元素是个结构体,对应一个场景。关于每个元素的结构描述,请参见result。 + * 暂时不展示审核结果明细 + */ + @JsonIgnore + private List results; + +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResultDTO.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResultDTO.java new file mode 100644 index 0000000000..34f3280a6f --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResultDTO.java @@ -0,0 +1,57 @@ +package com.epmet.openapi.scan.support.result; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 语音异步检测结果查询结果返参 -data-result详情 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/9 11:07 + */ +@Data +public class VoiceAsyncScanResultDTO implements Serializable { + private static final long serialVersionUID = 4602226363259983753L; + /** + * 检测场景,和调用请求中的场景对应。取值:antispam。 + */ + private String scene; + + /** + * 检测结果的分类。取值: + * normal:正常文本 + * spam:含垃圾信息 + * ad:广告 + * politics:涉政 + * terrorism:暴恐 + * abuse:辱骂 + * porn:色情 + * flood:灌水 + * contraband:违禁 + * meaningless:无意义 + * customized:自定义(例如命中自定义关键词) + */ + private String label; + + /** + * 建议您执行的后续操作。取值: + * pass:结果正常,无需进行其余操作。 + * review:结果不确定,需要进行人工审核。 + * block:结果违规,建议直接删除或者限制公开。 + */ + private String suggestion; + + /** + * 置信度分数,取值范围:0(表示置信度最低)~100(表示置信度最高)。 + * 如果suggestion为pass,则置信度越高,表示内容正常的可能性越高;如果suggestion为review或block,则置信度越高,表示内容违规的可能性越高。 + * 注意 该值仅作为参考,强烈建议您不要在业务中使用。建议您参考suggestion和label(或者部分接口返回的sublabel)结果用于内容违规判定。 + */ + private Float rate; + + /** + * 语音对应的文本详情。每一句文本对应一个元素,包含一个或者多个元素。关于每个元素的结构描述, + */ + private List details; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskDataDTO.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskDataDTO.java new file mode 100644 index 0000000000..ce43fec932 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskDataDTO.java @@ -0,0 +1,40 @@ +package com.epmet.openapi.scan.support.result; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Data; + +import java.io.Serializable; + +/** + * 语音异步检测,返回检测对象列表 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/9 16:38 + */ +@Data +public class VoiceAsyncScanTaskDataDTO implements Serializable { + /** + * 错误码,和HTTP状态码一致。 + * 更多信息,请参见公共错误码。 + */ + private Integer code; + /** + * 错误描述信息。 + */ + private String msg; + /** + * 检测对象对应的数据ID。 + */ + private String dataId; + + /** + * 检测任务的ID + */ + private String taskId; + + /** + * 暂时没用,所以返回忽略 + */ + @JsonIgnore + private String url; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskResult.java new file mode 100644 index 0000000000..2dcbecc398 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskResult.java @@ -0,0 +1,46 @@ +package com.epmet.openapi.scan.support.result; + +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * 语音异步检测,返参 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/9 9:23 + */ +@Data +public class VoiceAsyncScanTaskResult implements Serializable { + private static final long serialVersionUID = 8702129292884498023L; + /** + * 随机字符串,该值用于回调通知请求中的签名。 + */ + private String seed; + + /** + * 提交成功的失败对象 + */ + private List successTasks=new ArrayList<>(); + + /** + * 提交失败的检测对象 + */ + private List failTasks=new ArrayList<>(); + + /** + * 是否全部提交成功 + */ + private boolean isAllSuccess; + + public boolean isAllSuccess() { + if (failTasks.isEmpty() && !successTasks.isEmpty()) { + return true; + } + return isAllSuccess; + } + + +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskDataDTO.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskDataDTO.java new file mode 100644 index 0000000000..1d559a31cd --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskDataDTO.java @@ -0,0 +1,41 @@ +package com.epmet.openapi.scan.support.result.video; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Data; + +import java.io.Serializable; + +/** + * 视频审核-异步检测任务提交返参详情 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/29 13:42 + */ +@Data +public class VideoAsyncScanTaskDataDTO implements Serializable { + private static final long serialVersionUID = 8430710131685814181L; + /** + * 错误码,和HTTP状态码一致。 + * 更多信息,请参见公共错误码。 + */ + private Integer code; + /** + * 错误描述信息。 + */ + private String msg; + /** + * 检测对象对应的数据ID。 + */ + private String dataId; + + /** + * 检测任务的ID + */ + private String taskId; + + /** + * 暂时没用,所以返回忽略 + */ + @JsonIgnore + private String url; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskResultDTO.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskResultDTO.java new file mode 100644 index 0000000000..75ecd6e84f --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoAsyncScanTaskResultDTO.java @@ -0,0 +1,45 @@ +package com.epmet.openapi.scan.support.result.video; + +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * 视频审核-异步检测任务提交返参 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/29 13:38 + */ +@Data +public class VideoAsyncScanTaskResultDTO implements Serializable { + private static final long serialVersionUID = -467990806428860191L; + + /** + * 随机字符串,该值用于回调通知请求中的签名。 + */ + private String seed; + + /** + * 提交成功的失败对象 + */ + private List successTasks=new ArrayList<>(); + + /** + * 提交失败的检测对象 + */ + private List failTasks=new ArrayList<>(); + + /** + * 是否全部提交成功 + */ + private Boolean isAllSuccess; + + public boolean isAllSuccess() { + if (failTasks.isEmpty() && !successTasks.isEmpty()) { + return true; + } + return isAllSuccess; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoResultDTO.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoResultDTO.java new file mode 100644 index 0000000000..0e781bf463 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoResultDTO.java @@ -0,0 +1,48 @@ +package com.epmet.openapi.scan.support.result.video; + +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * 视频异步检测结果查询接口返参 + * 正在检测中的不返回,调用方继续轮询查询结果 + * @author yinzuomei@elink-cn.com + * @date 2020/12/29 15:37 + */ +@Data +public class VideoResultDTO implements Serializable { + private static final long serialVersionUID = -3451342817149956488L; + + /** + * 执行成功的任务Id集合 + * code=200,且所有语音+视频所有场景返回结果都为pass时则为成功 + */ + private List passDataIds = new ArrayList<>(); + /** + * 执行失败的任务Id集合 + */ + private List noPassDataIds = new ArrayList<>(); + + private List passTaskIds = new ArrayList<>(); + private List noPassTaskIds = new ArrayList<>(); + + /** + * desc:阿里内容审核API返回结果详情 + */ + private List details = new ArrayList<>(); + + /** + * 本地是否全部通过 + */ + private Boolean isAllPass; + + public boolean isAllPass() { + if (noPassTaskIds.isEmpty() && !passTaskIds.isEmpty()) { + return true; + } + return isAllPass; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginDetail.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginDetail.java new file mode 100644 index 0000000000..78916c1fe6 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginDetail.java @@ -0,0 +1,53 @@ +package com.epmet.openapi.scan.support.result.video; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 视频异步检测结果查询接口原生返参-视频检测结果 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/29 16:39 + */ +@Data +public class VideoScanOriginDetail implements Serializable { + private static final long serialVersionUID = 5547706236158849091L; + /** + * 视频检测场景,和调用请求中的场景对应。取值: + * porn:视频智能鉴黄 + * terrorism:视频暴恐涉政 + * live:视频不良场景 + * logo:视频logo + * ad:视频图文违规 + */ + private String scene; + + /** + * 视频检测结果的分类。不同检测场景的结果分类不同,具体如下: + * 视频智能鉴黄(porn)结果分类: + * normal:正常 + * porn:色情 + * 视频暴恐涉政(terrorism)结果分类: + * normal:正常 + * terrorism:暴恐涉政 + * 视频不良场景(live)结果分类: + * normal:正常 + * live:包含不良场景 + * 视频logo(logo)结果分类: + * normal:正常 + * logo:包含logo + * 视频图文违规(ad)结果分类: + * normal:正常 + * ad:包含广告或文字违规信息 + */ + private String label; + + /** + * 建议您执行的后续操作。取值: + * pass:结果正常,无需进行其余操作。 + * review:结果不确定,需要进行人工审核。 + * block:结果违规,建议直接删除或者限制公开。 + */ + private String suggestion; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginalResultDTO.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginalResultDTO.java new file mode 100644 index 0000000000..8964d5fe00 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/video/VideoScanOriginalResultDTO.java @@ -0,0 +1,51 @@ +package com.epmet.openapi.scan.support.result.video; + +import com.epmet.openapi.scan.support.result.VoiceAsyncScanResultDTO; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 视频异步检测结果查询接口原生返参 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/29 15:48 + */ +@Data +public class VideoScanOriginalResultDTO implements Serializable { + private static final long serialVersionUID = -1565008507757551616L; + + /** + * 错误码,和HTTP状态码一致。 + * 更多信息,请参见公共错误码。 + */ + private Integer code; + + private String codeDesc; + + /** + * 错误描述信息。 + */ + private String msg; + /** + * 检测对象对应的数据ID。 + */ + private String dataId; + + /** + * 检测任务的ID + */ + private String taskId; + + /** + * 返回结果,调用成功时(code=200),返回结果中包含一个或多个元素。每个元素是个结构体,具体结构描述,请参见result。 + * 说明 视频流检测场景中,code返回280表示在检测中,返回200表示检测完成。在检测中状态时,检测结果中包含从开始检测到当前时间的检测到结果。 + */ + private List results; + + /** + * 视频语音检测结果。具体结构描述,请参见audioScanResult。 + */ + private List audioScanResults; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/resources/bootstrap.yml b/epmet-openapi/epmet-openapi-scan/src/main/resources/bootstrap.yml new file mode 100644 index 0000000000..0aa0583c97 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/resources/bootstrap.yml @@ -0,0 +1,91 @@ +server: + port: @server.port@ + version: @version@ + servlet: + context-path: /epmetscan + +spring: + main: + allow-bean-definition-overriding: true + application: + name: epmet-openapi-scan + #环境 dev|test|prod + profiles: + active: @spring.profiles.active@ + messages: + encoding: UTF-8 + basename: i18n/messages_common + jackson: + time-zone: GMT+8 + date-format: yyyy-MM-dd HH:mm:ss + redis: + database: @spring.redis.index@ + host: @spring.redis.host@ + port: @spring.redis.port@ + password: @spring.redis.password@ + timeout: 30s + cloud: + nacos: + discovery: + server-addr: @nacos.server-addr@ + #nacos的命名空间ID,默认是public + namespace: @nacos.discovery.namespace@ + #不把自己注册到注册中心的地址 + register-enabled: @nacos.register-enabled@ + ip: @nacos.ip@ + config: + enabled: @nacos.config-enabled@ + server-addr: @nacos.server-addr@ + namespace: @nacos.config.namespace@ + group: @nacos.config.group@ + file-extension: yaml +management: + endpoints: + web: + exposure: + include: "*" + endpoint: + health: + show-details: ALWAYS + +feign: + hystrix: + enabled: true + client: + config: + default: + loggerLevel: BASIC + okhttp: + enabled: true + + +hystrix: + command: + default: + execution: + isolation: + thread: + timeoutInMilliseconds: 60000 #缺省为1000 + +ribbon: + ReadTimeout: 300000 + ConnectTimeout: 300000 + +aliyun: + green: + accessKeyId: LTAI4G6Fv6uTzQbpsayATHq4 + accessKeySecret: QevMw1RYCwQUG3RSMPq1J6EAfmSblo + regionId: cn-shanghai + bizType: epmet_img_text + +dingTalk: + robot: + webHook: @dingTalk.robot.webHook@ + secret: @dingTalk.robot.secret@ + +# 停机选项 +shutdown: + graceful: + enable: true #是否开启优雅停机 + waitTimeSecs: 30 # 优雅停机等待时间,超过30秒,发出告警 + diff --git a/epmet-openapi/epmet-openapi-scan/src/main/resources/logback-spring.xml b/epmet-openapi/epmet-openapi-scan/src/main/resources/logback-spring.xml new file mode 100644 index 0000000000..9d2ad51e14 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/resources/logback-spring.xml @@ -0,0 +1,169 @@ + + + + + + + + + + + + ${appname} + + + + + + + + + debug + + + ${CONSOLE_LOG_PATTERN} + + UTF-8 + + + + + + + + ${log.path}/debug.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${log.path}/debug-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + debug + ACCEPT + DENY + + + + + + + ${log.path}/info.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${log.path}/info-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + info + ACCEPT + DENY + + + + + + + ${log.path}/warn.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${log.path}/warn-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + warn + ACCEPT + DENY + + + + + + + ${log.path}/error.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${log.path}/error-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + ERROR + ACCEPT + DENY + ${webHook} + ${secret} + ${appname} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/epmet-openapi/epmet-openapi-scan/src/main/resources/readme b/epmet-openapi/epmet-openapi-scan/src/main/resources/readme new file mode 100644 index 0000000000..384fca6dfc --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/resources/readme @@ -0,0 +1,7 @@ +#访问openApi 需要向redis中 添加白名单 +sadd epmet:openapi:scan:whitelist "客户端ip地址" +#eg: +sadd epmet:openapi:scan:whitelist "\"192.168.1.1\"" + +#del +srem 'epmet:openapi:scan:whitelist' "\"116.179.32.197\"" "\"27.219.156.47\"" \ No newline at end of file diff --git a/epmet-openapi/epmet-openapi-scan/src/test/java/BaseSample.java b/epmet-openapi/epmet-openapi-scan/src/test/java/BaseSample.java new file mode 100644 index 0000000000..8c0774030d --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/test/java/BaseSample.java @@ -0,0 +1,50 @@ +import java.io.IOException; +import java.util.Properties; + +/** + * Created by liuhai.lh on 17/01/12. + */ +public class BaseSample { + + protected static String accessKeyId = "123"; + protected static String accessKeySecret = "456"; + + protected static String regionId = "cn-shanghai"; + + static { + Properties properties = new Properties(); + + try { + properties.load(BaseSample.class.getResourceAsStream("bootstrap.yml")); + accessKeyId = properties.getProperty("aliyun.green.accessKeyId"); + accessKeySecret = properties.getProperty("aliyun.green.accessKeySecret"); + regionId = properties.getProperty("aliyun.green.url"); + } catch(IOException e) { + e.printStackTrace(); + } + + } + protected static String getDomain(){ + if("cn-shanghai".equals(regionId)){ + return "green.cn-shanghai.aliyuncs.com"; + } + + if ("cn-beijing".equals(regionId)) { + return "green.cn-beijing.aliyuncs.com"; + } + + if ("ap-southeast-1".equals(regionId)) { + return "green.ap-southeast-1.aliyuncs.com"; + } + + if ("us-west-1".equals(regionId)) { + return "green.us-west-1.aliyuncs.com"; + } + + return "green.cn-shanghai.aliyuncs.com"; + } + protected static String getEndPointName(){ + return regionId; + } + +} diff --git a/epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanRequestSample.java b/epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanRequestSample.java new file mode 100644 index 0000000000..acba42e763 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanRequestSample.java @@ -0,0 +1,95 @@ +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.aliyuncs.DefaultAcsClient; +import com.aliyuncs.IAcsClient; +import com.aliyuncs.exceptions.ClientException; +import com.aliyuncs.exceptions.ServerException; +import com.aliyuncs.green.model.v20180509.ImageAsyncScanRequest; +import com.aliyuncs.http.FormatType; +import com.aliyuncs.http.HttpResponse; +import com.aliyuncs.profile.DefaultProfile; +import com.aliyuncs.profile.IClientProfile; +import com.epmet.openapi.scan.common.enu.RegionIdEnum; + +import java.util.*; + +/** + * Created by liuhai.lh on 2017/2/17. + * 图片异步检测接口 + * @author liuhai.lh + * @date 2017/02/17 + */ +public class ImageAsyncScanRequestSample extends BaseSample{ + + public static void main(String[] args) throws Exception { + //请替换成你自己的accessKeyId、accessKeySecret + IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret); + DefaultProfile.addEndpoint(getEndPointName(), regionId, "Green", RegionIdEnum.getDoMain(regionId)); + IAcsClient client = new DefaultAcsClient(profile); + + ImageAsyncScanRequest imageAsyncScanRequest = new ImageAsyncScanRequest(); + imageAsyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式 + imageAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法 + imageAsyncScanRequest.setEncoding("utf-8"); + imageAsyncScanRequest.setRegionId(regionId); + + + List> tasks = new ArrayList>(); + Map task1 = new LinkedHashMap(); + task1.put("dataId", UUID.randomUUID().toString()); + task1.put("url", "https://img.alicdn.com/tfs/TB1Xk_qvwmTBuNjy1XbXXaMrVXa-550-407.jpg"); + task1.put("time", new Date()); + + tasks.add(task1); + JSONObject data = new JSONObject(); + /** + * porn: 色情 + * terrorism: 暴恐 + * qrcode: 二维码 + * ad: 图片广告 + * ocr: 文字识别 + */ + data.put("scenes", Arrays.asList("porn", "ocr", "qrcode", "sface")); + data.put("tasks", tasks); + + imageAsyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON); + + /** + * 请务必设置超时时间 + */ + imageAsyncScanRequest.setConnectTimeout(3000); + imageAsyncScanRequest.setReadTimeout(6000); + + try { + HttpResponse httpResponse = client.doAction(imageAsyncScanRequest); + + if(httpResponse.isSuccess()){ + JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); + System.out.println(JSON.toJSONString(scrResponse, true)); + if (200 == scrResponse.getInteger("code")) { + JSONArray taskResults = scrResponse.getJSONArray("data"); + for (Object taskResult : taskResults) { + if(200 == ((JSONObject)taskResult).getInteger("code")){ + String taskId = ((JSONObject)taskResult).getString("taskId"); + // 将taskId 保存下来,间隔一段时间来轮询结果, 参照ImageAsyncScanResultsRequest + System.out.println("args = [" + taskId + "]"); + }else{ + System.out.println("task process fail:" + ((JSONObject)taskResult).getInteger("code")); + } + } + } else { + System.out.println("detect not success. code:" + scrResponse.getInteger("code")); + } + }else{ + System.out.println("response not success. status:" + httpResponse.getStatus()); + } + } catch (ServerException e) { + e.printStackTrace(); + } catch (ClientException e) { + e.printStackTrace(); + } catch (Exception e){ + e.printStackTrace(); + } + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanResultsSample.java b/epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanResultsSample.java new file mode 100644 index 0000000000..27e0b6e233 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/test/java/ImageAsyncScanResultsSample.java @@ -0,0 +1,83 @@ +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.aliyuncs.DefaultAcsClient; +import com.aliyuncs.IAcsClient; +import com.aliyuncs.exceptions.ClientException; +import com.aliyuncs.exceptions.ServerException; +import com.aliyuncs.green.model.v20180509.ImageAsyncScanResultsRequest; +import com.aliyuncs.http.FormatType; +import com.aliyuncs.http.HttpResponse; +import com.aliyuncs.profile.DefaultProfile; +import com.aliyuncs.profile.IClientProfile; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by liuhai.lh on 2017/2/17. + * 获取图片异步检测结果接口 + * @author liuhai.lh + * @date 2017/02/17 + */ +public class ImageAsyncScanResultsSample extends BaseSample{ + + public static void main(String[] args) throws Exception { + //请替换成你自己的accessKeyId、accessKeySecret + IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret); + DefaultProfile.addEndpoint(getEndPointName(), regionId, "Green", getDomain()); + IAcsClient client = new DefaultAcsClient(profile); + + ImageAsyncScanResultsRequest imageAsyncScanResultsRequest = new ImageAsyncScanResultsRequest(); + imageAsyncScanResultsRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式 + imageAsyncScanResultsRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法 + imageAsyncScanResultsRequest.setEncoding("utf-8"); + imageAsyncScanResultsRequest.setRegionId(regionId); + + + List taskIds = new ArrayList(); + taskIds.add("img1hdP5Wn0QC@7wW0n$VX0R@-1p3mnZ"); + imageAsyncScanResultsRequest.setHttpContent(JSON.toJSONString(taskIds).getBytes("UTF-8"), "UTF-8", FormatType.JSON); + + /** + * 请务必设置超时时间 + */ + imageAsyncScanResultsRequest.setConnectTimeout(3000); + imageAsyncScanResultsRequest.setReadTimeout(6000); + + try { + HttpResponse httpResponse = client.doAction(imageAsyncScanResultsRequest); + + if(httpResponse.isSuccess()){ + JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); + System.out.println(JSON.toJSONString(scrResponse, true)); + if (200 == scrResponse.getInteger("code")) { + JSONArray taskResults = scrResponse.getJSONArray("data"); + for (Object taskResult : taskResults) { + if(200 == ((JSONObject)taskResult).getInteger("code")){ + JSONArray sceneResults = ((JSONObject)taskResult).getJSONArray("results"); + for (Object sceneResult : sceneResults) { + String scene = ((JSONObject)sceneResult).getString("scene"); + String suggestion = ((JSONObject)sceneResult).getString("suggestion"); + //根据scene和suggetion做相关的处理 + //do something + } + }else{ + System.out.println("task process fail:" + ((JSONObject)taskResult).getInteger("code")); + } + } + } else { + System.out.println("detect not success. code:" + scrResponse.getInteger("code")); + } + }else{ + System.out.println("response not success. status:" + httpResponse.getStatus()); + } + } catch (ServerException e) { + e.printStackTrace(); + } catch (ClientException e) { + e.printStackTrace(); + } catch (Exception e){ + e.printStackTrace(); + } + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/test/java/ImageSyncScanRequestSample.java b/epmet-openapi/epmet-openapi-scan/src/test/java/ImageSyncScanRequestSample.java new file mode 100644 index 0000000000..ec418154d9 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/test/java/ImageSyncScanRequestSample.java @@ -0,0 +1,101 @@ +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.aliyuncs.DefaultAcsClient; +import com.aliyuncs.IAcsClient; +import com.aliyuncs.exceptions.ClientException; +import com.aliyuncs.exceptions.ServerException; +import com.aliyuncs.green.model.v20180509.ImageSyncScanRequest; +import com.aliyuncs.http.FormatType; +import com.aliyuncs.http.HttpResponse; +import com.aliyuncs.profile.DefaultProfile; +import com.aliyuncs.profile.IClientProfile; + +import java.util.*; + +/** + * Created by liuhai.lh on 2017/2/17. + * 图片同步检测接口 + * @author liuhai.lh + * @date 2017/02/17 + */ +public class ImageSyncScanRequestSample extends BaseSample { + + + public static void main(String[] args) throws Exception { + //请替换成你自己的accessKeyId、accessKeySecret + IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret); + DefaultProfile.addEndpoint(getEndPointName(), regionId, "Green", getDomain()); + IAcsClient client = new DefaultAcsClient(profile); + + ImageSyncScanRequest imageSyncScanRequest = new ImageSyncScanRequest(); + imageSyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式 + imageSyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法 + imageSyncScanRequest.setEncoding("utf-8"); + imageSyncScanRequest.setRegionId(regionId); + + + List> tasks = new ArrayList>(); + Map task = new LinkedHashMap(); + task.put("dataId", UUID.randomUUID().toString()); + task.put("url", "http://f.hiphotos.baidu.com/image/pic/item/aa18972bd40735fa13899ac392510fb30f24084b.jpg"); + task.put("time", new Date()); + + tasks.add(task); + JSONObject data = new JSONObject(); + /** + * porn: 色情 + * terrorism: 暴恐 + * qrcode: 二维码 + * ad: 图片广告 + * ocr: 文字识别 + */ + data.put("scenes", Arrays.asList("porn","terrorism")); + data.put("tasks", tasks); + + imageSyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON); + + /** + * 请务必设置超时时间 + */ + imageSyncScanRequest.setConnectTimeout(3000); + imageSyncScanRequest.setReadTimeout(10000); + + try { + HttpResponse httpResponse = client.doAction(imageSyncScanRequest); + + if (httpResponse.isSuccess()) { + JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); + System.out.println(JSON.toJSONString(scrResponse, true)); + if (200 == scrResponse.getInteger("code")) { + JSONArray taskResults = scrResponse.getJSONArray("data"); + for (Object taskResult : taskResults) { + if(200 == ((JSONObject)taskResult).getInteger("code")){ + JSONArray sceneResults = ((JSONObject)taskResult).getJSONArray("results"); + for (Object sceneResult : sceneResults) { + String scene = ((JSONObject)sceneResult).getString("scene"); + String suggestion = ((JSONObject)sceneResult).getString("suggestion"); + //根据scene和suggetion做相关的处理 + //do something + System.out.println("args = [" + scene + "]"); + System.out.println("args = [" + suggestion + "]"); + } + }else{ + System.out.println("task process fail:" + ((JSONObject)taskResult).getInteger("code")); + } + } + } else { + System.out.println("detect not success. code:" + scrResponse.getInteger("code")); + } + } else { + System.out.println("response not success. status:" + httpResponse.getStatus()); + } + } catch (ServerException e) { + e.printStackTrace(); + } catch (ClientException e) { + e.printStackTrace(); + } catch (Exception e){ + e.printStackTrace(); + } + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanRequestSample.java b/epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanRequestSample.java new file mode 100644 index 0000000000..617e6246d1 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanRequestSample.java @@ -0,0 +1,90 @@ +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.aliyuncs.DefaultAcsClient; +import com.aliyuncs.IAcsClient; +import com.aliyuncs.green.model.v20180509.VoiceAsyncScanRequest; +import com.aliyuncs.http.FormatType; +import com.aliyuncs.http.HttpResponse; +import com.aliyuncs.profile.DefaultProfile; +import com.aliyuncs.profile.IClientProfile; + +import java.util.*; + +/** + * 提交语音异步检测任务 demo + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/8 21:51 + */ +public class VoiceAsyncScanRequestSample extends BaseSample { + + + + public static void main(String[] args) throws Exception { + + //请替换成您自己的AccessKey ID、AccessKey Secret。 + IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", + "LTAI4G6Fv6uTzQbpsayATHq4", //您自己的AccessKey ID + "QevMw1RYCwQUG3RSMPq1J6EAfmSblo");//您自己的AccessKey Secret + final IAcsClient client = new DefaultAcsClient(profile); + + VoiceAsyncScanRequest asyncScanRequest = new VoiceAsyncScanRequest(); //class different vs common + asyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定API返回格式。 + asyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法。 + asyncScanRequest.setRegionId("cn-shanghai"); + asyncScanRequest.setConnectTimeout(3000); + asyncScanRequest.setReadTimeout(6000); + + List> tasks = new ArrayList>(); + Map task1 = new LinkedHashMap(); + // 请将下面的地址修改为要检测的语音文件的地址。 + task1.put("dataId","voice1"); + task1.put("url", "https://elink-esua-epdc.oss-cn-qingdao.aliyuncs.com/epmet/test/20201208/6480bd6be9f14a458162218cea84dfa5.aac"); + + Map task2 = new LinkedHashMap(); + task2.put("dataId","voice2"); + task2.put("url", "https://elink-esua-epdc.oss-cn-qingdao.aliyuncs.com/epmet/test/20201208/b566d94fd7114ffb9a203e80c22ebb96.aac"); + + tasks.add(task1); + tasks.add(task2); + + JSONObject data = new JSONObject(); + + System.out.println("==========Task count:" + tasks.size()); + data.put("scenes", Arrays.asList("antispam")); + data.put("tasks", tasks); + // 如果是语音流检测,则修改为true。 + data.put("live", false); + asyncScanRequest.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON); + System.out.println("接口入参:"+JSON.toJSONString(data, true)); + + try { + HttpResponse httpResponse = client.doAction(asyncScanRequest); + + if (httpResponse.isSuccess()) { + JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); + System.out.println("接口返参:"+JSON.toJSONString(scrResponse, true)); + if (200 == scrResponse.getInteger("code")) { + JSONArray taskResults = scrResponse.getJSONArray("data"); + for (Object taskResult : taskResults) { + Integer code = ((JSONObject) taskResult).getInteger("code"); + if (200 == code) { + final String taskId = ((JSONObject) taskResult).getString("taskId"); + System.out.println("submit async task success, taskId = [" + taskId + "]"); + } else { + System.out.println("task process fail: " + code); + } + } + } else { + System.out.println("detect not success. code: " + scrResponse.getInteger("code")); + } + } else { + System.out.println("response not success. status: " + httpResponse.getStatus()); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanResultsRequestSample.java b/epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanResultsRequestSample.java new file mode 100644 index 0000000000..85d268f175 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/test/java/VoiceAsyncScanResultsRequestSample.java @@ -0,0 +1,113 @@ +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.aliyuncs.DefaultAcsClient; +import com.aliyuncs.IAcsClient; +import com.aliyuncs.green.model.v20180509.VoiceAsyncScanResultsRequest; +import com.aliyuncs.http.FormatType; +import com.aliyuncs.http.HttpResponse; +import com.aliyuncs.profile.DefaultProfile; +import com.aliyuncs.profile.IClientProfile; + +import java.util.*; + +/** + * 查询异步语音检测结果。 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/8 22:08 + */ +public class VoiceAsyncScanResultsRequestSample extends BaseSample { + + + public static void main(String[] args) throws Exception { + // 请替换成您自己的AccessKey ID、AccessKey Secret。 + IClientProfile profile = DefaultProfile + .getProfile("cn-shanghai", + "LTAI4G6Fv6uTzQbpsayATHq4", + "QevMw1RYCwQUG3RSMPq1J6EAfmSblo"); + final IAcsClient client = new DefaultAcsClient(profile); + //提交语音异步检测任务后返回的taskId + pollingScanResult(client, Arrays.asList("vc_f_7WZZ01BCH0q6ZnM3g1OKGG-1tAaZ7", "vc_f_6AKaBxy4HdG5bruQ0JwweV-1tAaJi")); + // pollingScanResult(client, "vc_f_6AKaBxy4HdG5bruQ0JwweV-1tAaJi"); + } + + public static void pollingScanResult(IAcsClient client, List taskIdList) throws InterruptedException { + int failCount = 0; + boolean stop = false; + do { + // 设置每10秒查询一次。 + Thread.sleep(10 * 1000); + JSONObject scanResult = getScanResult(client, taskIdList); + System.out.println("接口完整返参:"+JSON.toJSONString(scanResult, true)); + if (scanResult == null || 200 != scanResult.getInteger("code")) { + failCount++; + System.out.println("请求失败,get result fail, failCount=" + failCount); + if (scanResult != null) { + System.out.println("请求失败,错误信息errorMsg:" + scanResult.getString("msg")); + } + if (failCount > 20) { + break; + } + continue; + } + + JSONArray taskResults = scanResult.getJSONArray("data"); + if (taskResults.isEmpty()) { + System.out.println("请求成功,but data is empty"); + break; + } + System.out.println("data.size=" + taskResults.size()); + for (Object taskResult : taskResults) { + JSONObject result = (JSONObject) taskResult; + Integer code = result.getInteger("code"); + String taskId = result.getString("taskId"); + if (280 == code) { + System.out.println("taskId=" + taskId + ": processing status: " + result.getString("msg")); + } else if (200 == code) { + System.out.println("taskId=" + taskId + "请求成功,返参:" + JSON.toJSONString(taskResult, true)); + stop = true; + } else { + System.out.println("taskId=" + taskId + "请求失败,返参:" + JSON.toJSONString(taskResult, true)); + stop = true; + } + } + } while (!stop); + } + + private static JSONObject getScanResult(IAcsClient client, List taskIdList) { + VoiceAsyncScanResultsRequest getResultsRequest = new VoiceAsyncScanResultsRequest(); + getResultsRequest.setAcceptFormat(FormatType.JSON); // 指定API返回格式。 + getResultsRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法。 + getResultsRequest.setEncoding("utf-8"); + getResultsRequest.setRegionId("cn-shanghai"); + + + List> tasks = new ArrayList>(); + for (String taskId : taskIdList) { + Map task1 = new LinkedHashMap(); + task1.put("taskId", taskId); + tasks.add(task1); + } + + /** + * 请务必设置超时时间。 + */ + getResultsRequest.setConnectTimeout(3000); + getResultsRequest.setReadTimeout(6000); + + try { + getResultsRequest.setHttpContent(JSON.toJSONString(tasks).getBytes("UTF-8"), "UTF-8", FormatType.JSON); + + HttpResponse httpResponse = client.doAction(getResultsRequest); + if (httpResponse.isSuccess()) { + return JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8")); + } else { + System.out.println("response not success. status: " + httpResponse.getStatus()); + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/epmet-openapi/pom.xml b/epmet-openapi/pom.xml new file mode 100644 index 0000000000..fd15705343 --- /dev/null +++ b/epmet-openapi/pom.xml @@ -0,0 +1,19 @@ + + + + epmet-cloud + com.epmet + 2.0.0 + + 4.0.0 + pom + + epmet-openapi + + epmet-openapi-scan + epmet-openapi-adv + + + \ No newline at end of file