From 68ee18438e99995d2d108cccb36e75f77ea96d76 Mon Sep 17 00:00:00 2001
From: luodangjia <luodangjia>
Date: 星期二, 21 一月 2025 17:36:08 +0800
Subject: [PATCH] 1

---
 ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/orc/OcrUtils.java |   22 ++++------------------
 1 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/orc/OcrUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/orc/OcrUtils.java
index 6e0d145..68b0f44 100644
--- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/orc/OcrUtils.java
+++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/orc/OcrUtils.java
@@ -38,32 +38,18 @@
     /**
      * 证件识别
      */
-    public static JSONObject idCard(InputStream bodyStream) throws Exception {
+    public static String idCard(InputStream bodyStream,String type) throws Exception {
         com.aliyun.ocr_api20210707.Client client = createClient();
         // 需要安装额外的依赖库,直接点击下载完整工程即可看到所有依赖。
         RecognizeAllTextRequest recognizeAllTextRequest = new RecognizeAllTextRequest()
                 .setBody(bodyStream)
-                .setType("IdCard")
+                .setType(type)
                 .setOutputFigure(true);
         RuntimeOptions runtime = new RuntimeOptions();
         try {
             // 复制代码运行请自行打印 API 的返回值
             RecognizeAllTextResponse recognizeAllTextResponse = client.recognizeAllTextWithOptions(recognizeAllTextRequest, runtime);
-            String jsonString = Common.toJSONString(TeaModel.buildMap(recognizeAllTextResponse));
-            JSONObject jsonObject = JSONObject.parseObject(jsonString);
-            Integer statusCode = jsonObject.getInteger("statusCode");
-            if (statusCode != 200) {
-                throw new RuntimeException("识别失败");
-            }
-            JSONObject body = jsonObject.getJSONObject("body");
-            JSONObject data = body.getJSONObject("Data");
-            JSONArray subImages = body.getJSONArray("SubImages");
-            if (subImages != null && !subImages.isEmpty()){
-                JSONObject subImage = subImages.getJSONObject(0);
-                JSONObject kvInfo = subImage.getJSONObject("KvInfo");
-                return kvInfo.getJSONObject("Data");
-            }
-            return null;
+            return Common.toJSONString(TeaModel.buildMap(recognizeAllTextResponse));
         } catch (TeaException error) {
             // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
             // 错误 message
@@ -86,7 +72,7 @@
 
     public static void main(String[] args) {
         try {
-            InputStream inputStream = UrlDownloader.downloadAsStream("https://ai.bdstatic.com/file/3C8C5B451BB4445697730217EC8648E3");
+            InputStream inputStream = UrlDownloader.downloadAsStream("http://192.168.110.188:9300/statics/2025/01/21/862dab34c5f83ce2635d219c467ac9f6_20250121170536A004.jpg");
             idCard(inputStream);
         } catch (Exception e) {
             throw new RuntimeException(e);

--
Gitblit v1.7.1