Commit a9c712fda8ebbaa1c179d8ea6f00a5e576bf0291
1 parent
773c31ce
Exists in
master
旷视云 api 配置,接口添加
Showing
8 changed files
with
218 additions
and
2 deletions
Show diff stats
springboot.iml
@@ -105,6 +105,20 @@ | @@ -105,6 +105,20 @@ | ||
105 | <orderEntry type="library" name="Maven: org.hdrhistogram:HdrHistogram:2.1.9" level="project" /> | 105 | <orderEntry type="library" name="Maven: org.hdrhistogram:HdrHistogram:2.1.9" level="project" /> |
106 | <orderEntry type="library" name="Maven: org.latencyutils:LatencyUtils:2.0.3" level="project" /> | 106 | <orderEntry type="library" name="Maven: org.latencyutils:LatencyUtils:2.0.3" level="project" /> |
107 | <orderEntry type="library" name="Maven: net.sf.ehcache:ehcache:2.10.6" level="project" /> | 107 | <orderEntry type="library" name="Maven: net.sf.ehcache:ehcache:2.10.6" level="project" /> |
108 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-redis:2.1.3.RELEASE" level="project" /> | ||
109 | + <orderEntry type="library" name="Maven: org.springframework.data:spring-data-redis:2.1.5.RELEASE" level="project" /> | ||
110 | + <orderEntry type="library" name="Maven: org.springframework.data:spring-data-keyvalue:2.1.5.RELEASE" level="project" /> | ||
111 | + <orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:2.1.5.RELEASE" level="project" /> | ||
112 | + <orderEntry type="library" name="Maven: org.springframework:spring-oxm:5.1.5.RELEASE" level="project" /> | ||
113 | + <orderEntry type="library" name="Maven: io.lettuce:lettuce-core:5.1.4.RELEASE" level="project" /> | ||
114 | + <orderEntry type="library" name="Maven: io.netty:netty-common:4.1.33.Final" level="project" /> | ||
115 | + <orderEntry type="library" name="Maven: io.netty:netty-handler:4.1.33.Final" level="project" /> | ||
116 | + <orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.33.Final" level="project" /> | ||
117 | + <orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.33.Final" level="project" /> | ||
118 | + <orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.33.Final" level="project" /> | ||
119 | + <orderEntry type="library" name="Maven: io.netty:netty-resolver:4.1.33.Final" level="project" /> | ||
120 | + <orderEntry type="library" name="Maven: io.projectreactor:reactor-core:3.2.6.RELEASE" level="project" /> | ||
121 | + <orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.2" level="project" /> | ||
108 | <orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-starter-netflix-eureka-server:2.1.1.RELEASE" level="project" /> | 122 | <orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-starter-netflix-eureka-server:2.1.1.RELEASE" level="project" /> |
109 | <orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-starter:2.1.1.RELEASE" level="project" /> | 123 | <orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-starter:2.1.1.RELEASE" level="project" /> |
110 | <orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-context:2.1.1.RELEASE" level="project" /> | 124 | <orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-context:2.1.1.RELEASE" level="project" /> |
springboot/pom.xml
@@ -134,6 +134,11 @@ | @@ -134,6 +134,11 @@ | ||
134 | <artifactId>commons-lang3</artifactId> | 134 | <artifactId>commons-lang3</artifactId> |
135 | <version>3.1</version> | 135 | <version>3.1</version> |
136 | </dependency> | 136 | </dependency> |
137 | + <!--redis配置--> | ||
138 | + <dependency> | ||
139 | + <groupId>org.springframework.boot</groupId> | ||
140 | + <artifactId>spring-boot-starter-data-redis</artifactId> | ||
141 | + </dependency> | ||
137 | <!--注册中心--> | 142 | <!--注册中心--> |
138 | <dependency> | 143 | <dependency> |
139 | <groupId>org.springframework.cloud</groupId> | 144 | <groupId>org.springframework.cloud</groupId> |
springboot/src/main/java/com/sincre/springboot/ApiModel/FacePlusResult.java
0 → 100644
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +package com.sincre.springboot.ApiModel; | ||
2 | + | ||
3 | +import com.fasterxml.jackson.annotation.JsonInclude; | ||
4 | + | ||
5 | +@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
6 | +public class FacePlusResult { | ||
7 | + | ||
8 | + private int error_code; | ||
9 | + private String error_message; | ||
10 | + | ||
11 | + public String getError_message() { | ||
12 | + return error_message; | ||
13 | + } | ||
14 | + | ||
15 | + public void setError_message(String error_message) { | ||
16 | + this.error_message = error_message; | ||
17 | + } | ||
18 | + | ||
19 | + public int getError_code() { | ||
20 | + return error_code; | ||
21 | + } | ||
22 | + | ||
23 | + public void setError_code(int error_code) { | ||
24 | + this.error_code = error_code; | ||
25 | + } | ||
26 | +} |
springboot/src/main/java/com/sincre/springboot/ApiModel/YinShiResResult.java
@@ -9,6 +9,8 @@ public class YinShiResResult<T> { | @@ -9,6 +9,8 @@ public class YinShiResResult<T> { | ||
9 | 9 | ||
10 | private Page page ; | 10 | private Page page ; |
11 | private T data; | 11 | private T data; |
12 | + private Integer code; | ||
13 | + private String msg; | ||
12 | 14 | ||
13 | public T getData() { | 15 | public T getData() { |
14 | return data; | 16 | return data; |
@@ -41,8 +43,7 @@ public class YinShiResResult<T> { | @@ -41,8 +43,7 @@ public class YinShiResResult<T> { | ||
41 | public void setPage(Page page) { | 43 | public void setPage(Page page) { |
42 | this.page = page; | 44 | this.page = page; |
43 | } | 45 | } |
44 | - private Integer code; | ||
45 | - private String msg; | 46 | + |
46 | } | 47 | } |
47 | 48 | ||
48 | 49 |
springboot/src/main/java/com/sincre/springboot/ApiPlatform/FacePlusConfig.java
0 → 100644
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +package com.sincre.springboot.ApiPlatform; | ||
2 | + | ||
3 | +public class FacePlusConfig { | ||
4 | + | ||
5 | + | ||
6 | + /** | ||
7 | + * 旷视 api 基础参数 | ||
8 | + */ | ||
9 | + public static String hostUrl = "https://api-cn.faceplusplus.com"; | ||
10 | + public static String apiKey = "Xgyw3EZmAO70MOHVmt0q-zHWtmZEHtYP"; | ||
11 | + public static String apiSecret = "uskc2mPcC7dQIh-aTdOqsym9kS0bl_hE"; | ||
12 | + | ||
13 | +} |
springboot/src/main/java/com/sincre/springboot/controller/FacePlusController.java
0 → 100644
@@ -0,0 +1,89 @@ | @@ -0,0 +1,89 @@ | ||
1 | +package com.sincre.springboot.controller; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSON; | ||
4 | +import com.sincre.springboot.ApiModel.FacePlusResult; | ||
5 | +import com.sincre.springboot.ApiPlatform.FacePlusConfig; | ||
6 | +import com.sincre.springboot.common.ServerResponse; | ||
7 | +import com.sincre.springboot.utils.ApiHelper; | ||
8 | +import com.sincre.springboot.utils.ResultUtils; | ||
9 | +import io.swagger.annotations.Api; | ||
10 | +import io.swagger.annotations.ApiImplicitParam; | ||
11 | +import io.swagger.annotations.ApiImplicitParams; | ||
12 | +import io.swagger.annotations.ApiOperation; | ||
13 | +import org.omg.CORBA.Any; | ||
14 | +import org.springframework.web.bind.annotation.PostMapping; | ||
15 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
16 | +import org.springframework.web.bind.annotation.RestController; | ||
17 | +import springfox.documentation.spring.web.json.Json; | ||
18 | + | ||
19 | +import java.util.HashMap; | ||
20 | +import java.util.Map; | ||
21 | + | ||
22 | +@RestController | ||
23 | +@RequestMapping(value = "/FacePlus/*") | ||
24 | +@Api(tags = "旷视云服务API") | ||
25 | +public class FacePlusController { | ||
26 | + | ||
27 | + | ||
28 | + @ApiOperation("人脸数据注册") | ||
29 | + @ApiImplicitParam(name = "imageUrl",value = "人脸图片地址",required = true) | ||
30 | + @PostMapping("detect") | ||
31 | + public ServerResponse detect(String imageUrl){ | ||
32 | + | ||
33 | + String url = FacePlusConfig.hostUrl + "/facepp/v3/detect"; | ||
34 | + Map<String,String> head = new HashMap<>(); | ||
35 | + Map<String,Object> body = setUpCommonBody(); | ||
36 | + body.put("image_url",imageUrl); | ||
37 | + | ||
38 | + String result = ApiHelper.doPost(url,head,body); | ||
39 | + FacePlusResult faceResult = JSON.parseObject(result,FacePlusResult.class); | ||
40 | + return ResultUtils.getInstance().returnResult_Face(faceResult,result); | ||
41 | + } | ||
42 | + | ||
43 | + | ||
44 | + @ApiOperation("人脸数据比较") | ||
45 | + @ApiImplicitParams({ | ||
46 | + @ApiImplicitParam(name = "faceToken1",value = "人脸1token",required = true), | ||
47 | + @ApiImplicitParam(name = "faceToken2",value = "人脸2token",required = true) | ||
48 | + }) | ||
49 | + @PostMapping("compare") | ||
50 | + public ServerResponse compare(String faceToken1,String faceToken2){ | ||
51 | + | ||
52 | + String url = FacePlusConfig.hostUrl + "/facepp/v3/compare"; | ||
53 | + Map<String,String> head = new HashMap<>(); | ||
54 | + Map<String,Object> body = setUpCommonBody(); | ||
55 | + body.put("face_token1",faceToken1); | ||
56 | + body.put("face_token2",faceToken2); | ||
57 | + | ||
58 | + String result = ApiHelper.doPost(url,head,body); | ||
59 | + FacePlusResult faceResult = JSON.parseObject(result,FacePlusResult.class); | ||
60 | + return ResultUtils.getInstance().returnResult_Face(faceResult,result); | ||
61 | + } | ||
62 | + | ||
63 | + @ApiOperation("人脸数据查询") | ||
64 | + @ApiImplicitParam(name = "faceToken",value = "人脸token",required = true) | ||
65 | + @PostMapping("search") | ||
66 | + public ServerResponse search(String faceToken){ | ||
67 | + | ||
68 | + String url = FacePlusConfig.hostUrl + "/facepp/v3/search"; | ||
69 | + Map<String,String> head = new HashMap<>(); | ||
70 | + Map<String,Object> body = setUpCommonBody(); | ||
71 | + body.put("face_token",faceToken); | ||
72 | + | ||
73 | + String result = ApiHelper.doPost(url,head,body); | ||
74 | + FacePlusResult faceResult = JSON.parseObject(result,FacePlusResult.class); | ||
75 | + return ResultUtils.getInstance().returnResult_Face(faceResult,result); | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * 通用参数 | ||
80 | + * @return | ||
81 | + */ | ||
82 | + private Map<String,Object> setUpCommonBody(){ | ||
83 | + | ||
84 | + Map<String,Object> map = new HashMap<>(); | ||
85 | + map.put("api_key", FacePlusConfig.apiKey); | ||
86 | + map.put("api_secret",FacePlusConfig.apiSecret); | ||
87 | + return map; | ||
88 | + } | ||
89 | +} |
springboot/src/main/java/com/sincre/springboot/utils/ResultUtils.java
@@ -4,6 +4,7 @@ package com.sincre.springboot.utils; | @@ -4,6 +4,7 @@ package com.sincre.springboot.utils; | ||
4 | import com.alibaba.fastjson.JSON; | 4 | import com.alibaba.fastjson.JSON; |
5 | import com.alibaba.fastjson.JSONArray; | 5 | import com.alibaba.fastjson.JSONArray; |
6 | import com.sincre.springboot.ApiModel.BaiduResult; | 6 | import com.sincre.springboot.ApiModel.BaiduResult; |
7 | +import com.sincre.springboot.ApiModel.FacePlusResult; | ||
7 | import com.sincre.springboot.ApiModel.TuYaResResult; | 8 | import com.sincre.springboot.ApiModel.TuYaResResult; |
8 | import com.sincre.springboot.ApiModel.YinShiResResult; | 9 | import com.sincre.springboot.ApiModel.YinShiResResult; |
9 | import com.sincre.springboot.common.ResponseCode; | 10 | import com.sincre.springboot.common.ResponseCode; |
@@ -114,4 +115,50 @@ public class ResultUtils { | @@ -114,4 +115,50 @@ public class ResultUtils { | ||
114 | return ServerResponse.createByErrorMessage("服务器内部处理出错!"); | 115 | return ServerResponse.createByErrorMessage("服务器内部处理出错!"); |
115 | } | 116 | } |
116 | } | 117 | } |
118 | + /** | ||
119 | + * 旷视返回结果 | ||
120 | + * @param result | ||
121 | + * @return | ||
122 | + */ | ||
123 | + public ServerResponse returnResult_Face(FacePlusResult result,String data){ | ||
124 | + | ||
125 | + try{ | ||
126 | + String msg = result.getError_message(); | ||
127 | + if (msg == null) { | ||
128 | + return ServerResponse.createBySuccess(data); | ||
129 | + }else{ | ||
130 | + int errorCode = 400; | ||
131 | + switch (msg) { | ||
132 | + case "AUTHENTICATION_ERROR": | ||
133 | + errorCode = 401; | ||
134 | + break; | ||
135 | + case "AUTHORIZATION_ERROR": | ||
136 | + errorCode = 403; | ||
137 | + break; | ||
138 | + case "CONCURRENCY_LIMIT_EXCEEDED": | ||
139 | + errorCode = 403; | ||
140 | + break; | ||
141 | + case "IMAGE_DOWNLOAD_TIMEOUT": | ||
142 | + errorCode = 412; | ||
143 | + case "Request Entity Too Large": | ||
144 | + errorCode = 413; | ||
145 | + break; | ||
146 | + case "API_NOT_FOUND": | ||
147 | + errorCode = 404; | ||
148 | + break; | ||
149 | + case "INTERNAL_ERROR": | ||
150 | + errorCode = 500; | ||
151 | + break; | ||
152 | + default: | ||
153 | + break; | ||
154 | + } | ||
155 | + return ServerResponse.createByErrorCodeMessage(errorCode,msg); | ||
156 | + } | ||
157 | + }catch (Exception e){ | ||
158 | + return ServerResponse.createByErrorMessage("服务器内部处理出错!"); | ||
159 | + } | ||
160 | + | ||
161 | + | ||
162 | + } | ||
163 | + | ||
117 | } | 164 | } |
springboot/src/main/resources/application.properties
@@ -17,3 +17,24 @@ eureka.client.register-with-ecueka=false | @@ -17,3 +17,24 @@ eureka.client.register-with-ecueka=false | ||
17 | #不去检索服务 | 17 | #不去检索服务 |
18 | eureka.client.fetch-registry=false | 18 | eureka.client.fetch-registry=false |
19 | eureka.client.serviceUrl.defaultZone=http://121.40.109.21:8761/eureka/ | 19 | eureka.client.serviceUrl.defaultZone=http://121.40.109.21:8761/eureka/ |
20 | + | ||
21 | +# http://121.40.109.21:8761/eureka/,http://121.40.109.21:8762/eureka/ | ||
22 | +#Redis 配置 | ||
23 | +# Redis数据库索引(默认为0) | ||
24 | +spring.redis.database=0 | ||
25 | +# Redis服务器地址 | ||
26 | +spring.redis.host=127.0.0.1 | ||
27 | +# Redis服务器连接端口 | ||
28 | +spring.redis.port=6379 | ||
29 | +# Redis服务器连接密码(默认为空) | ||
30 | +spring.redis.password= | ||
31 | +# 连接池最大连接数(使用负值表示没有限制) | ||
32 | +spring.redis.jedis.pool.max-active=20 | ||
33 | +# 连接池最大阻塞等待时间(使用负值表示没有限制) | ||
34 | +spring.redis.jedis.pool.max-wait=-1 | ||
35 | +# 连接池中的最大空闲连接 | ||
36 | +spring.redis.jedis.pool.max-idle=10 | ||
37 | +# 连接池中的最小空闲连接 | ||
38 | +spring.redis.jedis.pool.min-idle=0 | ||
39 | +# 连接超时时间(毫秒) | ||
40 | +spring.redis.timeout=1000 | ||
20 | \ No newline at end of file | 41 | \ No newline at end of file |