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

哪里有免费的网站源码wordpress 注册邮箱验证失败

哪里有免费的网站源码,wordpress 注册邮箱验证失败,wordpress推荐配置,4p 4c 4r营销理论区别一、技术选型 OCR服务&#xff1a;推荐使用百度AI 二、实现 1.注册一个服务 百度智能云控制台https://console.bce.baidu.com/ai-engine/ocr/overview/index?_1742309417611 填写完之后可以获取到app-id、apiKey、SecretKey这三个后面文件配置会用到 2、导入依赖 <!-- …

一、技术选型

OCR服务:推荐使用百度AI

二、实现

1.注册一个服务

百度智能云控制台https://console.bce.baidu.com/ai-engine/ocr/overview/index?_=1742309417611

填写完之后可以获取到app-idapiKeySecretKey这三个后面文件配置会用到

2、导入依赖

        <!-- Spring Boot Web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>2.6.13</version></dependency><!-- 百度AI SDK(示例) --><dependency><groupId>com.baidu.aip</groupId><artifactId>java-sdk</artifactId><version>4.16.13</version></dependency><!--json依赖--><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>2.0.40</version></dependency>

3、配置文件

spring:servlet:multipart:max-request-size: 10MB # 文件上传最大值max-file-size: 10MB # 单个文件最大值
baidu:ai:app-id: ***** 换成自己的secret-key: ***** 换成自己的api-key: ***** 换成自己的

4、编写OCR工具类

import com.baidu.aip.ocr.AipOcr;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;import java.util.HashMap;
import java.util.Map;@Component
public class OcrService {@Value("${baidu.ai.app-id}")private String appId;@Value("${baidu.ai.api-key}")private String apiKey;@Value("${baidu.ai.secret-key}")private String secretKey;public Map<String, String> recognizeIdCard(MultipartFile file, boolean isFront) throws Exception {AipOcr client = new AipOcr(appId, apiKey, secretKey);// 读取图片字节byte[] imgData = file.getBytes();// 设置身份证正反面String idCardSide = isFront ? "front" : "back";// 设置其他识别选项(如果有)HashMap<String, String> options = new HashMap<String, String>();// 可以在这里添加其他选项,例如:// options.put("detect_direction", "true"); // 检测图像朝向// 调用身份证识别接口JSONObject res = client.idcard(imgData, idCardSide, options);// 检查返回结果if (res == null || !res.has("words_result")) {throw new Exception("OCR 识别失败: 返回结果为空或不包含 words_result");}// 解析结果Map<String, String> result = new HashMap<String, String>();JSONObject words = res.getJSONObject("words_result");// 根据正反面提取不同字段if (isFront) {result.put("姓名", words.optString("姓名", ""));result.put("性别", words.optString("性别", ""));result.put("民族", words.optString("民族", ""));result.put("出生日期", words.optString("出生年月日", ""));result.put("住址", words.optString("住址", ""));result.put("身份证号", words.optString("公民身份号码", ""));} else {result.put("签发机关", words.optString("签发机关", ""));result.put("有效期限", words.optString("失效日期", ""));}return result;}
}

5、文件上传接口

import com.alibaba.fastjson.JSON;
import com.cykj.service.OcrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;import java.util.HashMap;
import java.util.Map;@RestController
@RequestMapping("/api/idcard")
/*** 身份证识别控制器* 提供身份证图片上传和识别功能*/
public class IdCardController {@Autowiredprivate OcrService ocrService;/*** 上传身份证图片并进行识别* * @param frontFile 身份证正面图片* @param backFile 身份证反面图片* @return 身份证信息的Map,包括正面和反面的识别结果*/@PostMapping("/upload")public ResponseEntity<?> uploadIdCard(@RequestParam("frontFile") MultipartFile frontFile,@RequestParam("backFile") MultipartFile backFile) {System.out.println(frontFile);System.out.println(backFile);try {// 识别正面信息Map<String, String> frontInfo = ocrService.recognizeIdCard(frontFile, true);System.out.println("Front Info: " + frontInfo);// 识别反面信息Map<String, String> backInfo = ocrService.recognizeIdCard(backFile, false);System.out.println("Back Info: " + backInfo);// 合并结果Map<String, String> combined = new HashMap<String, String>();combined.putAll(frontInfo);combined.putAll(backInfo);// 身份证校验(示例)String idNumberJson = combined.get("身份证号");//解析获取身份证号com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(idNumberJson);String idNumber = jsonObject.getString("words");if (!validateIdCard(idNumber)) {return ResponseEntity.badRequest().body("身份证号校验失败");}return ResponseEntity.ok(combined);} catch (Exception e) {e.printStackTrace();return ResponseEntity.status(500).body("识别失败: " + e.getMessage());}}/*** 简单身份证号校验(正则表达式)* * @param idNumber 身份证号码字符串* @return 校验通过返回true,否则返回false*/private boolean validateIdCard(String idNumber) {String regex = "^[1-9]\\d{5}(19|20)\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[\\dXx]$";return idNumber != null && idNumber.matches(regex);}
}

三、前端写个测试页面

这边的action路径要改成自己的路径

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<form action="http://localhost:8086/api/idcard/upload" method="post" enctype="multipart/form-data"><input type="file" name="frontFile" accept="image/*" required><input type="file" name="backFile" accept="image/*" required><button type="submit">上传并识别</button>
</form>
</body>
</html>

第一张为身份证正面(人)

第二张上传为身份证反面(国徽那面)

测试成功在页面和控制台都可以看见自己提取出来的信息就成功啦!

http://www.dtcms.com/wzjs/582628.html

相关文章:

  • 微网站开发工具有哪些提供手机自适应网站制作
  • 做网站培训做企业网站需要准备什么材料
  • 湖南住房与城乡建设厅网站创业投资公司网站建设
  • 如何做推广网站做互助盘网站
  • 企业网站icp是什么WordPress十万数据可以
  • 个人网站 前置审批谷歌浏览器官网下载安装
  • 湖南城市建设技术学院官方网站ssh框架做的网站问题
  • 枣庄建网站的公司网站 架构设计
  • 东莞php网站建设wordpress导入表单
  • 2023传奇手游排行榜网站建设优化文档
  • 做网站把自己做死学校网站建设开发方案书
  • 网站开发架构文档网站备案 自己的服务器
  • 怎么查网站的icp备案wordpress构建android
  • 人才网站建设cms淮北论坛最新招聘信息网
  • 建设部网站证件查询个人开店的电商平台
  • c 网站开发入门视频wordpress 过滤词
  • 国际酒店网站建设不好招聘网站开发视频
  • 网站域名每年费用wordpress 固定链接 id
  • 5 网站建设进度表传统企业网站建设制作
  • seo优化网站源码猎头招聘网官网
  • 进入网站后台管理系统wordpress 自带主题修改
  • 网站备案太久了内网wordpress响应慢
  • 嘉兴网站建设哪家做得好建筑工程网站建设方案
  • 昆明做网站优化大连鑫农建设集团网站
  • wordpress文章中的相关文章代码在网站优化顺义案例
  • 做网站为什么需要购买域名网站开发维护招聘
  • 做零售外贸网站有哪些聚搜济南网站建设公司
  • 用别人服务器做网站wordpress 1核2g的服务器卡
  • 建网站要多少钱维护制作投票网站
  • 外贸建设网站公司哪家好学做app