当前位置: 首页 > article >正文

SpringBoot集成腾讯云OCR实现身份证识别

OCR身份证识别

官网地址:https://cloud.tencent.com/document/product/866/33524
在这里插入图片描述

身份信息认证(二要素核验)

官网地址:https://cloud.tencent.com/document/product/1007/33188
在这里插入图片描述

代码实现

引入依赖

<dependency>
   <groupId>com.tencentcloudapi</groupId>
    <artifactId>tencentcloud-sdk-java</artifactId>
    <version>4.0.11</version>
</dependency>

工具类

package com.qiangesoft.ocr.utils;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
import com.tencentcloudapi.faceid.v20180301.models.IdCardVerificationRequest;
import com.tencentcloudapi.faceid.v20180301.models.IdCardVerificationResponse;
import com.tencentcloudapi.ocr.v20181119.OcrClient;
import com.tencentcloudapi.ocr.v20181119.models.IDCardOCRRequest;
import com.tencentcloudapi.ocr.v20181119.models.IDCardOCRResponse;

/**
 * 腾讯云ocr识别
 *
 * @author qiangesoft
 * @date 2025-03-27
 */
public class TencentCloudOcr {

    private static final String SECRET_ID = "xxx";

    private static final String SECRET_KEY = "xxx ";

    private static final String REGION_NAME = "ap-shanghai";

    /**
     * 调用OCR识别身份证信息
     * https://cloud.tencent.com/document/product/866/33524
     *
     * @param imgUrl
     * @return
     * @throws TencentCloudSDKException
     */
    public static IDCardOCRResponse idCardOCR(String imgUrl) throws TencentCloudSDKException {
        Credential cred = new Credential(SECRET_ID, SECRET_KEY);
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint("ocr.tencentcloudapi.com");
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        OcrClient client = new OcrClient(cred, REGION_NAME, clientProfile);

        IDCardOCRRequest req = new IDCardOCRRequest();
        req.setImageUrl(imgUrl);
        req.setCardSide("FRONT");
//        req.setCardSide("BACK");
        return client.IDCardOCR(req);
    }

    /**
     * 调用身份信息核验API
     * https://cloud.tencent.com/document/product/1007/33188
     *
     * @param name
     * @param idCard
     * @return
     * @throws TencentCloudSDKException
     */
    public static IdCardVerificationResponse idCardVerification(String name, String idCard) throws TencentCloudSDKException {
        Credential cred = new Credential(SECRET_ID, SECRET_KEY);
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint("faceid.tencentcloudapi.com");
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        FaceidClient client = new FaceidClient(cred, REGION_NAME, clientProfile);

        IdCardVerificationRequest req = new IdCardVerificationRequest();
        req.setName(name);
        req.setIdCard(idCard);
        return client.IdCardVerification(req);
    }

    public static void main(String[] args) throws TencentCloudSDKException {
        IDCardOCRResponse idCardOCRResponse = idCardOCR("https://www.fsf.com");
        IdCardVerificationResponse idCardVerificationResponse = idCardVerification("xxx", "22222");
    }

}

http://www.kler.cn/a/612058.html

相关文章:

  • 【牛客网】数据分析笔试刷题
  • Charles抓HTTPS包
  • 数据结构:汉诺塔问题的递归求解和分析
  • 部分 Bash 内置命令的详解
  • 企业网站源码HTML成品网站与网页代码模板指南
  • 学习记录-Ajax-自封装axios函数
  • RAMS(区域大气建模系统)评估土地利用/覆被变化的气候与水文效应
  • 【Django】教程-3-数据库相关介绍
  • NVIDIA Megatron Core:大规模语言模型训练与部署框架详解
  • [250325] Claude AI 现已支持网络搜索功能!| ReactOS 0.4.15 发布!
  • 英语不好,可以考取Oracle OCP认证吗?
  • HO与OH差异之Navigation三
  • Android第六次面试总结(自定义 View与事件分发)
  • Unity Shader编程】之FallBack
  • CSS3:现代Web设计的魔法卷轴
  • 行为型——责任链模式
  • 本地文生图使用插件(Stable Diffusion)
  • MybatisPlus(SpringBoot版)学习第五讲:条件构造器和常用接口
  • poetry install --with aws
  • SQL语言的安全开发