From 6ae0901878f342a9c1025c8edc302bdf03f58a6d Mon Sep 17 00:00:00 2001
From: xusd <hugeinfo123>
Date: Wed, 18 Sep 2024 17:37:00 +0800
Subject: [PATCH] 新增获取企业信息接口
---
dyh-service/dyh-sys/src/main/java/cn/huge/module/utils/BaiduOcrUtils.java | 42 ++++++++++++++++++++++++++++++++++++++++--
1 files changed, 40 insertions(+), 2 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 ddf10fe..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
@@ -1,14 +1,19 @@
package cn.huge.module.utils;
-import cn.huge.module.constant.CaseBaseConstsEnum;
-import cn.huge.module.constant.NotionBaseConstsEnum;
+import cn.huge.module.mediate.constant.CaseBaseConstsEnum;
+import cn.huge.module.mediate.constant.NotionBaseConstsEnum;
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