网站域名免费注册商城网站设计公司排名

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

网站域名免费注册,商城网站设计公司排名,鑫牛元网站建设,外包公司是正规公司吗使用场景: 远程身份认证 自动识别录入用户身份/企业资质信息#xff0c;应用于金融、政务、保险、电商、直播等场景#xff0c;对用户、商家、主播进行实名身份认证#xff0c;有效降低用户输入成本#xff0c;控制业务风险 文档电子化 识别提取各类办公文档、合同文件、企…使用场景: 远程身份认证 自动识别录入用户身份/企业资质信息应用于金融、政务、保险、电商、直播等场景对用户、商家、主播进行实名身份认证有效降低用户输入成本控制业务风险 文档电子化 识别提取各类办公文档、合同文件、企业年报、法律卷宗等纸质文档中的文字信息并基于位置信息进行比对、结构化处理提高信息录入、存档、检索效率 交通出行 实现卡证、车辆信息的快速录入提升比对效率适用于司机身份核验、车主信息管理、智慧停车、卡口通行、车辆维修保养等场景 快递物流 实现快递分发全链路智能化升级满足身份核验、智能寄件下单运输车辆管理、快递单识别等不同场景需求。同时助力大宗货运物流过磅提效 财税报销 对10 余种常见税务发票、差旅票据自动分类、识别、录入可快速对接国税平台进行增值税发票验真适用于企业税务核算及内部报销场景释放企业人力简化业务流程 医疗保险 识别患者身份信息/各类医疗票据/医疗仪器盘数据提升信息录入效率助力提高保险理赔整体时效并辅助病患管理、健康监测、处方单电子化等 识别实战 身份证验证 使用百度智能云的OCR身份证识别 鉴权认证机制 获取到access_token 通过API Key和Secret Key获取的access_token,参考“Access Token获取” 鉴权的主要目的是获取Access_token。Access_token是用户的访问令牌承载了用户的身份、权限等信息。 1.获取AK/SK 创建应用 2.添加到nacos配置中 3.在业务层使用Value获取 4.获取Access_token 使用下面编写好的工具类BaiduOcrApi 。 5.controller层 Operation(summary 识别身份证)Parameters({Parameter(name type, description back国徽面front照片面, required true, in ParameterIn.QUERY)})PostMapping(/idCard)public SimpleResponseOCRIdCardResponse recognizeIdCardBack(RequestPart(name file) MultipartFile file,RequestParam(type) String type) {return SimpleResponse.success(ocrService.recognizeIdCard(file, type));} 6.service层  Value(\({ocr.apiKey})private String apiKey;Value(\){ocr.secretKey})private String secretKey;Resourceprivate ObjectMapper objectMapper;Resourceprivate RedissonClientTemplate redissonClientTemplate;/*** 识别身份证** param file 文件* param type 类型* return {link OCRIdCardResponse}/OverrideSneakyThrowspublic OCRIdCardResponse recognizeIdCard(MultipartFile file, String type) {if (file null || file.isEmpty()) {log.info(———- 文件内容为空 ———-);throw new AppRuntimeException(ResponseCode.OPERATION_FAILED);}InputStream inputStream file.getInputStream();// 获取access_tokenString accessToken redissonClientTemplate.get(RedisKeyConstants.OCR_ACCESS_TOKEN);if (StringUtils.isEmpty(accessToken)) {accessToken BaiduOcrApi.getAccessToken(apiKey, secretKey);// 保存accessToken到redis有效时间为29天redissonClientTemplate.setex(RedisKeyConstants.OCR_ACCESS_TOKEN, accessToken, 29L, TimeUnit.DAYS);}// ocr识别String result BaiduOcrApi.recognizeIDCardResult(inputStream, accessToken, type);OCRResult orcIdCardResult objectMapper.readValue(result, OCRResult.class);if (orcIdCardResult null || !normal.equals(orcIdCardResult.getImage_status()) || orcIdCardResult.getWords_result_num() 0) {throw new AppRuntimeException(ResponseCode.OCR_API_ERROR);}OCRIdCardResponse orcIdCardResponse new OCRIdCardResponse();MapString, OCRResult.wordsModel wordsResult orcIdCardResult.getWords_result();// 获取结果if (back.equals(type)) {// 身份证国徽面OCRResult.wordsModel wordsModel wordsResult.get(OcrConstant.EXPIRATION_DATE);if (wordsModel null) {throw new AppRuntimeException(ResponseCode.OCR_API_ERROR);}orcIdCardResponse.setExpirationDate(wordsModel.getWords());} else {// 身份证头像面OCRResult.wordsModel wordsModel1 wordsResult.get(OcrConstant.NAME);if (wordsModel1 null) {throw new AppRuntimeException(ResponseCode.OCR_API_ERROR);}orcIdCardResponse.setName(wordsModel1.getWords());OCRResult.wordsModel wordsModel2 wordsResult.get(OcrConstant.ID_NUMBER);if (wordsModel2 null) {throw new AppRuntimeException(ResponseCode.OCR_API_ERROR);}orcIdCardResponse.setIdNumber(wordsModel2.getWords());}// TODO 保存照片到OSSreturn orcIdCardResponse; 6.百度ocr请求工具类 import cn.hutool.json.JSONObject; import okhttp3.;import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.Base64;/*** ClassName: BaiduOcrApi* Author: wujiada* Date: 2024/12/16 10:21* Description: 使用API Key和Secret Key获取Access Token,获取识别结果/ public class BaiduOcrApi {private static final OkHttpClient HTTP_CLIENT new OkHttpClient().newBuilder().build();/** 从用户的AKSK生成鉴权签名Access Token** return 鉴权签名Access Token* throws IOException IO异常/public static String getAccessToken(String apiKey, String secretKey) throws Exception {MediaType mediaType MediaType.parse(application/x-www-form-urlencoded);RequestBody body RequestBody.create(mediaType, grant_typeclient_credentialsclient_id apiKey client_secret secretKey);Request request new Request.Builder().url(https://aip.baidubce.com/oauth/2.0/token).method(POST, body).addHeader(Content-Type, application/x-www-form-urlencoded).build();Response response HTTP_CLIENT.newCall(request).execute();assert response.body() ! null;return new JSONObject(response.body().string()).get(access_token, String.class);}/** p请求百度OCR识别身份证/p** param inputStream 文件输入流* param accessToken 访问百度云API的token* param type back国徽面front照片面* return {link String}* author wujiada* since 2024/12/16 11:35/public static String recognizeIDCardResult(InputStream inputStream, String accessToken, String type) throws Exception {// 读取图片文件并转换为Base64编码// 将输入流转换为字节数组byte[] imageBytes readInputStream(inputStream);// 使用Base64编码字节数组String base64EncodedImage Base64.getEncoder().encodeToString(imageBytes);MediaType mediaType MediaType.parse(application/x-www-form-urlencoded);// front身份证含照片的一面// back身份证带国徽的一面RequestBody body RequestBody.create(mediaType, image URLEncoder.encode(base64EncodedImage, StandardCharsets.UTF_8) id_card_side type detect_psfalsedetect_riskfalsedetect_qualityfalsedetect_photofalsedetect_cardfalsedetect_directionfalse);Request request new Request.Builder().url(https://aip.baidubce.com/rest/2.0/ocr/v1/idcard?access_token accessToken).method(POST, body).addHeader(Content-Type, application/x-www-form-urlencoded).addHeader(Accept, application/json).build();Response response HTTP_CLIENT.newCall(request).execute();assert response.body() ! null;return response.body().string();}/** p请求百度OCR识别营业执照/p** param inputStream 文件输入流* param accessToken 访问百度云API的token* return {link String}* author wujiada* since 2024/12/16 11:35/public static String recognizeBusinessLicenseResult(InputStream inputStream, String accessToken) throws Exception {// 读取图片文件并转换为Base64编码// 将输入流转换为字节数组byte[] imageBytes readInputStream(inputStream);// 使用Base64编码字节数组String base64EncodedImage Base64.getEncoder().encodeToString(imageBytes);MediaType mediaType MediaType.parse(application/x-www-form-urlencoded);RequestBody body RequestBody.create(mediaType, image URLEncoder.encode(base64EncodedImage, StandardCharsets.UTF_8));Request request new Request.Builder().url(https://aip.baidubce.com/rest/2.0/ocr/v1/business_license?access_token accessToken).method(POST, body).addHeader(Content-Type, application/x-www-form-urlencoded).addHeader(Accept, application/json).build();Response response HTTP_CLIENT.newCall(request).execute();assert response.body() ! null;return response.body().string();}/** p从输入流中读取所有字节并将它们存储在ByteArrayOutputStream/p** param inputStream 文件输入流* return {link byte[]}* author wujiada* since 2024/12/16 11:37/private static byte[] readInputStream(InputStream inputStream) throws IOException {// 使用ByteArrayOutputStream收集字节ByteArrayOutputStream byteArrayOutputStream new ByteArrayOutputStream();byte[] buffer new byte[1024];int bytesRead;// 从输入流中读取数据直到EOFwhile ((bytesRead inputStream.read(buffer)) ! -1) {byteArrayOutputStream.write(buffer, 0, bytesRead);}// 将收集的字节转换为字节数组return byteArrayOutputStream.toByteArray();}} 7.ocrAPI接收结果实体类 /** ClassName: OCRResult* Author: wujiada* Date: 2024/12/16 11:45* Description: 请求百度OCRAPI识别返回结果/ Data Schema(description 请求百度ORC识别API身份证返回结果) public class OCRResult implements Serializable {Schema(description 唯一的log id用于问题定位)private Long log_id;Schema(description 识别结果数表示words_result的元素个数)private Long words_result_num;Schema(description 定位和识别结果数组)private MapString, wordsModel words_result;/ normal-识别正常reversed_side-身份证正反面颠倒non_idcard-上传的图片中不包含身份证blurred-身份证模糊other_type_card-其他类型证照over_exposure-身份证关键字段反光或过曝over_dark-身份证欠曝亮度过低unknown-未知状态*/Schema(description 识别状态)private String image_status;Datapublic static class wordsModel {private Object location;private String words;} } 总结 通过以上操作就可以实现前端上传身份证文件然后发送到百度云OCR识别校验身份证。