From 6119e760d3428d6e624407f4bd7ee3398245abdc Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Mon, 30 Jun 2025 16:52:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=86=E8=BA=AB=E4=BB=BD?= =?UTF-8?q?=E8=AF=81=E8=AF=86=E5=88=AB=EF=BC=8C=E5=8E=BB=E9=99=A4=E4=BA=86?= =?UTF-8?q?=E5=8F=8D=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/file/controller/ImageController.java | 10 +---- .../module/app/file/service/OcrService.java | 44 ++----------------- 2 files changed, 5 insertions(+), 49 deletions(-) diff --git a/sa-admin/src/main/java/net/lab1024/sa/admin/module/app/file/controller/ImageController.java b/sa-admin/src/main/java/net/lab1024/sa/admin/module/app/file/controller/ImageController.java index 4e6facc..199cbb0 100644 --- a/sa-admin/src/main/java/net/lab1024/sa/admin/module/app/file/controller/ImageController.java +++ b/sa-admin/src/main/java/net/lab1024/sa/admin/module/app/file/controller/ImageController.java @@ -24,23 +24,17 @@ public class ImageController { @ApiOperation(value = "身份证识别-ocr") @PostMapping("/ocr/idCard") public ResponseDTO getIdCardOcr( - @RequestParam("frontFile") MultipartFile frontFile, - @RequestParam("backFile") MultipartFile backFile + @RequestParam("frontFile") MultipartFile frontFile ){ if (frontFile == null || frontFile.isEmpty()) { return ResponseDTO.userErrorParam("参数错误"); } - if (backFile == null || backFile.isEmpty()) { - return ResponseDTO.userErrorParam("参数错误"); - } - try { byte[] frontBytes = frontFile.getBytes(); - byte[] backBytes = backFile.getBytes(); // 调用 Service - GetIdCardOcrVo result = ocrService.getIdCardOcr(frontBytes, backBytes); + GetIdCardOcrVo result = ocrService.getIdCardOcr(frontBytes); return ResponseDTO.app_ok(result); } catch (Exception e) { diff --git a/sa-admin/src/main/java/net/lab1024/sa/admin/module/app/file/service/OcrService.java b/sa-admin/src/main/java/net/lab1024/sa/admin/module/app/file/service/OcrService.java index 706951a..e78caf7 100644 --- a/sa-admin/src/main/java/net/lab1024/sa/admin/module/app/file/service/OcrService.java +++ b/sa-admin/src/main/java/net/lab1024/sa/admin/module/app/file/service/OcrService.java @@ -22,10 +22,10 @@ public class OcrService { /** * 身份证识别 */ - public GetIdCardOcrVo getIdCardOcr(byte[] frontBytes,byte[] backBytes) { + public GetIdCardOcrVo getIdCardOcr(byte[] frontBytes) { try { - // 反面 - JSONObject result = ocr.idCard(backBytes,"back"); + // 正面 + JSONObject result = ocr.idCard(frontBytes,"front"); String imageStatus = result.getString("image_status"); switch (imageStatus) { @@ -62,44 +62,6 @@ public class OcrService { } } - // 正面 - result = ocr.idCard(frontBytes,"front"); - - imageStatus = result.getString("image_status"); - switch (imageStatus) { - case "normal": - // 识别正常,继续处理 - break; - case "reversed_side": - throw new BusinessException("身份证未摆正,请重新上传"); - case "non_idcard": - throw new BusinessException("上传的图片中不包含身份证,请上传正确图片"); - case "blurred": - throw new BusinessException("身份证模糊,请重新上传清晰图片"); - case "over_exposure": - throw new BusinessException("身份证关键字段反光或过曝,请重新拍摄"); - case "unknown": - default: - throw new BusinessException("无法识别身份证,请重新上传"); - } - - if (result.has("risk_type")) { - String riskType = result.getString("risk_type"); - if (!"normal".equals(riskType)) { - switch (riskType) { - case "copy": - throw new BusinessException("检测到复印件身份证,请上传原件"); - case "temporary": - throw new BusinessException("检测到临时身份证,请上传正式身份证"); - case "screen": - throw new BusinessException("检测到翻拍身份证,请上传原件照片"); - case "unknow": - default: - throw new BusinessException("身份证真实性存疑,请重新上传"); - } - } - } - // 解析识别结果 String name = result.getJSONObject("words_result").getJSONObject("姓名").getString("words"); String idNo = result.getJSONObject("words_result").getJSONObject("公民身份号码").getString("words");