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

Java实现 自主学习一套身份证识别(识别营业执照信息和语音识别接口)

20.身份证识别-沙溪行政执法系统-未验证

1.在学习身份证识别 接口 (语音识别接口,营业执照识别接口–我发现他们都是类似的)

20.1-身份证识别接口

实体层

BaseEntity-基础类

/**
 * Created by vincent.yang on 2016-01-05.
 * <p/>
 * 基础实体类
 */
@Getter
@Setter
@ToString
public abstract class BaseEntity  {
    private static final long serialVersionUID = -5488114907242694673L;


    // 状态: 0无效 1有效
    private Long status = 1L;
    /**
     * 删除标记:逻辑删除用, 0-表示未删除, 1-表示已删除
     */
    private String deletedFlag = "0";
    /**
     * 数据标识,S-系统数据(初始化),I-插入数据,O-其他
     */
    private String inputType = "I";
    /**
     * 描述
     */
    private String description = "";
    /**
     * 备注
     */
    private String note = "";

    private String updatedUser;
    private String createdUser;
    private Long updatedUserId;
    private Long createdUserId;
    private Date updatedTime;
    private Date createdTime;

}

身份证识别结果类

@Getter
@Setter
public class IDCardResult extends BaseEntity {
    /**
     * 身份证号
     */
    String idcard;
    /**
     * 籍贯
     */
    String address;
    /**
     * 性别 男/女
     */
    String sexnual;
    /**
     * 民族
     */
    String nation;
    /**
     * 出生年月 年/月/日 不补全
     */
    String birth;


}

身份证识别-控制层

/**
 * 识别身份证信息
 *
 * @param file 图片
 * @return 识别结果
 */
@PostMapping("secured/IDCardIdentify")
@ResponseBody
public IDCardResult identifyIDCard(@RequestParam("file") MultipartFile file) {
    return videoCollectService.identifyIDCard(file);
}

身份证识别-service层

/**
 * 调用接口识别身份证信息
 * @param file 图片
 * @return 结果
 */
IDCardResult identifyIDCard(MultipartFile file);
/**
 * 身份证识别
 *
 * @param file 图片
 * @return 结果
 */
@Override
public IDCardResult identifyIDCard(MultipartFile file) {
    String pictureParamName = "idcard";
    String ticketParamName = "appid";
    //IDCardIdentifyUrl 这个是识别的url的服务  录入identify.idCardUrl=http://47.XXXX:8888/idcardocr
    String jsonStr = identify(file, IDCardIdentifyUrl, pictureParamName, ticketParamName);  //==》这里
    if (jsonStr != null) {
        JSONObject object = JSON.parseObject(jsonStr);
        return object.getJSONArray("results").getJSONObject(0).getObject("ocrresult", IDCardResult.class);
    }
    return new IDCardResult();
}

所用到的identify公共这个方法

/**
 * 识别公共方法
 *
 * @param file             文件
 * @param interfaceUrl     接口地址
 * @param pictureParamName 文件参数名
 * @param ticketParamName  授权码参数名
 * @return 返回信息
 */
private String identify(MultipartFile file, String interfaceUrl, String pictureParamName, String ticketParamName) {
    CloseableHttpClient httpClient = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost(interfaceUrl);
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    String jsonStr = null;
    try {
        builder.addBinaryBody(pictureParamName, file.getBytes(), ContentType.MULTIPART_FORM_DATA, file.getOriginalFilename());
        //identifyToken 这个也是识别的token例如:identify.token=02628280fa5c45b1af06cXXX
        builder.addTextBody(ticketParamName, identifyToken, ContentType.MULTIPART_FORM_DATA);
        HttpEntity entity = builder.build();
        httpPost.setEntity(entity);
        CloseableHttpResponse response = httpClient.execute(httpPost);
        HttpEntity responseEntity = response.getEntity();
        jsonStr = EntityUtils.toString(responseEntity, "utf-8");
    } catch (IOException e) {
        e.printStackTrace();
    }
    return jsonStr;
}

这个方法需要MultipartEntityBuilder引入这个相关的maven

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpmime</artifactId>
    <version>4.5.13</version>
</dependency>

20.2-识别营业执照信息接口

营业执照信息实体

/**
 * @author Steven.sun
 * @date 2020/11/30 16:07
 * 营业执照识别结果
 */
