互亿无线 · 文档中心

身份证OCR识别 - 代码示例


Java对接身份证OCR识别DEMO示例
本文为您提供了Java语言版本的身份证OCR识别的DEMO示例,快速对接调用,轻松完成系统集成,智能识别身份证图片中的文字内容。

身份证OCR识别API接口文档 点击下载

身份证OCR识别接入指南 点击访问



// 接口类型:互亿无线OCR识别接口
// 账户注册:https://user.ihuyi.com/register.html
// 注意事项:
// DEMO仅作参考

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import util.StringUtil;

public class test {
	
	private static String Url = "https://api.ihuyi.com/ocr/Submit.json";
	
	public static void main(String [] args) {
		
		HttpClient client = new HttpClient();
		PostMethod method = new PostMethod(Url);

		client.getParams().setContentCharset("UTF-8");
		method.setRequestHeader("ContentType","application/x-www-form-urlencoded;charset=UTF-8");

		String account = 'APPID'
		String password = 'APPKEY'
		String app = 'idcard' //固定值
		String img_base64 = ''
		String img_url = 'http://www.xx.com/xx.png'
		String _now = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new java.util.Date(Unix timestamp *1000))
		String password_raw = account + password + app + img_base64 + img_url + _now
		// System.out.println((password_raw)
		String password_md5 = util.StringUtil.MD5Encode(password_raw)
		// System.out.println((password_raw)

		NameValuePair[] data = {//提交认证
			    new NameValuePair("account", account),
			    // new NameValuePair("password", password),
			    new NameValuePair("password", password_md5),
			    new NameValuePair("app", app),
			    new NameValuePair("img_base64", img_base64),
			    new NameValuePair("img_url", img_url),
		};
		method.setRequestBody(data);

		try {
			client.executeMethod(method);

			String res =method.getResponseBodyAsString();

			System.out.println(res);

		} catch (HttpException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
}

现在注册,即享新用户礼包!

在线咨询
电话咨询

服务热线:

4008 808 898

服务热线(工作时间):

4008 808 898

业务咨询(非工作时间):

4008 808 898

售后咨询(非工作时间):

4008 808 898

验证码已发送到您的手机,请查收!

填写验证码后,点击“开通体验账户”自动开通体验账户。

收不到短信验证码?
×