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

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

官方地址:

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

首先编写Controller:

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

随后编写Service:

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

    ////驾驶证识别@Overridepublic 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());//上传驾驶证反面图片到腾讯云cosCosUploadVo cosUploadVo = cosService.upload(file, "driverLicense");driverLicenseOcrVo.setDriverLicenseFrontUrl(cosUploadVo.getUrl());driverLicenseOcrVo.setDriverLicenseFrontShowUrl(cosUploadVo.getShowUrl());} else {//驾驶证反面//上传驾驶证反面图片到腾讯云cosCosUploadVo 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:

/*** 驾驶证识别* @param file* @return*/
@PostMapping(value = "/ocr/driverLicenseOcr", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
Result<DriverLicenseOcrVo> driverLicenseOcr(@RequestPart("file") MultipartFile file);

http://www.dtcms.com/a/317767.html

相关文章:

  • 云市场周报 (2025.08.06):腾讯云开学季、阿里云OSS降价及市场格局分析
  • Spring文件泄露与修复方案总结
  • C语言零基础第12讲:各类指针变量介绍与转移表应用
  • 基于Github Pages搭建个人博客站点:hexo环境搭建、本地预览与发布
  • 11、系统配置System文件夹
  • Docker 数据存储路径(解决默认docker路径位置磁盘空间不足的情况)
  • React(二):jsx事件绑定、条件渲染、列表渲染、jsx的本质、购物车案例
  • 玳瑁的嵌入式日记D13-0806(C语言)
  • Spring Boot部门管理系统:查询、删除、新增实战
  • IntelliJ IDEA 2025.1.4.1 中文版
  • Nacos配置中心和数据隔离在idea中的实现
  • NWinfo(硬件信息检测工具)v1.4.20绿色免费版,U盘随走随检,结果即刻导出
  • 借助Aspose.OCR ,使用 Python 提取JPG图像文本、将JPG图像转换为Word
  • 本地服务器端部署基于大模型的通用OCR项目——dots.ocr
  • 达梦数据库数据守护集群启动与关闭标准流程
  • docker安装FFmpeg
  • Pytest项目_day06(requests中Session的用法)
  • 引领GameFi 2.0新范式:D.Plan携手顶级财经媒体启动“龙珠创意秀”
  • SpringMVC基础
  • 关于 idea 里 properties 文件的中文乱码问题
  • 「iOS」————单例与代理
  • 使用PHP与Apache实现服务器端文件管理
  • 19day-人工智能-机器学习-分类算法-决策树
  • docker 部署Bedrock Connector
  • 希尔排序:高效插入排序的进阶之道
  • 从零开始部署Qwen3-8b大模型到本地
  • Centos 安装 redis
  • 17_INIT_WORKLinux内核模块
  • prefetch 下载 GEO 数据注意事项
  • 设计模式—桥梁模式(Bridge)