From 78c1f87d61d1411356a422ab841afde67342d228 Mon Sep 17 00:00:00 2001 From: wangwh <2397901735@qq.com> Date: Wed, 04 Sep 2024 20:52:15 +0800 Subject: [PATCH] 1、事项登记、详情查询接口 2、ocr识别文字接口 3、办理流转-查询下属人员、选择经办人、获取工作人员信息、添加办理反馈、获取办理反馈信息、修改办理反馈信息 4、督办-添加督办、回复督办、查询督办列表 5、查询评价 --- dyh-service/dyh-sys/src/main/java/cn/huge/module/utils/BaiduOcrUtils.java | 38 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 38 insertions(+), 0 deletions(-) diff --git a/dyh-service/dyh-sys/src/main/java/cn/huge/module/utils/BaiduOcrUtils.java b/dyh-service/dyh-sys/src/main/java/cn/huge/module/utils/BaiduOcrUtils.java index 93769d6..00d8834 100644 --- a/dyh-service/dyh-sys/src/main/java/cn/huge/module/utils/BaiduOcrUtils.java +++ b/dyh-service/dyh-sys/src/main/java/cn/huge/module/utils/BaiduOcrUtils.java @@ -6,9 +6,14 @@ import cn.huge.module.sys.dto.IdcardOcrResultDTO; import com.baidu.aip.ocr.AipOcr; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.json.JSONArray; import org.json.JSONObject; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * @title: 百度云OCR工具类 @@ -28,6 +33,10 @@ public static final String APP_ID = "27535980"; public static final String API_KEY = "6U6tSA75gKf4UMXvHgDpzOC9"; public static final String SECRET_KEY = "BBjjCDhy2sAVO0jfiaGn8OWIGE470lWU"; + // 个人账号-18607214221 + public static final String APP_ID_TEXT = "113806304"; + public static final String API_KEY_TEXT = "ajKtDuIs8xr0XvjbUZLPGi8C"; + public static final String SECRET_KEY_TEXT = "vgMrG5BJbUfGwKLda1yPWovTQWuRFWDB"; public static void main(String[] args) { @@ -81,6 +90,35 @@ } } + + public static Map<String, Object> ocrText(byte[] images) { + AipOcr client = new AipOcr(APP_ID_TEXT, API_KEY_TEXT, SECRET_KEY_TEXT); + // 传入可选参数调用接口 + HashMap<String, String> options = new HashMap<String, String>(); + options.put("language_type", "CHN_ENG"); + options.put("detect_direction", "true"); + options.put("detect_language", "true"); + options.put("probability", "true"); + + Map<String, Object> map = new HashMap<String, Object>(); + // 参数为本地图片二进制数组 + JSONObject res = client.basicAccurateGeneral(images, options); + map.put("wordsResultNum", res.getInt("words_result_num")); + map.put("direction", res.getInt("direction")); + + List<String> wordsResultList = new ArrayList<>(); + JSONArray jsonArray = res.getJSONArray("words_result"); + for(int i = 0; i < jsonArray.length(); i++){ + JSONObject wordResult = jsonArray.getJSONObject(i); + String words = wordResult.getString("words"); + if(StringUtils.isNotBlank(words)){ + wordsResultList.add(words); + } + } + map.put("wordsResult", wordsResultList); + return map; + } + } /** * -------------------_ooOoo_------------------- -- Gitblit v1.8.0