当前位置: 首页 > 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.lryc.cn/news/612174.html

相关文章:

  • Spring_事务
  • docker相关操作记录
  • C语言控制语句练习题1
  • 记一次ORACLE ORA-00600 [19004] 错误的分析与解决方法
  • ABAP QRFC 队列函数的使用
  • 院校机试刷题第二十一天|回顾代码随想录第十六天、
  • gorm:初识gorm
  • 线性代数中矩阵的基本运算运算
  • 二、Istio流量治理(一)
  • Kali Linux虚拟机安装和中文配置详细教程(2025版)
  • Aop中的相关术语
  • FluentUI的介绍与使用案列
  • K8S的POD数量限制
  • 《Transformer黑魔法Mask与Softmax、Attention的关系:一个-∞符号如何让AI学会“选择性失明“》
  • sqli-labs靶场less40-less45
  • 【python中级】关于Flask服务在同一系统里如何只被运行一次
  • 大型音频语言模型论文总结
  • 基于CentOS-7.6部署k8s-1.24.0,containerd作为CRI,nerdctl作为容器管理CLI
  • 高阶组件实现Button权限
  • 对 .NET线程 异常退出引发程序崩溃的反思
  • PowerShell部署Windows爬虫自动化方案
  • 玩转 InfluxDB 3:用 HTTP API 快速创建高效数据表
  • 【Linux】调试器gdb/cgdb的使用
  • 信号处理:信号产生
  • 张艺兴续约担任传音手机全球品牌代言人 携手共启创新征程
  • 企业级DDoS防护实战案例
  • 数字取证和网络安全:了解两者的交叉点和重要性
  • 什么是 Kafka 中的消息?它由哪些部分组成
  • 《设计模式之禅》笔记摘录 - 13.迭代器模式
  • JP3-4-MyClub后台前端(二)