实名认证 —— 腾讯云驾驶证识别接口

官方地址:

API Explorer - 云 API - 控制台https://console.cloud.tencent.com/api/explorer?Product=ocr&Version=2018-11-19&Action=DriverLicenseOCR前置操作与下面博客前置操作一致:实名认证 ------ 腾讯云身份证认证接口-CSDN博客

首先编写Controller:

java 复制代码
@Operation(summary = "驾驶证识别")
@PostMapping("/driverLicenseOcr")
public Result<DriverLicenseOcrVo> driverLicenseOcr(@RequestPart("file") MultipartFile file) {
    return Result.ok(ocrService.driverLicenseOcr(file));
}

随后编写Service:

步骤解析:实名认证 ------ 腾讯云身份证认证接口-CSDN博客几乎一致

java 复制代码
    ////驾驶证识别
    @Override
    public DriverLicenseOcrVo driverLicenseOcr(MultipartFile file) {
        try{
            //图片转换base64格式字符串
            byte[] base64 = Base64.encodeBase64(file.getBytes());
            String fileBase64 = new String(base64);
            
            // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
            Credential cred = new Credential(tencentCloudProperties.getSecretId(),
                    tencentCloudProperties.getSecretKey());
            // 实例化一个http选项,可选的,没有特殊需求可以跳过
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("ocr.tencentcloudapi.com");
            // 实例化一个client选项,可选的,没有特殊需求可以跳过
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            // 实例化要请求产品的client对象,clientProfile是可选的
            OcrClient client = new OcrClient(cred, tencentCloudProperties.getRegion(),
                                                clientProfile);
            // 实例化一个请求对象,每个接口都会对应一个request对象
            DriverLicenseOCRRequest req = new DriverLicenseOCRRequest();
            req.setImageBase64(fileBase64);
            
            // 返回的resp是一个DriverLicenseOCRResponse的实例,与请求对象对应
            DriverLicenseOCRResponse resp = client.DriverLicenseOCR(req);

            //封装到vo对象里面
            DriverLicenseOcrVo driverLicenseOcrVo = new DriverLicenseOcrVo();
            if (StringUtils.hasText(resp.getName())) {
                //驾驶证正面
                //驾驶证名称要与身份证名称一致
                driverLicenseOcrVo.setName(resp.getName());
                driverLicenseOcrVo.setDriverLicenseClazz(resp.getClass_());
                driverLicenseOcrVo.setDriverLicenseNo(resp.getCardCode());
                driverLicenseOcrVo.setDriverLicenseIssueDate(DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(resp.getDateOfFirstIssue()).toDate());
                driverLicenseOcrVo.setDriverLicenseExpire(DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(resp.getEndDate()).toDate());

                //上传驾驶证反面图片到腾讯云cos
                CosUploadVo cosUploadVo = cosService.upload(file, "driverLicense");
                driverLicenseOcrVo.setDriverLicenseFrontUrl(cosUploadVo.getUrl());
                driverLicenseOcrVo.setDriverLicenseFrontShowUrl(cosUploadVo.getShowUrl());
            } else {
                //驾驶证反面
                //上传驾驶证反面图片到腾讯云cos
                CosUploadVo cosUploadVo =  cosService.upload(file, "driverLicense");
                driverLicenseOcrVo.setDriverLicenseBackUrl(cosUploadVo.getUrl());
                driverLicenseOcrVo.setDriverLicenseBackShowUrl(cosUploadVo.getShowUrl());
            }

            return driverLicenseOcrVo;
        } catch (Exception e) {
            e.printStackTrace();
            throw new GuiguException(ResultCodeEnum.DATA_ERROR);
        }
    }

随后编写feign:

java 复制代码
/**
 * 驾驶证识别
 * @param file
 * @return
 */
@PostMapping(value = "/ocr/driverLicenseOcr", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
Result<DriverLicenseOcrVo> driverLicenseOcr(@RequestPart("file") MultipartFile file);
相关推荐
Johny_Zhao2 小时前
达梦数据库高可用集群部署方案
linux·mysql·网络安全·docker·信息安全·kubernetes·云计算·shell·containerd·达梦数据库·yum源·系统运维·centos8
云道轩2 小时前
阿里云和华为云Rocky LINUX 9.X镜像就绪及低端可用英伟达GPU
阿里云·华为云·云计算·gpu·rocky linux
wb1895 小时前
CICD的持续集成与持续交付和Zabbix
运维·笔记·ci/cd·云计算·zabbix
HR Zhou6 小时前
DAG与云计算任务调度优化
算法·云计算·任务调度·调度
Britz_Kevin6 小时前
从零开始的云计算生活——第五十七天,蓄势待发,DevOps模块
云计算·生活·devops·#jenkins
fyihdg16 小时前
aws上创建jenkins
云计算·aws
TG_yilongcloud19 小时前
亚马逊云代理商:如何选择适合的AWS EC2实例类型?
服务器·云计算·aws·实例类型
Akamai中国19 小时前
应用平台更新:可定制目录、基于Git的密钥管理与K8s项目自动化管理
人工智能·云计算·云服务·云存储
重启的码农20 小时前
云游戏技术之高速截屏和GPU硬编码 (1) 捕获-预处理-编码流水线
c++·云计算·音视频开发
重启的码农20 小时前
云游戏技术之高速截屏和GPU硬编码 (2) 应用程序主控
c++·云计算·音视频开发