1
luodangjia
2025-01-21 f981c1f30461ef9a40a39338aa77e511ffc24d1f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.ruoyi.system.controller;
 
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.UrlDownloader;
import com.ruoyi.common.core.utils.orc.OcrUtils;
import com.ruoyi.system.api.model.IdCard;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.io.InputStream;
 
@RestController
@RequestMapping("/common")
public class CommonController {
 
    /**
     * ocr提取身份证信息
     */
    @GetMapping("/idCard")
    public R<IdCard> idCard(@Parameter(name = "url", description = "图片地址") String url) {
        InputStream inputStream;
        try {
            inputStream = UrlDownloader.downloadAsStream(url);
            JSONObject jsonObject = OcrUtils.idCard(inputStream);
            IdCard idCard = JSONObject.parseObject(jsonObject.toJSONString(), IdCard.class);
            return R.ok(idCard);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}