|
@@ -1,6 +1,7 @@
|
|
|
package com.crm.manager.service.impl;
|
|
package com.crm.manager.service.impl;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.crm.manager.config.ImageConfig;
|
|
import com.crm.manager.config.ImageConfig;
|
|
|
import com.crm.manager.repository.ImageRecognizeConfigRepository;
|
|
import com.crm.manager.repository.ImageRecognizeConfigRepository;
|
|
|
import com.crm.manager.service.OcrService;
|
|
import com.crm.manager.service.OcrService;
|
|
@@ -11,17 +12,13 @@ import com.crm.rely.backend.core.dto.base.BaseResultDto;
|
|
|
import com.crm.rely.backend.core.exception.ServiceException;
|
|
import com.crm.rely.backend.core.exception.ServiceException;
|
|
|
import com.crm.rely.backend.core.pojo.table.SysConfigTable;
|
|
import com.crm.rely.backend.core.pojo.table.SysConfigTable;
|
|
|
import com.crm.rely.backend.model.constant.ConfigConstants;
|
|
import com.crm.rely.backend.model.constant.ConfigConstants;
|
|
|
-import com.crm.rely.backend.model.entity.ocr.IdCardData;
|
|
|
|
|
import com.crm.rely.backend.model.entity.ocr.OcrCheckEntity;
|
|
import com.crm.rely.backend.model.entity.ocr.OcrCheckEntity;
|
|
|
-import com.crm.rely.backend.model.entity.ocr.OcrResult;
|
|
|
|
|
import com.crm.rely.backend.model.pojo.table.ImageRecognizeConfigTable;
|
|
import com.crm.rely.backend.model.pojo.table.ImageRecognizeConfigTable;
|
|
|
import com.crm.rely.backend.util.AESUtil;
|
|
import com.crm.rely.backend.util.AESUtil;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.jsoup.Connection;
|
|
import org.jsoup.Connection;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
@@ -49,8 +46,8 @@ public class OcrServiceImpl implements OcrService {
|
|
|
entity.setImageBase64(HutoolAesUtil.decrypt(entity.getImageBase64(),getPropertyKey()));
|
|
entity.setImageBase64(HutoolAesUtil.decrypt(entity.getImageBase64(),getPropertyKey()));
|
|
|
// 这里开始调用 python 接口
|
|
// 这里开始调用 python 接口
|
|
|
ImageConfig imageConfig = getImagePythonConfig();
|
|
ImageConfig imageConfig = getImagePythonConfig();
|
|
|
- return BaseResultDto.success(Constants.SUCCESS, HutoolAesUtil.encrypt(JSON.toJSONString(idCardOcr(entity.getImageBase64(),imageConfig.getOcrRequestUrl())),getPropertyKey()));
|
|
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
|
|
|
|
+ return BaseResultDto.success(Constants.SUCCESS, HutoolAesUtil.encrypt(idCardOcr(entity.getImageBase64(),imageConfig.getOcrRequestUrl()),getPropertyKey()));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -93,7 +90,7 @@ public class OcrServiceImpl implements OcrService {
|
|
|
* @param base64Image 图片 base64 字符串(不带前缀 data:image/png;base64,)
|
|
* @param base64Image 图片 base64 字符串(不带前缀 data:image/png;base64,)
|
|
|
* @return IdCardData 识别后的身份证实体
|
|
* @return IdCardData 识别后的身份证实体
|
|
|
*/
|
|
*/
|
|
|
- public static IdCardData idCardOcr(String base64Image,String url) {
|
|
|
|
|
|
|
+ public static String idCardOcr(String base64Image,String url) {
|
|
|
try {
|
|
try {
|
|
|
// 1. 接口地址
|
|
// 1. 接口地址
|
|
|
// String url = "http://103.214.175.29:5000/ocr/idcard/base64";
|
|
// String url = "http://103.214.175.29:5000/ocr/idcard/base64";
|
|
@@ -111,12 +108,12 @@ public class OcrServiceImpl implements OcrService {
|
|
|
String json = response.body();
|
|
String json = response.body();
|
|
|
|
|
|
|
|
// 5. 解析结果
|
|
// 5. 解析结果
|
|
|
- OcrResult result = JSON.parseObject(json, OcrResult.class);
|
|
|
|
|
|
|
+ JSONObject result = JSON.parseObject(json, JSONObject.class);
|
|
|
|
|
|
|
|
- if (result.getCode() == 0) {
|
|
|
|
|
- return result.getData();
|
|
|
|
|
|
|
+ if (result.getIntValue("code") == 0) {
|
|
|
|
|
+ return result.getJSONObject("data").getString("full_text");
|
|
|
} else {
|
|
} else {
|
|
|
- System.err.println("OCR 识别失败:" + result.getMsg());
|
|
|
|
|
|
|
+ System.err.println("OCR 识别失败:" + result.getString("msg"));
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|