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

官方地址:

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);
相关推荐
Clownseven2 小时前
云市场周报 (2025.08.06):腾讯云开学季、阿里云OSS降价及市场格局分析
阿里云·云计算·腾讯云
记得开心一点嘛2 小时前
实名认证 —— 腾讯云身份证认证接口
云计算·腾讯云
Johny_Zhao8 小时前
SeaTunnel的搭建部署以及测试
linux·网络·网络安全·信息安全·kubernetes·云计算·containerd·devops·seatunnel·系统运维
思绪漂移11 小时前
从博客到播客:文本转音频的全流程技术点
人工智能·音频·腾讯云·信息传播
云和数据.ChenGuang12 小时前
envFrom 是一个 列表类型字段bug
大数据·云原生·容器·kubernetes·云计算·bug
Elastic 中国社区官方博客13 小时前
升级 Elasticsearch 到新的 AWS Java SDK
java·大数据·elasticsearch·搜索引擎·云计算·全文检索·aws
AOwhisky16 小时前
云计算一阶段Ⅱ——12. SELinux 加固 Linux 安全
linux·安全·云计算
记得开心一点嘛19 小时前
实名认证 —— 腾讯云人脸识别接口
云计算·腾讯云
INFINI Labs1 天前
Easysearch 集成阿里云与 Ollama Embedding API,构建端到端的语义搜索系统
阿里云·云计算·openai·embedding·easysearch