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

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");
    }

}

相关文章:

  • 企业网站源码HTML成品网站与网页代码模板指南
  • SpringBoot报错解决方案
  • win11+ubuntu双系统安装
  • selenium实现自动登录项目(5)
  • 自定义协议的网络计算器项目
  • 北斗导航 | 改进奇偶矢量法的接收机自主完好性监测算法原理,公式,应用,RAIM算法研究综述,matlab代码
  • element-plus中,Tour 漫游式引导组件的使用
  • 小程序中过滤苹果设备中的表情(即 emoji)
  • UniApp和微信小程序中v-switch夜间模式动画开关
  • Flutter环境配置
  • seatunnel配置mysql2hive
  • FALL靶场通关攻略
  • 小样本学习(概念区分)VS对比学习VS元学习的联系与区别
  • CCF编程能力等级认证GESP—C++7级—20250322
  • PHP 应用SQL 注入符号拼接请求方法HTTP 头JSON编码类
  • 【面试八股】:常见的锁策略
  • Rk3568驱动开发_设备树点亮LED_10
  • 大语言模型引擎选型:vLLM、SGLang 、 Ollama
  • 软考笔记6——结构化开发方法
  • 基于HTML5的3D魔方项目开发实践
  • 阿里巴巴做企业网站/网络营销专业可以干什么工作
  • 湖南做网站的公司排名/百度网盘网页登录入口
  • java 视频网站开发/域名备案查询系统
  • 朝阳区社会建设网站/win优化大师怎么样
  • 做搜索网站能发财吗/网络营销策划总结
  • 北京网站建设比较好的公司/长沙seo全网营销