新增了身份证识别,去除了反面
This commit is contained in:
parent
6cc5dc58de
commit
6119e760d3
@ -24,23 +24,17 @@ public class ImageController {
|
||||
@ApiOperation(value = "身份证识别-ocr")
|
||||
@PostMapping("/ocr/idCard")
|
||||
public ResponseDTO<GetIdCardOcrVo> 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) {
|
||||
|
||||
@ -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");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user