欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > Java实现 自主学习一套身份证识别(识别营业执照信息和语音识别接口)

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

2025/3/31 21:45:24 来源:https://blog.csdn.net/weixin_45979122/article/details/146549969  浏览:    关键词: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/idcardocrString 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=02628280fa5c45b1af06cXXXbuilder.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/speechrecreturn identify(file, voiceIdentifyUrl, voiceParamName, ticketParamName);
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词