diff --git a/springboot.iml b/springboot.iml index 56a71e9..58631eb 100644 --- a/springboot.iml +++ b/springboot.iml @@ -105,6 +105,20 @@ + + + + + + + + + + + + + + diff --git a/springboot/pom.xml b/springboot/pom.xml index 926e2e3..5d160c8 100644 --- a/springboot/pom.xml +++ b/springboot/pom.xml @@ -134,6 +134,11 @@ commons-lang3 3.1 + + + org.springframework.boot + spring-boot-starter-data-redis + org.springframework.cloud diff --git a/springboot/src/main/java/com/sincre/springboot/ApiModel/FacePlusResult.java b/springboot/src/main/java/com/sincre/springboot/ApiModel/FacePlusResult.java new file mode 100644 index 0000000..6283032 --- /dev/null +++ b/springboot/src/main/java/com/sincre/springboot/ApiModel/FacePlusResult.java @@ -0,0 +1,26 @@ +package com.sincre.springboot.ApiModel; + +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class FacePlusResult { + + private int error_code; + private String error_message; + + public String getError_message() { + return error_message; + } + + public void setError_message(String error_message) { + this.error_message = error_message; + } + + public int getError_code() { + return error_code; + } + + public void setError_code(int error_code) { + this.error_code = error_code; + } +} diff --git a/springboot/src/main/java/com/sincre/springboot/ApiModel/YinShiResResult.java b/springboot/src/main/java/com/sincre/springboot/ApiModel/YinShiResResult.java index 2a9c56a..2f721b9 100644 --- a/springboot/src/main/java/com/sincre/springboot/ApiModel/YinShiResResult.java +++ b/springboot/src/main/java/com/sincre/springboot/ApiModel/YinShiResResult.java @@ -9,6 +9,8 @@ public class YinShiResResult { private Page page ; private T data; + private Integer code; + private String msg; public T getData() { return data; @@ -41,8 +43,7 @@ public class YinShiResResult { public void setPage(Page page) { this.page = page; } - private Integer code; - private String msg; + } diff --git a/springboot/src/main/java/com/sincre/springboot/ApiPlatform/FacePlusConfig.java b/springboot/src/main/java/com/sincre/springboot/ApiPlatform/FacePlusConfig.java new file mode 100644 index 0000000..51825ac --- /dev/null +++ b/springboot/src/main/java/com/sincre/springboot/ApiPlatform/FacePlusConfig.java @@ -0,0 +1,13 @@ +package com.sincre.springboot.ApiPlatform; + +public class FacePlusConfig { + + + /** + * 旷视 api 基础参数 + */ + public static String hostUrl = "https://api-cn.faceplusplus.com"; + public static String apiKey = "Xgyw3EZmAO70MOHVmt0q-zHWtmZEHtYP"; + public static String apiSecret = "uskc2mPcC7dQIh-aTdOqsym9kS0bl_hE"; + +} diff --git a/springboot/src/main/java/com/sincre/springboot/controller/FacePlusController.java b/springboot/src/main/java/com/sincre/springboot/controller/FacePlusController.java new file mode 100644 index 0000000..aee0a62 --- /dev/null +++ b/springboot/src/main/java/com/sincre/springboot/controller/FacePlusController.java @@ -0,0 +1,89 @@ +package com.sincre.springboot.controller; + +import com.alibaba.fastjson.JSON; +import com.sincre.springboot.ApiModel.FacePlusResult; +import com.sincre.springboot.ApiPlatform.FacePlusConfig; +import com.sincre.springboot.common.ServerResponse; +import com.sincre.springboot.utils.ApiHelper; +import com.sincre.springboot.utils.ResultUtils; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.omg.CORBA.Any; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import springfox.documentation.spring.web.json.Json; + +import java.util.HashMap; +import java.util.Map; + +@RestController +@RequestMapping(value = "/FacePlus/*") +@Api(tags = "旷视云服务API") +public class FacePlusController { + + + @ApiOperation("人脸数据注册") + @ApiImplicitParam(name = "imageUrl",value = "人脸图片地址",required = true) + @PostMapping("detect") + public ServerResponse detect(String imageUrl){ + + String url = FacePlusConfig.hostUrl + "/facepp/v3/detect"; + Map head = new HashMap<>(); + Map body = setUpCommonBody(); + body.put("image_url",imageUrl); + + String result = ApiHelper.doPost(url,head,body); + FacePlusResult faceResult = JSON.parseObject(result,FacePlusResult.class); + return ResultUtils.getInstance().returnResult_Face(faceResult,result); + } + + + @ApiOperation("人脸数据比较") + @ApiImplicitParams({ + @ApiImplicitParam(name = "faceToken1",value = "人脸1token",required = true), + @ApiImplicitParam(name = "faceToken2",value = "人脸2token",required = true) + }) + @PostMapping("compare") + public ServerResponse compare(String faceToken1,String faceToken2){ + + String url = FacePlusConfig.hostUrl + "/facepp/v3/compare"; + Map head = new HashMap<>(); + Map body = setUpCommonBody(); + body.put("face_token1",faceToken1); + body.put("face_token2",faceToken2); + + String result = ApiHelper.doPost(url,head,body); + FacePlusResult faceResult = JSON.parseObject(result,FacePlusResult.class); + return ResultUtils.getInstance().returnResult_Face(faceResult,result); + } + + @ApiOperation("人脸数据查询") + @ApiImplicitParam(name = "faceToken",value = "人脸token",required = true) + @PostMapping("search") + public ServerResponse search(String faceToken){ + + String url = FacePlusConfig.hostUrl + "/facepp/v3/search"; + Map head = new HashMap<>(); + Map body = setUpCommonBody(); + body.put("face_token",faceToken); + + String result = ApiHelper.doPost(url,head,body); + FacePlusResult faceResult = JSON.parseObject(result,FacePlusResult.class); + return ResultUtils.getInstance().returnResult_Face(faceResult,result); + } + + /** + * 通用参数 + * @return + */ + private Map setUpCommonBody(){ + + Map map = new HashMap<>(); + map.put("api_key", FacePlusConfig.apiKey); + map.put("api_secret",FacePlusConfig.apiSecret); + return map; + } +} diff --git a/springboot/src/main/java/com/sincre/springboot/utils/ResultUtils.java b/springboot/src/main/java/com/sincre/springboot/utils/ResultUtils.java index 9e6aeb9..2870ddc 100644 --- a/springboot/src/main/java/com/sincre/springboot/utils/ResultUtils.java +++ b/springboot/src/main/java/com/sincre/springboot/utils/ResultUtils.java @@ -4,6 +4,7 @@ package com.sincre.springboot.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.sincre.springboot.ApiModel.BaiduResult; +import com.sincre.springboot.ApiModel.FacePlusResult; import com.sincre.springboot.ApiModel.TuYaResResult; import com.sincre.springboot.ApiModel.YinShiResResult; import com.sincre.springboot.common.ResponseCode; @@ -114,4 +115,50 @@ public class ResultUtils { return ServerResponse.createByErrorMessage("服务器内部处理出错!"); } } + /** + * 旷视返回结果 + * @param result + * @return + */ + public ServerResponse returnResult_Face(FacePlusResult result,String data){ + + try{ + String msg = result.getError_message(); + if (msg == null) { + return ServerResponse.createBySuccess(data); + }else{ + int errorCode = 400; + switch (msg) { + case "AUTHENTICATION_ERROR": + errorCode = 401; + break; + case "AUTHORIZATION_ERROR": + errorCode = 403; + break; + case "CONCURRENCY_LIMIT_EXCEEDED": + errorCode = 403; + break; + case "IMAGE_DOWNLOAD_TIMEOUT": + errorCode = 412; + case "Request Entity Too Large": + errorCode = 413; + break; + case "API_NOT_FOUND": + errorCode = 404; + break; + case "INTERNAL_ERROR": + errorCode = 500; + break; + default: + break; + } + return ServerResponse.createByErrorCodeMessage(errorCode,msg); + } + }catch (Exception e){ + return ServerResponse.createByErrorMessage("服务器内部处理出错!"); + } + + + } + } diff --git a/springboot/src/main/resources/application.properties b/springboot/src/main/resources/application.properties index bac78b2..9e1d1bc 100644 --- a/springboot/src/main/resources/application.properties +++ b/springboot/src/main/resources/application.properties @@ -17,3 +17,24 @@ eureka.client.register-with-ecueka=false #不去检索服务 eureka.client.fetch-registry=false eureka.client.serviceUrl.defaultZone=http://121.40.109.21:8761/eureka/ + +# http://121.40.109.21:8761/eureka/,http://121.40.109.21:8762/eureka/ +#Redis 配置 +# Redis数据库索引(默认为0) +spring.redis.database=0 +# Redis服务器地址 +spring.redis.host=127.0.0.1 +# Redis服务器连接端口 +spring.redis.port=6379 +# Redis服务器连接密码(默认为空) +spring.redis.password= +# 连接池最大连接数(使用负值表示没有限制) +spring.redis.jedis.pool.max-active=20 +# 连接池最大阻塞等待时间(使用负值表示没有限制) +spring.redis.jedis.pool.max-wait=-1 +# 连接池中的最大空闲连接 +spring.redis.jedis.pool.max-idle=10 +# 连接池中的最小空闲连接 +spring.redis.jedis.pool.min-idle=0 +# 连接超时时间(毫秒) +spring.redis.timeout=1000 \ No newline at end of file -- libgit2 0.21.0