ApiController.java 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package com.yx.face.controller.api;
  2. import com.yx.face.boot.core.BaseController;
  3. import com.yx.face.boot.restful.RestResponse;
  4. import com.yx.face.boot.restful.RestResult;
  5. import com.yx.face.model.dto.WxInfoDTO;
  6. import com.yx.face.service.FaceService;
  7. import com.yx.face.service.UserInfoService;
  8. import io.swagger.annotations.Api;
  9. import io.swagger.annotations.ApiOperation;
  10. import lombok.RequiredArgsConstructor;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.*;
  13. import javax.servlet.http.HttpServletRequest;
  14. import java.io.BufferedInputStream;
  15. import java.io.IOException;
  16. import java.io.InputStream;
  17. import java.nio.charset.StandardCharsets;
  18. import java.util.Map;
  19. /**
  20. * @description: 地址编码表(AreaCode)表控制层 <br>
  21. * @author: PWB <br>
  22. * @since: 1.0 <br>
  23. * @date: 2021-06-04 14:25:45 <br>
  24. */
  25. @RequiredArgsConstructor(onConstructor = @__(@Autowired))
  26. @Api(tags = "A 人脸下发相关功能接口 API")
  27. @RestController
  28. @RequestMapping("api/next")
  29. public class ApiController extends BaseController {
  30. /**
  31. * 服务对象
  32. */
  33. private final FaceService faceService;
  34. private final UserInfoService userInfoService;
  35. /**
  36. * 小程序访问
  37. * @param taskId
  38. * @return
  39. */
  40. @ApiOperation(value = "查询人脸下发是否成功")
  41. @GetMapping("doQueryFaceSuccess")
  42. public RestResult<Map<String, Object>> doQueryFaceSuccess(@RequestParam String taskId) {
  43. return RestResponse.ok(faceService.queryFaceSuccess(taskId));
  44. }
  45. @ApiOperation(value = "获取微信用户绑定的手机号")
  46. @PostMapping("doGetPhone")
  47. public RestResult<String> phone(@RequestBody WxInfoDTO dto) {
  48. return RestResponse.ok(userInfoService.getWxPhone(dto));
  49. }
  50. @ApiOperation(value = "人脸下发")
  51. @GetMapping("doGetFacePass")
  52. public RestResult<Map<String, Object>> doGetFacePass(Integer userId, String taskId) {
  53. return RestResponse.ok(userInfoService.doGetFacePass(userId, taskId));
  54. }
  55. @ApiOperation(value = "注册人脸认证回调接口")
  56. @PostMapping("doConfirmFaceNotify")
  57. public void doConfirmFaceNotify(HttpServletRequest request) {
  58. StringBuilder sb = new StringBuilder();
  59. try (InputStream is = request.getInputStream();
  60. BufferedInputStream bis = new BufferedInputStream(is)) {
  61. byte[] buffer = new byte[1024];
  62. int read;
  63. while ((read = bis.read(buffer)) != -1) {
  64. sb.append(new String(buffer, 0, read, StandardCharsets.UTF_8));
  65. }
  66. } catch (IOException e) {
  67. return;
  68. }
  69. userInfoService.confirmFaceNotify(sb.toString());
  70. }
  71. }