18 changed files with 1020 additions and 0 deletions
@ -0,0 +1,17 @@ |
|||
version: "3.7" |
|||
services: |
|||
epmet-user-server: |
|||
container_name: epmet-openapi-scan-dev |
|||
image: 192.168.1.130:10080/epmet-cloud-dev/epmet-openapi-scan:0.3.56 |
|||
ports: |
|||
- "8107:8107" |
|||
network_mode: host # 不会创建新的网络 |
|||
volumes: |
|||
- "/opt/epmet-cloud-logs/dev:/logs" |
|||
environment: |
|||
RUN_INSTRUCT: "java -Xms32m -Xmx200m -jar ./app.jar" |
|||
deploy: |
|||
resources: |
|||
limits: |
|||
cpus: '0.1' |
|||
memory: 300M |
@ -0,0 +1,17 @@ |
|||
version: "3.7" |
|||
services: |
|||
epmet-user-server: |
|||
container_name: epmet-openapi-scan-test |
|||
image: registry-vpc.cn-qingdao.aliyuncs.com/epmet-cloud-release/epmet-user-scan:0.3.53 |
|||
ports: |
|||
- "8107:8107" |
|||
network_mode: host # 不会创建新的网络 |
|||
volumes: |
|||
- "/opt/epmet-cloud-logs/test:/logs" |
|||
environment: |
|||
RUN_INSTRUCT: "java -Xms32m -Xmx200m -jar ./app.jar" |
|||
deploy: |
|||
resources: |
|||
limits: |
|||
cpus: '0.1' |
|||
memory: 300M |
@ -0,0 +1,136 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|||
<parent> |
|||
<artifactId>epmet-cloud</artifactId> |
|||
<groupId>com.epmet</groupId> |
|||
<version>2.0.0</version> |
|||
</parent> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<artifactId>epmet-openapi-scan</artifactId> |
|||
<packaging>jar</packaging> |
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-web</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework</groupId> |
|||
<artifactId>spring-context-support</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-actuator</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.alibaba.cloud</groupId> |
|||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.alibaba.cloud</groupId> |
|||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.epmet</groupId> |
|||
<artifactId>epmet-commons-tools</artifactId> |
|||
<version>2.0.0</version> |
|||
</dependency> |
|||
<!--aliyun green--> |
|||
<dependency> |
|||
<groupId>com.aliyun</groupId> |
|||
<artifactId>aliyun-java-sdk-core</artifactId> |
|||
<version>3.5.0</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.aliyun</groupId> |
|||
<artifactId>aliyun-java-sdk-green</artifactId> |
|||
<version>3.5.0</version> |
|||
</dependency> |
|||
<!-- httpclient --> |
|||
<dependency> |
|||
<groupId>org.apache.httpcomponents</groupId> |
|||
<artifactId>httpclient</artifactId> |
|||
<version>4.5.2</version> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
<build> |
|||
<finalName>${project.artifactId}</finalName> |
|||
<plugins> |
|||
<plugin> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-maven-plugin</artifactId> |
|||
</plugin> |
|||
<plugin> |
|||
<groupId>org.apache.maven.plugins</groupId> |
|||
<artifactId>maven-surefire-plugin</artifactId> |
|||
<configuration> |
|||
<skipTests>true</skipTests> |
|||
</configuration> |
|||
</plugin> |
|||
</plugins> |
|||
|
|||
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> |
|||
<resources> |
|||
<resource> |
|||
<filtering>true</filtering> |
|||
<directory>${basedir}/src/main/resources</directory> |
|||
</resource> |
|||
</resources> |
|||
</build> |
|||
|
|||
<profiles> |
|||
<profile> |
|||
<id>dev</id> |
|||
<activation> |
|||
<activeByDefault>true</activeByDefault> |
|||
</activation> |
|||
<properties> |
|||
<server.port>8107</server.port> |
|||
<spring.profiles.active>dev</spring.profiles.active> |
|||
|
|||
|
|||
<!-- redis配置 --> |
|||
<spring.redis.index>0</spring.redis.index> |
|||
<spring.redis.host>192.168.1.130</spring.redis.host> |
|||
<spring.redis.port>6379</spring.redis.port> |
|||
<spring.redis.password>123456</spring.redis.password> |
|||
<!-- nacos --> |
|||
<nacos.register-enabled>true</nacos.register-enabled> |
|||
<nacos.server-addr>122.152.200.70:8848</nacos.server-addr> |
|||
<nacos.discovery.namespace>fcd6fc8f-ca3a-4b01-8026-2b05cdc5976b</nacos.discovery.namespace> |
|||
<nacos.config.namespace></nacos.config.namespace> |
|||
<nacos.config.group></nacos.config.group> |
|||
<nacos.config-enabled>false</nacos.config-enabled> |
|||
<nacos.ip/> |
|||
</properties> |
|||
</profile> |
|||
<profile> |
|||
<id>test</id> |
|||
<!-- <activation> |
|||
<activeByDefault>true</activeByDefault> |
|||
</activation>--> |
|||
<properties> |
|||
<server.port>8107</server.port> |
|||
<spring.profiles.active>test</spring.profiles.active> |
|||
|
|||
<!-- redis配置 --> |
|||
<spring.redis.index>0</spring.redis.index> |
|||
<spring.redis.host>r-m5eoz5b6tkx09y6bpz.redis.rds.aliyuncs.com</spring.redis.host> |
|||
<spring.redis.port>6379</spring.redis.port> |
|||
<spring.redis.password>EpmEtrEdIs!q@w</spring.redis.password> |
|||
<!-- nacos --> |
|||
<nacos.register-enabled>true</nacos.register-enabled> |
|||
<nacos.server-addr>192.168.10.150:8848</nacos.server-addr> |
|||
<nacos.discovery.namespace>67e3c350-533e-4d7c-9f8f-faf1b4aa82ae</nacos.discovery.namespace> |
|||
<nacos.config.namespace></nacos.config.namespace> |
|||
<nacos.config.group></nacos.config.group> |
|||
<nacos.config-enabled>false</nacos.config-enabled> |
|||
<nacos.ip/> |
|||
</properties> |
|||
</profile> |
|||
</profiles> |
|||
|
|||
</project> |
@ -0,0 +1,28 @@ |
|||
/** |
|||
* 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; |
|||
|
|||
/** |
|||
* 管理后台 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
|
|||
@SpringBootApplication |
|||
public class ScanApplication { |
|||
|
|||
public static void main(String[] args) { |
|||
SpringApplication.run(ScanApplication.class, args); |
|||
} |
|||
|
|||
} |
@ -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(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,46 @@ |
|||
package com.epmet.openapi.scan.common.enu; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @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<String> getImgSceneList() { |
|||
List<String> 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; |
|||
} |
|||
} |
@ -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; |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
package com.epmet.openapi.scan.controller; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.epmet.commons.tools.utils.Result; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @author jianjun liu |
|||
* @date 2020-06-04 20:39 |
|||
**/ |
|||
@RestController |
|||
@RequestMapping("test") |
|||
public class TestController { |
|||
@Value("${aliyun.green.accessKeyId}") |
|||
private String accessKeyId; |
|||
|
|||
@Value("${aliyun.green.accessKeySecret}") |
|||
private String accessKeySecret; |
|||
|
|||
@Value("${aliyun.green.regionId}") |
|||
private String regionId; |
|||
@GetMapping("api") |
|||
public Result<String> page() { |
|||
Map<String,Object> map = new HashMap<>(); |
|||
map.put(accessKeyId,accessKeyId); |
|||
map.put(accessKeySecret,accessKeySecret); |
|||
map.put(regionId, regionId); |
|||
return new Result<String>().ok(JSON.toJSONString(map)); |
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
package com.epmet.openapi.scan.support.param; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 审查参数 |
|||
* |
|||
* @author jianjun liu |
|||
* @date 2020-06-04 21:57 |
|||
**/ |
|||
@Data |
|||
public class ScanParam { |
|||
/** |
|||
* 场景 必填 |
|||
* |
|||
* @see com.epmet.openapi.scan.common.enu.ImgSceneEnum; |
|||
*/ |
|||
private List<String> scenes; |
|||
|
|||
/** |
|||
* 要检测的内容列表,必填 |
|||
* remark:一组任务列表中的taskId不能相同 |
|||
*/ |
|||
private List<Task> tasks; |
|||
|
|||
/** |
|||
* 异步检测结果回调地址,执行异步审查内容时 必填 |
|||
*/ |
|||
private String callback; |
|||
|
|||
/** |
|||
* 随机字符串,该值用于回调通知请求中的签名,使用callback时 必填 |
|||
*/ |
|||
private String seed; |
|||
} |
@ -0,0 +1,25 @@ |
|||
package com.epmet.openapi.scan.support.param; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 任务参数 |
|||
* |
|||
* @author jianjun liu |
|||
* @email liujianjun@yunzongnet.com |
|||
* @date 2020-06-04 22:13 |
|||
**/ |
|||
@Data |
|||
public class Task { |
|||
|
|||
/** |
|||
* 要检测的数据id 非必填 |
|||
* |
|||
* */ |
|||
private String dataId; |
|||
|
|||
/** |
|||
* 图片url 必填 |
|||
*/ |
|||
private String url; |
|||
} |
@ -0,0 +1,77 @@ |
|||
server: |
|||
port: @server.port@ |
|||
servlet: |
|||
context-path: /epmetscan |
|||
|
|||
spring: |
|||
main: |
|||
allow-bean-definition-overriding: true |
|||
application: |
|||
name: epmet-openapi-scan |
|||
#环境 dev|test|prod |
|||
profiles: |
|||
active: dev |
|||
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 |
|||
httpclient: |
|||
enabled: true |
|||
|
|||
|
|||
hystrix: |
|||
command: |
|||
default: |
|||
execution: |
|||
isolation: |
|||
thread: |
|||
timeoutInMilliseconds: 60000 #缺省为1000 |
|||
|
|||
ribbon: |
|||
ReadTimeout: 300000 |
|||
ConnectTimeout: 300000 |
|||
|
|||
aliyun: |
|||
green: |
|||
accessKeyId: 123 |
|||
accessKeySecret: 456 |
|||
regionId: cn-shanghai |
@ -0,0 +1,164 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<configuration> |
|||
<include resource="org/springframework/boot/logging/logback/base.xml"/> |
|||
|
|||
<property name="log.path" value="logs/epmet/openapi/scan"/> |
|||
|
|||
<springProperty scope="context" name="appname" source="spring.application.name"/> |
|||
|
|||
<!-- 日志上下文名称 --> |
|||
<contextName>${appname}</contextName> |
|||
|
|||
<!-- 彩色日志格式 --> |
|||
<property name="CONSOLE_LOG_PATTERN" |
|||
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> |
|||
|
|||
<!--1. 输出到控制台--> |
|||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> |
|||
<!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息--> |
|||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> |
|||
<level>debug</level> |
|||
</filter> |
|||
<encoder> |
|||
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern> |
|||
<!-- 设置字符集 --> |
|||
<charset>UTF-8</charset> |
|||
</encoder> |
|||
</appender> |
|||
|
|||
<!--2. 输出到文档--> |
|||
<!-- 2.1 level为 DEBUG 日志,时间滚动输出 --> |
|||
<appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
|||
<!-- 正在记录的日志文档的路径及文档名 --> |
|||
<file>${log.path}/debug.log</file> |
|||
<!--日志文档输出格式--> |
|||
<encoder> |
|||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n</pattern> |
|||
<charset>UTF-8</charset> <!-- 设置字符集 --> |
|||
</encoder> |
|||
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
|||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
|||
<!-- 日志归档 --> |
|||
<fileNamePattern>${log.path}/debug-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
|||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
|||
<maxFileSize>100MB</maxFileSize> |
|||
</timeBasedFileNamingAndTriggeringPolicy> |
|||
<!--日志文档保留天数--> |
|||
<maxHistory>15</maxHistory> |
|||
</rollingPolicy> |
|||
<!-- 此日志文档只记录debug级别的 --> |
|||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
|||
<level>debug</level> |
|||
<onMatch>ACCEPT</onMatch> |
|||
<onMismatch>DENY</onMismatch> |
|||
</filter> |
|||
</appender> |
|||
|
|||
<!-- 2.2 level为 INFO 日志,时间滚动输出 --> |
|||
<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
|||
<!-- 正在记录的日志文档的路径及文档名 --> |
|||
<file>${log.path}/info.log</file> |
|||
<!--日志文档输出格式--> |
|||
<encoder> |
|||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n</pattern> |
|||
<charset>UTF-8</charset> |
|||
</encoder> |
|||
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
|||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
|||
<!-- 每天日志归档路径以及格式 --> |
|||
<fileNamePattern>${log.path}/info-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
|||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
|||
<maxFileSize>100MB</maxFileSize> |
|||
</timeBasedFileNamingAndTriggeringPolicy> |
|||
<!--日志文档保留天数--> |
|||
<maxHistory>15</maxHistory> |
|||
</rollingPolicy> |
|||
<!-- 此日志文档只记录info级别的 --> |
|||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
|||
<level>info</level> |
|||
<onMatch>ACCEPT</onMatch> |
|||
<onMismatch>DENY</onMismatch> |
|||
</filter> |
|||
</appender> |
|||
|
|||
<!-- 2.3 level为 WARN 日志,时间滚动输出 --> |
|||
<appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
|||
<!-- 正在记录的日志文档的路径及文档名 --> |
|||
<file>${log.path}/warn.log</file> |
|||
<!--日志文档输出格式--> |
|||
<encoder> |
|||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n</pattern> |
|||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
|||
</encoder> |
|||
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
|||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
|||
<fileNamePattern>${log.path}/warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
|||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
|||
<maxFileSize>100MB</maxFileSize> |
|||
</timeBasedFileNamingAndTriggeringPolicy> |
|||
<!--日志文档保留天数--> |
|||
<maxHistory>15</maxHistory> |
|||
</rollingPolicy> |
|||
<!-- 此日志文档只记录warn级别的 --> |
|||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
|||
<level>warn</level> |
|||
<onMatch>ACCEPT</onMatch> |
|||
<onMismatch>DENY</onMismatch> |
|||
</filter> |
|||
</appender> |
|||
|
|||
<!-- 2.4 level为 ERROR 日志,时间滚动输出 --> |
|||
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
|||
<!-- 正在记录的日志文档的路径及文档名 --> |
|||
<file>${log.path}/error.log</file> |
|||
<!--日志文档输出格式--> |
|||
<encoder> |
|||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%contextName] [%thread] %-5level %logger{50} - %msg%n</pattern> |
|||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
|||
</encoder> |
|||
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
|||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
|||
<fileNamePattern>${log.path}/error-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
|||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
|||
<maxFileSize>100MB</maxFileSize> |
|||
</timeBasedFileNamingAndTriggeringPolicy> |
|||
<!--日志文档保留天数--> |
|||
<maxHistory>15</maxHistory> |
|||
</rollingPolicy> |
|||
<!-- 此日志文档只记录ERROR级别的 --> |
|||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
|||
<level>ERROR</level> |
|||
<onMatch>ACCEPT</onMatch> |
|||
<onMismatch>DENY</onMismatch> |
|||
</filter> |
|||
</appender> |
|||
|
|||
<!-- 开发、测试环境 --> |
|||
<springProfile name="dev,test"> |
|||
<logger name="org.springframework.web" level="INFO"/> |
|||
<logger name="org.springboot.sample" level="INFO"/> |
|||
<logger name="com.epmet.dao" level="INFO"/> |
|||
<logger name="com.epmet.dao" level="DEBUG"/> |
|||
<root level="INFO"> |
|||
<appender-ref ref="DEBUG_FILE"/> |
|||
<appender-ref ref="INFO_FILE"/> |
|||
<appender-ref ref="WARN_FILE"/> |
|||
<appender-ref ref="ERROR_FILE"/> |
|||
</root> |
|||
</springProfile> |
|||
|
|||
<!-- 生产环境 --> |
|||
<springProfile name="prod"> |
|||
<logger name="org.springframework.web" level="INFO"/> |
|||
<logger name="org.springboot.sample" level="INFO"/> |
|||
<logger name="com.epmet.dao" level="INFO"/> |
|||
<root level="INFO"> |
|||
<appender-ref ref="CONSOLE"/> |
|||
<appender-ref ref="DEBUG_FILE"/> |
|||
<appender-ref ref="INFO_FILE"/> |
|||
<appender-ref ref="WARN_FILE"/> |
|||
<appender-ref ref="ERROR_FILE"/> |
|||
</root> |
|||
</springProfile> |
|||
|
|||
</configuration> |
@ -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; |
|||
} |
|||
|
|||
} |
@ -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<Map<String, Object>> tasks = new ArrayList<Map<String, Object>>(); |
|||
Map<String, Object> task1 = new LinkedHashMap<String, Object>(); |
|||
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(); |
|||
} |
|||
} |
|||
} |
@ -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<String> taskIds = new ArrayList<String>(); |
|||
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(); |
|||
} |
|||
} |
|||
} |
@ -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<Map<String, Object>> tasks = new ArrayList<Map<String, Object>>(); |
|||
Map<String, Object> task = new LinkedHashMap<String, Object>(); |
|||
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(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|||
<parent> |
|||
<artifactId>epmet-cloud</artifactId> |
|||
<groupId>com.epmet</groupId> |
|||
<version>2.0.0</version> |
|||
</parent> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
<packaging>jar</packaging> |
|||
|
|||
<artifactId>epmet-openapi</artifactId> |
|||
<modules> |
|||
<module>epmet-openapi-scan</module> |
|||
</modules> |
|||
|
|||
</project> |
Loading…
Reference in new issue