ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/UrlDownloader.java
@@ -2,8 +2,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; public class UrlDownloader { @@ -29,9 +31,17 @@ return connection.getInputStream(); } public static void main(String[] args) { String urlString = "https://example.com/file.txt"; // 替换为你要下载的URL public static void main(String[] args) throws UnsupportedEncodingException { String urlString = "http://192.168.110.188:9300/statics/2025/01/21/身份证人像面_20250121171827A014.png"; // 替换为你要下载的URL //将路径中的中文进行编码 //String urlString = "http://192.168.110.188:9300/statics/2025/01/21/%E8%BA%AB%E4%BB%BD%E8%AF%81%E4%BA%BA%E5%83%8F%E9%9D%A2_20250121171827A014.png"; // 找到最后一个斜杠的位置 int lastSlashIndex = urlString.lastIndexOf("/"); // 从斜杠后提取文件名 String baseUrl = urlString.substring(0, lastSlashIndex); String fileName = urlString.substring(lastSlashIndex + 1); String encode = URLEncoder.encode(fileName, "UTF-8"); urlString = baseUrl + "/" + encode; try (InputStream inputStream = downloadAsStream(urlString)) { // 这里你可以处理输入流,例如将其写入文件或进行其他操作 byte[] buffer = new byte[1024]; ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/orc/OcrUtils.java
@@ -11,7 +11,6 @@ import com.ruoyi.common.core.utils.UrlDownloader; import java.io.InputStream; import java.util.Map; public class OcrUtils { @@ -57,7 +56,7 @@ } JSONObject body = jsonObject.getJSONObject("body"); JSONObject data = body.getJSONObject("Data"); JSONArray subImages = body.getJSONArray("SubImages"); JSONArray subImages = data.getJSONArray("SubImages"); if (subImages != null && !subImages.isEmpty()){ JSONObject subImage = subImages.getJSONObject(0); JSONObject kvInfo = subImage.getJSONObject("KvInfo"); ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CommonController.java
@@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RestController; import java.io.InputStream; import java.net.URLEncoder; @RestController @RequestMapping("/common") @@ -27,6 +28,13 @@ public R<IdCard> idCard(@Parameter(name = "url", description = "图片地址") String url) { InputStream inputStream; try { // 找到最后一个斜杠的位置 int lastSlashIndex = url.lastIndexOf("/"); // 从斜杠后提取文件名 String baseUrl = url.substring(0, lastSlashIndex); String fileName = url.substring(lastSlashIndex + 1); String encode = URLEncoder.encode(fileName, "UTF-8"); url = baseUrl + "/" + encode; inputStream = UrlDownloader.downloadAsStream(url); JSONObject jsonObject = OcrUtils.idCard(inputStream); IdCard idCard = JSONObject.parseObject(jsonObject.toJSONString(), IdCard.class);