java腾讯艾城人脸对比对接代码实例

  

技术栈:

  
      <李>春季启动2. x   <李>腾讯李   <李> java版1.8本李   
  

注意事项:

  
      <李>本文内的“* *。* *”需要自己替换为自己的路径。   <李>常量内的“* *”需要自己定义自己内容。   <李>业务中认证图片,上传至阿里云OSS上李   
  

话不多说,直接上代码

  

<强> 1,pom文件:

        & lt; !——apache httpclient组件——比;   & lt; dependency>   & lt; groupId> org.apache.httpcomponents   & lt; artifactId> httpclient   & lt; version> 4.5.6   & lt;/dependency>         & lt; !——https://mvnrepository.com/artifact/com.aliyun.oss/aliyun-sdk-oss——比;   & lt; dependency>   & lt; groupId> com.aliyun.oss   & lt; artifactId> aliyun-sdk-oss   & lt; version> 2.2.1   & lt;/dependency>      

<强> 2人脸识别业务:FaceController文件:

        包com . * * . * * .合肥;         进口com.mb.initial.entity.Test;   进口com.mb.initial.enums.ResultEnum;   进口com.mb.initial.result.Result;   进口com.mb.initial.service.IFaceService;   进口com.mb.initial.util.ResultUtils;   进口io.swagger.annotations.Api;   进口io.swagger.annotations.ApiOperation;   进口io.swagger.annotations.ApiResponse;   进口io.swagger.annotations.ApiResponses;   进口org.slf4j.Logger;   进口org.slf4j.LoggerFactory;   进口org.springframework.beans.factory.annotation.Autowired;   进口org.springframework.web.bind.annotation.RequestMapping;   进口org.springframework.web.bind.annotation.RequestMethod;   进口org.springframework.web.bind.annotation.RequestParam;   进口org.springframework.web.bind.annotation.RestController;      进口javax.servlet.http.HttpServletRequest;   进口javax.servlet.http.HttpServletResponse;/* *   *人脸识别业务   * @author: yanjianghua   * @date: 2018/11/16 16:58   */@Api(值=" https://www.yisu.com/zixun/人脸识别业务”,描述=叭肆呈侗鹨滴瘛?   @ApiResponses (value=https://www.yisu.com/zixun/{@ApiResponse(代码=200,消息=俺晒Α?响应=Test.class)})   @RequestMapping (value=" https://www.yisu.com/1.0/face ",方法={RequestMethod。得到,RequestMethod.POST})   @RestController   公开课FaceController {      私人日志记录器=LoggerFactory.getLogger (FaceController.class);      @ autowired   私人IFaceService faceService;      @ApiOperation(值=" https://www.yisu.com/zixun/人脸对比信息接口”,指出=叭肆扯员刃畔⒔涌凇?   @RequestMapping (value=" https://www.yisu.com/getFaceCompare ")   公共结果getFaceCompare (@RequestParam (value=" https://www.yisu.com/zixun/imageBaseAuthentication ",要求=false)字符串imageBaseAuthentication,   @RequestParam (value=" https://www.yisu.com/zixun/imageBase ",要求=false)字符串imageBase,   HttpServletResponse的回应,   {HttpServletRequest请求)抛出异常      如果(imageBaseAuthentication==null | | imageBase==null | |”“.equals (imageBase) | |”“.equals (imageBaseAuthentication)) {   返回ResultUtils.response (ResultEnum.PARAMETER_NULL);   }      对象=faceService结果。getFaceCompare (imageBaseAuthentication imageBase);      如果(结果==null) {   返回ResultUtils.response (ResultEnum.ERROR);   其他}{   返回ResultUtils.response(结果);   }   }               }      

<强> 3,IFaceService文件:

        包com。* *。* * .service;/* *   *   * @author: yanjianghua   * @date: 2018/11/16访谈   */公共接口IFaceService {/* *   *人脸对比API接口   * @param imageBaseAuthentication   * @param imageBase   * @return   */imageBaseAuthentication getFaceCompare公共对象(字符串,字符串imageBase);      }      

<强> 4,逻辑实现类:IFaceServiceImpl

        包com。* *。* * .service.impl;         进口com.alibaba.fastjson.JSON;   进口com.alibaba.fastjson.JSONObject;   导入的com。* *。* * .constants.BaseConstants;   导入的com。* *。* * .exception.BillingException;   导入的com。* *。* * .result.HttpClientResult;   导入的com。* *。* * .service.IFaceService;   导入的com。* *。* * .util.HttpClientUtils;   导入的com。* *。* * .util.MD5Utils;   导入的com。* *。* * .util.TencentAISignUtils;   导入的com。* *。* * .util.TimeUtils;   进口org.springframework.stereotype.Service;      进口java.io.IOException;   进口java.util.HashMap;   进口java.util.Map;/* *   *   * @author: yanjianghua   * @date: 2018/11/16 16:50   */@ service   公共类IFaceServiceImpl实现IFaceService {      @Override   imageBaseAuthentication getFaceCompare公共对象(字符串,字符串imageBase) {   HttpClientResult结果=零;      String> Map

java腾讯艾城人脸对比对接代码实例