@Getter
@Setter
public class BusinessLicenseResult extends BaseEntity {
    /**
     * 法人代表
     */
    String lawer;
    /**
     * 类型
     */
    String type;
    /**
     * 营业期限
     */
    String limit;
    /**
     * 地址
     */
    String address;
    /**
     * 注册资本
     */
    String regmoney;
    /**
     * 信用代码
     */
    String sid;
    /**
     * 成立日期
     */
    String created;
    /**
     * 经营范围
     */
    String business;

}

识别营业执照信息-控制层

/**
 * 识别营业执照信息
 * @param file 图片
 * @return 识别结果
 */
@PostMapping("licenseIdentify")
@ResponseBody
public BusinessLicenseResult identityBusinessLicense(@RequestParam("file") MultipartFile file){
    return videoCollectService.identityBusinessLicense(file);
}

识别营业执照信息-service层

/**
 * 调用接口识别营业执照信息
 * @param img 图片
 * @return 结果
 */
BusinessLicenseResult identityBusinessLicense(MultipartFile img);
/**
 * 营业执照识别
 *
 * @param file 图片
 * @return 结果
 */
@Override
public BusinessLicenseResult identityBusinessLicense(MultipartFile file) {
    //图片字段名
    String pictureParamName = "taxcard";
    //鉴权字段名
    String ticketParamName = "appid";
    //===taxLicenseIdentifyUrl是        identify.taxLicenseUrl=http://47.xxxx:8888/taxcardocr
    //identify  上面公共的方法
    String jsonStr = identify(file, taxLicenseIdentifyUrl, pictureParamName, ticketParamName);
    if (jsonStr != null) {
        return JSON.parseObject(jsonStr, BusinessLicenseResult.class);
    }
    return new BusinessLicenseResult();

}

20.3 语音识别接口

控制层

/**
 * 语音识别
 *
 * @param file 文件
 * @return 结果
 */
@PostMapping("APP_VOICE_IDENTIFY")
@ResponseBody
public String identifyVoice(@RequestParam("file") MultipartFile file) {
    return videoCollectService.identifyVoice(file);
}

service层

/**
 * 语音识别
 * @param file 文件
 * @return 结果
 */
String identifyVoice(MultipartFile file);
/**
 * 语音识别
 * @param file 文件
 * @return 结果
 */
@Override
public String identifyVoice(MultipartFile file) {
    String voiceParamName = "speechfile";
    String ticketParamName = "appid";
    //identify        公共的方法
    //voiceIdentifyUrl服务            identify.voiceUrl=http://47.xxxx:8888/speechrec
    return identify(file, voiceIdentifyUrl, voiceParamName, ticketParamName);
}

相关文章:

  • DeepSeek集成:如何将DeepSeek修炼成‘国殇剑舞‘
  • 数据库后续
  • python实现登录页面图形验证码
  • Pydantic字段元数据指南:从基础到企业级文档增强
  • 【软考备考】系统架构设计论文完整范文示例
  • iOS自定义collection view的page size(width/height)分页效果
  • 横扫SQL面试——事件流处理(峰值统计)问题
  • 8.3MW屋顶光伏+光储协同:上海汽车变速器低碳工厂的能源革命-安科瑞黄安南
  • 飞桨PP系列新成员PP-DocLayout开源,版面检测加速大模型数据构建,超百页文档图像一秒搞定
  • 解决 “Cannot read SQL script from class path resource [sql/XX.sql]“ 错误
  • 每日总结3.28
  • 卷积神经网络 - 转置卷积
  • Neo4j GDS-05-neo4j GDS 库中对应的中心性分析算法介绍
  • Netty——零拷贝
  • 上海SMT贴片技术解析与行业趋势
  • 【CSS3】02-选择器 + CSS特性 + 背景属性 + 显示模式
  • axios文件下载使用后端传递的名称
  • PyQt6实例_批量下载pdf工具_exe使用方法
  • OSPF邻居状态机
  • MAC环境给docker换源
  • 甘肃白银煤矿透水事故仍有3人失联,现场约510立方米煤泥拥堵巷道
  • 花旗回应减员传闻:持续评估人力资源战略,将为受影响的个人提供支持
  • 铜川耀州窑遗址内违法矿场存在多年,省市区文物部门多次处罚叫停仍在生产
  • 一女游客在稻城亚丁景区因高反去世,急救两个多小时未能恢复生命体征
  • 没有握手,采用翻译:俄乌三年来首次直接会谈成效如何?
  • 俄媒:俄乌代表团抵达谈判会场