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..53eaad58d0 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java @@ -0,0 +1,15 @@ +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_TEXT_TASKS = 100; + public static final Integer MAX_IMG_TASKS = 10; +} 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 index 1fcbbba9f0..cfb8d77ac2 100644 --- 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 @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; /** + * desc:图片检测场景 * @author jianjun liu * @date 2020-06-04 21:39 **/ 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..455b2975f4 --- /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..4cd76b8ca5 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java @@ -0,0 +1,45 @@ +package com.epmet.openapi.scan.common.enu; + +/** + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-04 21:39 + **/ +public enum SysResponseEnum { + /** + * + * 业务代码枚举类 + * + * 编码样式:【CCCBBOOXX】 + * 编码示例说明: + * CCC 中心编码&业务系统 (110-内容扫描服务中心服务) + * BB 业务类型(00-默认 ) + * OO 操作类型(00-默认) + * XX 具体编码(00-成功,01-失败,02-参数错误,10-异常 99-系统错误) + * + */ + /*通用枚举 */ + EXCEPTION(10001,"系统异常"), + AUTH_FAIL(10002,"验签失败"), + + + /*审核内容 业务 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/exception/AuthException.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/AuthException.java new file mode 100644 index 0000000000..7d0b652025 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/AuthException.java @@ -0,0 +1,17 @@ +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 AuthException extends RuntimeException { + private int code; + private String msg; + + public AuthException() { + this.code = SysResponseEnum.AUTH_FAIL.getCode(); + this.msg = SysResponseEnum.AUTH_FAIL.getMsg(); + } +} 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..99daf84bae --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExeCuteHttpException.java @@ -0,0 +1,23 @@ +package com.epmet.openapi.scan.common.exception; + +import com.epmet.commons.tools.utils.MessageUtils; +import com.epmet.openapi.scan.common.enu.SysResponseEnum; + +/** + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @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... params) { + this.code = code; + this.msg = MessageUtils.getMessage(code, params); + + } +} 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..978ca23004 --- /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: CallResult + * 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: CallResult + * 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: CallResult + * 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..d9e815348c --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/IAcsClientUtil.java @@ -0,0 +1,68 @@ +package com.epmet.openapi.scan.common.util; + +/** + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @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/common/util/RSASignature.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/RSASignature.java new file mode 100644 index 0000000000..c79906908d --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/util/RSASignature.java @@ -0,0 +1,152 @@ +package com.epmet.openapi.scan.common.util; + +import org.apache.commons.codec.binary.Base64; +import org.bouncycastle.util.encoders.UrlBase64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.crypto.Cipher; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.security.KeyFactory; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.Signature; +import java.security.cert.Certificate; +import java.security.cert.CertificateFactory; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; + +/** + * @author jianjun liu + * @date 2020-06-05 16:48 + **/ + +public class RSASignature { + private static final Logger LOGGER = LoggerFactory.getLogger(RSASignature.class); + public static final String KEY_ALGORITHM = "RSA"; + public static final String SIGNATURE_ALGORITHM = "SHA1WithRSA"; + public static final String ENCODING = "utf-8"; + public static final String X509 = "X.509"; + + /** + * 获取私钥 + * + * @param key + * @return + * @throws Exception + */ + public static PrivateKey getPrivateKey(String key) throws Exception { + byte[] keyBytes = Base64.decodeBase64(key.getBytes(ENCODING)); + PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes); + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); + PrivateKey privateKey = keyFactory.generatePrivate(keySpec); + return privateKey; + } + + /** + * 获取公钥 + * + * @param key + * @return + * @throws Exception + */ + public static PublicKey getPublicKey(String key) throws Exception { + byte[] keyBytes = Base64.decodeBase64(key.getBytes(ENCODING)); + CertificateFactory certificateFactory = CertificateFactory.getInstance(X509); + InputStream in = new ByteArrayInputStream(keyBytes); + Certificate certificate = certificateFactory.generateCertificate(in); + PublicKey publicKey = certificate.getPublicKey(); + return publicKey; + } + + /** + * 使用公钥对明文进行加密,返回BASE64编码的字符串 + * + * @param publicKey + * @param plainText + * @return + */ + public static String encrypt(String publicKey, String plainText) { + try { + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); + byte[] encodedKey = Base64.decodeBase64(publicKey.getBytes(ENCODING)); + PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey)); + Cipher cipher = Cipher.getInstance(KEY_ALGORITHM); + cipher.init(Cipher.ENCRYPT_MODE, pubKey); + byte[] enBytes = cipher.doFinal(plainText.getBytes()); + return new String(Base64.encodeBase64(enBytes)); + } catch (Exception e) { + LOGGER.error("rsa encrypt exception: {}", e.getMessage(), e); + } + return null; + } + + /** + * 使用私钥对明文密文进行解密 + * + * @param privateKey + * @param enStr + * @return + */ + public static String decrypt(String privateKey, String enStr) { + try { + PrivateKey priKey = getPrivateKey(privateKey); + Cipher cipher = Cipher.getInstance(KEY_ALGORITHM); + cipher.init(Cipher.DECRYPT_MODE, priKey); + byte[] deBytes = cipher.doFinal(Base64.decodeBase64(enStr)); + return new String(deBytes); + } catch (Exception e) { + LOGGER.error("rsa decrypt exception: {}", e.getMessage(), e); + } + return null; + } + + /** + * RSA私钥签名 + * + * @param content 待签名数据 + * @param privateKey 私钥 + * @return 签名值 + */ + public static String signByPrivateKey(String content, String privateKey) { + try { + PrivateKey priKey = getPrivateKey(privateKey); + Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM); + signature.initSign(priKey); + signature.update(content.getBytes(ENCODING)); + byte[] signed = signature.sign(); + return new String(UrlBase64.encode(signed), ENCODING); + } catch (Exception e) { + LOGGER.error("sign error, content: {}", content, e); + } + return null; + } + + /** + * 公钥验签 + * + * @param content + * @param sign + * @param publicKey + * @return + */ + public static boolean verifySignByPublicKey(String content, String sign, String publicKey) { + try { + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); + byte[] encodedKey = Base64.decodeBase64(publicKey.getBytes(ENCODING)); + PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey)); + + Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM); + signature.initVerify(pubKey); + signature.update(content.getBytes(ENCODING)); + + return signature.verify(UrlBase64.decode(sign.getBytes(ENCODING))); + + } catch (Exception e) { + LOGGER.error("verify sign error, content: {}, sign: {}", content, sign, e); + } + return false; + } + +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/FastJsonConfiguration.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/FastJsonConfiguration.java new file mode 100644 index 0000000000..8270a85299 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/config/FastJsonConfiguration.java @@ -0,0 +1,52 @@ +package com.epmet.openapi.scan.config; + +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.alibaba.fastjson.support.config.FastJsonConfig; +import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; +import org.springframework.boot.autoconfigure.http.HttpMessageConverters; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.StringHttpMessageConverter; + +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.List; + +/** + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-05 14:14 + **/ +@Configuration +public class FastJsonConfiguration { + + @Bean + public HttpMessageConverters fastJsonHttpMessageConverters() { + FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); + FastJsonConfig fastJsonConfig = new FastJsonConfig(); + + List fastMediaTypes = new ArrayList<>(); + + // 处理中文乱码问题 + fastJsonConfig.setCharset(Charset.forName("UTF-8")); + fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); + // 设置时间格式 + fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); + + fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); + fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); + + // 在转换器中添加配置信息 + fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); + HttpMessageConverter converter = fastJsonHttpMessageConverter; + + StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(); + stringConverter.setDefaultCharset(Charset.forName("UTF-8")); + stringConverter.setSupportedMediaTypes(fastMediaTypes); + + return new HttpMessageConverters(stringConverter, converter); + } + +} 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..add1a09ea1 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java @@ -0,0 +1,56 @@ +package com.epmet.openapi.scan.controller; + +import com.epmet.commons.tools.utils.Result; +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.result.ImgAsyncScanResult; +import com.epmet.openapi.scan.support.result.SyncScanResult; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @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) { + Result scanResultResult = scanService.sendSyncImgScan(param); + return scanResultResult; + } + + /** + * desc:文本同步检测接口 + * + * @param param + * @return + */ + @RequestMapping("textScan") + public Result textSyncScan(@RequestBody TextScanParam param) { + Result scanResultResult = scanService.sendTextScan(param); + return scanResultResult; + } + + @RequestMapping("imgAsyncScan") + public Result ImgAsyncScan(@RequestBody ImgScanParam param) { + Result scanResultResult = scanService.sendASyncImgScan(param); + return scanResultResult; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiInterceptor.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiInterceptor.java new file mode 100644 index 0000000000..91eb34a720 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/interceptor/ScanApiInterceptor.java @@ -0,0 +1,113 @@ +package com.epmet.openapi.scan.interceptor; + +import com.epmet.openapi.scan.common.exception.AuthException; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-05 16:36 + **/ +public class ScanApiInterceptor implements HandlerInterceptor { + private static final Logger log = LoggerFactory.getLogger(ScanApiInterceptor.class); + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) + throws Exception { + Gson gson = new GsonBuilder().serializeNulls().enableComplexMapKeySerialization().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); + Map parameterMap = request.getParameterMap(); + String requestUrl = request.getServletPath(); + log.info(" 请求地址为: " + requestUrl + " 请求参数为: " + gson.toJson(parameterMap)); + + try { + String timestamp = ""; + String appkey = ""; + String sign = ""; + if (parameterMap.containsKey("timestamp")) { + timestamp = parameterMap.get("timestamp").toString(); + //验证时间戳 + Long timestampL = new Long(timestamp); + Calendar timestampCalendar = Calendar.getInstance(); + timestampCalendar.setTimeInMillis(timestampL * 1000L); + //设置过期时间 + timestampCalendar.add(Calendar.MINUTE, 10); + Date timestampDate = timestampCalendar.getTime(); + Date nowDate = new Date(); + if (timestampDate.compareTo(nowDate) < 0) { + throw new AuthException(); + } + } else { + throw new AuthException(); + } + if (parameterMap.containsKey("appkey")) { + appkey = parameterMap.get("appkey").toString(); + } else { + throw new AuthException(); + } + if (parameterMap.containsKey("sign")) { + sign = parameterMap.get("sign").toString(); + } else { + throw new AuthException(); + } + + Map map2 = new HashMap(); + map2.putAll(parameterMap); + map2.remove("sign"); + /*String urls = MapUtil.getUrlParamsByMap(map2); + urls += "&appsecret=" + OakConfig.getApiAppSecret(); + String newSign = MD5Util.md5(urls); + //log.info("拼接urls参数为:" + urls + " 服务器端签名sign为:" + newSign); + if (!sign.equals(newSign)) { + throw new AuthException(); + return false; + }*/ + return true; + } catch (Exception e) { + log.error(e.toString()); + throw new AuthException(); + } + } + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, + ModelAndView modelAndView) throws Exception { + + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) + throws Exception { + + } + + 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..6f1959a2f8 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanService.java @@ -0,0 +1,37 @@ +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.result.ImgAsyncScanResult; +import com.epmet.openapi.scan.support.result.SyncScanResult; + +/** + * 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); + /** + * desc:扫描图片内容 异步 + * @param imgScanParam + * @return + */ + public Result sendASyncImgScan(ImgScanParam imgScanParam); +} 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..9471f1935d --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java @@ -0,0 +1,311 @@ +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.exceptions.ClientException; +import com.aliyuncs.exceptions.ServerException; +import com.aliyuncs.green.model.v20180509.ImageAsyncScanRequest; +import com.aliyuncs.green.model.v20180509.ImageSyncScanRequest; +import com.aliyuncs.green.model.v20180509.TextScanRequest; +import com.aliyuncs.http.FormatType; +import com.aliyuncs.http.HttpResponse; +import com.epmet.commons.tools.utils.Result; +import com.epmet.openapi.scan.common.constant.SysConstant; +import com.epmet.openapi.scan.common.enu.ImgSceneEnum; +import com.epmet.openapi.scan.common.enu.SuggestionEnum; +import com.epmet.openapi.scan.common.enu.SysResponseEnum; +import com.epmet.openapi.scan.common.enu.TextSceneEnum; +import com.epmet.openapi.scan.common.exception.ExeCuteHttpException; +import com.epmet.openapi.scan.common.util.IAcsClientUtil; +import com.epmet.openapi.scan.support.param.ImgScanParam; +import com.epmet.openapi.scan.support.param.ImgTask; +import com.epmet.openapi.scan.support.param.TextScanParam; +import com.epmet.openapi.scan.support.param.TextTask; +import com.epmet.openapi.scan.support.result.BaseScanResult; +import com.epmet.openapi.scan.support.result.ImgAsyncScanResult; +import com.epmet.openapi.scan.support.result.ScanTaskResult; +import com.epmet.openapi.scan.support.result.SyncScanResult; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.io.UnsupportedEncodingException; +import java.util.List; + +/** + * @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; + + @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_TEXT_TASKS) { + return new Result().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg()); + } + + TextScanRequest textScanRequest = new TextScanRequest(); + textScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式 + textScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法 + textScanRequest.setEncoding(SysConstant.UTF8); + textScanRequest.setRegionId(regionId); + + try { + textScanRequest.setHttpContent(JSON.toJSONString(textScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); + } catch (UnsupportedEncodingException e) { + log.error("sendTextScan exception", e.getMessage()); + } + + + /** + * 请务必设置超时时间 + */ + textScanRequest.setConnectTimeout(3000); + textScanRequest.setReadTimeout(6000); + try { + SyncScanResult textScanResult = executeSyncText(textScanRequest); + return new Result().ok(textScanResult); + } catch (Exception e) { + log.error("sendTextScan exception", e); + throw new ExeCuteHttpException(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg()); + } + } + + @Override + public Result sendSyncImgScan(ImgScanParam imgScanParam) { + + ImageSyncScanRequest imageSyncScanRequest = new ImageSyncScanRequest(); + imageSyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式 + imageSyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法 + imageSyncScanRequest.setEncoding(SysConstant.UTF8); + imageSyncScanRequest.setRegionId(regionId); + + //默认参数 + // 鉴黄 暴恐涉政 + imgScanParam.setScenes(ImgSceneEnum.getImgSceneList()); + imgScanParam.setBizType(bizType); + + List imgTasks = imgScanParam.getTasks(); + if (CollectionUtils.isEmpty(imgTasks) || imgTasks.size() > SysConstant.MAX_IMG_TASKS) { + return new Result().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg()); + } + + try { + imageSyncScanRequest.setHttpContent(JSON.toJSONString(imgScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); + } catch (UnsupportedEncodingException e) { + log.error("sendSyncImgScan exception", e.getMessage()); + return new Result().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); + } + + /** + * 请务必设置超时时间 + */ + imageSyncScanRequest.setConnectTimeout(3000); + imageSyncScanRequest.setReadTimeout(6000); + + try { + SyncScanResult scanResult = executeSyncImg(imageSyncScanRequest); + return new Result().ok(scanResult); + } catch (Exception e) { + log.error("sendImgScan execute Exception", e); + return new Result().error(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg()); + } + } + + @Override + public Result sendASyncImgScan(ImgScanParam imgScanParam) { + ImageAsyncScanRequest imageAsyncScanRequest = new ImageAsyncScanRequest(); + imageAsyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式 + imageAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法 + imageAsyncScanRequest.setEncoding(SysConstant.UTF8); + imageAsyncScanRequest.setRegionId(regionId); + + //默认参数 + // 鉴黄 暴恐涉政 + imgScanParam.setScenes(ImgSceneEnum.getImgSceneList()); + imgScanParam.setBizType(bizType); + + List imgTasks = imgScanParam.getTasks(); + if (CollectionUtils.isEmpty(imgTasks) || imgTasks.size() > SysConstant.MAX_IMG_TASKS) { + return new Result().error(SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_TASK_LIST_PARAM_ERROR.getMsg()); + } + + try { + imageAsyncScanRequest.setHttpContent(JSON.toJSONString(imgScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); + } catch (UnsupportedEncodingException e) { + log.error("sendASyncImgScan exception", e.getMessage()); + return new Result().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); + } + + /** + * 请务必设置超时时间 + */ + imageAsyncScanRequest.setConnectTimeout(3000); + imageAsyncScanRequest.setReadTimeout(6000); + + try { + ImgAsyncScanResult scanResult = executeAsyncImg(imageAsyncScanRequest); + return new Result().ok(scanResult); + } catch (Exception e) { + log.error("sendImgScan execute Exception", e); + return new Result().error(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg()); + } + } + + 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)); + System.out.println(JSON.toJSONString(scrResponse, true)); + if (200 == scrResponse.getInteger("code")) { + //任务 列表 + List scanTaskResults = scrResponse.getJSONArray("data").toJavaList(ScanTaskResult.class); + for (ScanTaskResult taskResult : scanTaskResults) { + //又根据场景不同 + if (200 == taskResult.getCode()) { + //如果是多个场景 则为对个 BaseScanResult + List sceneResults = taskResult.getResults(); + //是文本检测 目前就一种场景 + for (BaseScanResult sceneResult : sceneResults) { + String scene = sceneResult.getScene(); + String suggestion = sceneResult.getSuggestion(); + if (SuggestionEnum.BLOCK.getCode().equals(suggestion)) { + result.getFailDataIds().add(taskResult.getDataId()); + } else { + result.getSuccessDataIds().add(taskResult.getDataId()); + } + } + } else { + log.warn("executeSyncText task process fail:code:{},msg:{}", taskResult.getCode(), taskResult.getMsg()); + throw new ExeCuteHttpException(" executeSyncTexttask process fail:code:" + taskResult.getCode() + ",msg:" + taskResult.getMsg()); + } + } + return result; + } else { + throw new ExeCuteHttpException("executeSyncText detect not success. code:" + scrResponse.getInteger("code")); + } + } else { + log.warn("executeSyncText response not success. status:" + httpResponse.getStatus()); + throw new ExeCuteHttpException("response not success. status:" + httpResponse.getStatus()); + } + + } catch (Exception e) { + log.warn("executeSyncImg exception", e); + throw new ExeCuteHttpException(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg()); + } + } + + + /** + * desc:异步 检查图片 TODO 结果处理 + * + * @param request + * @return + */ + private ImgAsyncScanResult executeAsyncImg(AcsRequest request) { + ImgAsyncScanResult result = new ImgAsyncScanResult(); + try { + HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(request); + 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 + "]"); + result.getSuccessTaskIds().add(taskId); + } else { + //TODO 细化失败结果 属性 code等 + String taskId = ((JSONObject) taskResult).getString("taskId"); + result.getFailTaskIds().add(taskId); + log.warn("task process fail:{}", ((JSONObject) taskResult).getInteger("code")); + throw new ExeCuteHttpException("task process fail:" + ((JSONObject) taskResult).getInteger("code")); + } + } + return result; + } else { + System.out.println("detect not success. code:" + scrResponse.getInteger("code")); + throw new ExeCuteHttpException("detect not success. code:" + scrResponse.getInteger("code")); + } + } else { + System.out.println("response not success. status:" + httpResponse.getStatus()); + throw new ExeCuteHttpException("response not success. status:" + httpResponse.getStatus()); + } + } catch (ServerException e) { + e.printStackTrace(); + } catch (ClientException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } + + 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(), "UTF-8")); + System.out.println(JSON.toJSONString(scrResponse, true)); + if (200 == scrResponse.getInteger("code")) { + JSONArray taskResults = scrResponse.getJSONArray("data"); + List scanTaskResults = taskResults.toJavaList(ScanTaskResult.class); + for (ScanTaskResult taskResult : scanTaskResults) { + //如果是多个场景 则为对个 BaseScanResult + List sceneResults = taskResult.getResults(); + //是文本检测 目前就一种场景 + for (BaseScanResult sceneResult : sceneResults) { + String scene = sceneResult.getScene(); + String suggestion = sceneResult.getSuggestion(); + if (SuggestionEnum.BLOCK.getCode().equals(suggestion)) { + if (result.getFailDataIds().contains(taskResult.getDataId())) { + continue; + } + result.getFailDataIds().add(taskResult.getDataId()); + } else { + if (result.getSuccessDataIds().contains(taskResult.getDataId())) { + continue; + } + result.getSuccessDataIds().add(taskResult.getDataId()); + } + } + } + return result; + } else { + log.warn("executeSyncImg detect not success. code:", scrResponse.getInteger("code")); + throw new ExeCuteHttpException("detect not success. code:" + scrResponse.getInteger("code")); + } + } else { + log.warn("executeSyncImg response not success. status:" + httpResponse.getStatus()); + throw new ExeCuteHttpException("response not success. status:" + httpResponse.getStatus()); + } + } catch (Exception e) { + log.warn("executeSyncImg exception", e); + throw new ExeCuteHttpException(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg()); + } + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ScanParam.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java similarity index 73% rename from epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ScanParam.java rename to epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java index d589aa33b7..16e38eaa04 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ScanParam.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java @@ -2,6 +2,7 @@ package com.epmet.openapi.scan.support.param; import lombok.Data; +import java.io.Serializable; import java.util.List; /** @@ -11,7 +12,13 @@ import java.util.List; * @date 2020-06-04 21:57 **/ @Data -public class ScanParam { +public class ImgScanParam implements Serializable { + + private static final long serialVersionUID = 958801658335909745L; + /** + * 业务类型 + */ + private String bizType; /** * 场景 必填 * @@ -23,7 +30,7 @@ public class ScanParam { * 要检测的内容列表,必填 * remark:一组任务列表中的taskId不能相同 */ - private List tasks; + private List tasks; /** * 异步检测结果回调地址,执行异步审查内容时 必填 diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/Task.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java similarity index 68% rename from epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/Task.java rename to epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java index 51f38b1b3b..e06204415f 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/Task.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java @@ -2,6 +2,8 @@ package com.epmet.openapi.scan.support.param; import lombok.Data; +import java.io.Serializable; + /** * 任务参数 * @@ -10,8 +12,9 @@ import lombok.Data; * @date 2020-06-04 22:13 **/ @Data -public class Task { +public class ImgTask implements Serializable { + private static final long serialVersionUID = -747206284930578105L; /** * 要检测的数据id 非必填 * 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..8a49fd5d2a --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java @@ -0,0 +1,44 @@ +package com.epmet.openapi.scan.support.param; + +import lombok.Data; + +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不能相同 + */ + 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..aeb976506c --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextTask.java @@ -0,0 +1,28 @@ +package com.epmet.openapi.scan.support.param; + +import lombok.Data; + +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 非必填 + * + * */ + private String dataId; + + /** + * 文本内容 必填 最多不能超过10000 + */ + private String content; +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/BaseScanResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/BaseScanResult.java new file mode 100644 index 0000000000..76226d75d3 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/BaseScanResult.java @@ -0,0 +1,31 @@ +package com.epmet.openapi.scan.support.result; + +import lombok.Data; + +/** + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-05 14:24 + **/ +@Data +public class BaseScanResult { + /** + * 结果为该分类的概率 + */ + 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/ImgAcsReponse.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAcsReponse.java new file mode 100644 index 0000000000..b3a2f65ef1 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ImgAcsReponse.java @@ -0,0 +1,18 @@ +package com.epmet.openapi.scan.support.result; + +import com.aliyuncs.AcsResponse; +import com.aliyuncs.exceptions.ClientException; +import com.aliyuncs.exceptions.ServerException; +import com.aliyuncs.transform.UnmarshallerContext; + +/** + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-05 10:24 + **/ +public class ImgAcsReponse extends AcsResponse { + @Override + public AcsResponse getInstance(UnmarshallerContext context) throws ClientException, ServerException { + return null; + } +} 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..6ff3c512ea --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/ScanTaskResult.java @@ -0,0 +1,26 @@ +package com.epmet.openapi.scan.support.result; + +import lombok.Data; + +import java.util.List; + +/** + * desc:文本检测返回结果 + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-05 14:24 + **/ +@Data +public class ScanTaskResult { + + 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/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..59b2a04f94 --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/SyncScanResult.java @@ -0,0 +1,41 @@ +package com.epmet.openapi.scan.support.result; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * 检测结果 + * + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-05 10:52 + **/ +@Data +public class SyncScanResult { + /** + * 执行成功的任务Id集合 + */ + private List successDataIds = new ArrayList<>(); + /** + * 执行失败的任务Id集合 + */ + private List failDataIds = new ArrayList<>(); + + /** + * 本地是否全部通过 + */ + private boolean isAllPass; + + public boolean isAllPass() { + if (failDataIds.isEmpty() && !successDataIds.isEmpty()) { + return true; + } + return isAllPass; + } + + public void setAllPass(boolean allPass) { + isAllPass = allPass; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/TextScanResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/TextScanResult.java new file mode 100644 index 0000000000..c24f2bed6e --- /dev/null +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/TextScanResult.java @@ -0,0 +1,41 @@ +package com.epmet.openapi.scan.support.result; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * 检测结果 + * + * @author jianjun liu + * @email liujianjun@yunzongnet.com + * @date 2020-06-05 10:52 + **/ +@Data +public class TextScanResult { + /** + * 执行成功的任务Id集合 + */ + private List successDataIds = new ArrayList<>(); + /** + * 执行失败的任务Id集合 + */ + private List failDataIds = new ArrayList<>(); + + /** + * 本地是否全部通过 + */ + private boolean isAllPass; + + public boolean isAllPass() { + if (failDataIds.isEmpty() && !successDataIds.isEmpty()) { + return true; + } + return isAllPass; + } + + public void setAllPass(boolean allPass) { + isAllPass = allPass; + } +} diff --git a/epmet-openapi/epmet-openapi-scan/src/main/resources/bootstrap.yml b/epmet-openapi/epmet-openapi-scan/src/main/resources/bootstrap.yml index c2cf89a17e..6c9dba5543 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/resources/bootstrap.yml +++ b/epmet-openapi/epmet-openapi-scan/src/main/resources/bootstrap.yml @@ -72,6 +72,8 @@ ribbon: aliyun: green: - accessKeyId: 123 - accessKeySecret: 456 - regionId: cn-shanghai \ No newline at end of file + accessKeyId: LTAI4G6Fv6uTzQbpsayATHq4 + accessKeySecret: QevMw1RYCwQUG3RSMPq1J6EAfmSblo + regionId: cn-shanghai + bizType: epmet_img_text +