laitimes

ID number API query interface

author:IT Intelligence Column

Interface description

Function description: Query the id card number to obtain information such as date of birth, gender, and issuing area of the ID card.

URL example

1) http protocol:

POST mode request: http://cha.ebaitian.cn/api/json?appid=xxx&module=getIDCardInfo&idcard=xxx&sign=xxx

GET mode request: http://cha.ebaitian.cn/api/json?type=get&appid=xxx&module=getIDCardInfo&idcard=xxx&sign=xxx

2) https protocol:

POST mode request: https://cha.ebaitian.cn/api/json?appid=xxx&module=getIDCardInfo&idcard=xxx&sign=xxx

GET mode request: https://cha.ebaitian.cn/api/json?type=get&appid=xxx&module=getIDCardInfo&idcard=xxx&sign=xxx

Request parameters

Packet body

{
"type": "get",
"appid": "1000xxxx",
"module": "getIDCardInfo",
"idcard": "420101199001010000",
"sign": "ecab4881ee80ad3d76bb1da68387428ca752eb885e52621a3129dcf4d9bc4fd4"
}           

Parameter description

Parameter required type description

Type No String authorization interface request mode

AppID is the AppID of the string authorization interface, please fill in the AppID you applied for on the I want to check the official website

The module is the data module of the string target request, and the query ID number is: getIDCardInfo

Idcard is the ID number to be queried by the string target, and only 18-digit second-generation ID numbers are supported

sign is a string request credential, the specific calculation method is shown in the following other instructions

Additional Instructions

1) type: optional value get, if assigned get, then submit data in the way of get; By default, data is submitted in post mode;

2) sign: signature verification, generated according to the formula $sign=sha256(appid=$appid&module=getIDCardInfo&idcard=$idcard&appkey=$appkey); Among them: appkey is the AppKey of the authorized interface, please fill in the AppKey you applied for on the official website of I want to check.

Construct the pseudocode as follows:

string type = "get"; //请求方式,可以赋值为:post
string appid = "1000xxxx"; //sdkappid 对应的 appid,需要业务方高度保密
string module = "getIDCardInfo"; //请求的数据模块,此处赋值:getIDCardInfo
string idcard = "420101199001010000"; //要查询的身份证号码,注意仅支持18位二代身份证号码
string sign = sha256(appid=1000xxxx&module=getIDCardInfo&idcard=420101199001010000&appkey=56cf61af4b7897e704f67deb88ae8f24);           

Response parameters

Packet body

{
"result":1,
"description":"TRUE",
"flag":"",
"idcardInfo":{
"birthday":"1996年02月01日",
"sex":"女",
"province":"湖北省",
"city":"武汉市",
"dis":"东西湖区",
"note":null
}
}           

Parameter description

Parameter required type description

result is the result of the string interface response: 0 - failed; 1- Success

Description is a description of the string interface response: typically TURE(result=1) and FALSE(result=0), or an error message is returned

Flag no string error description, no error return null

idcardInfo is an object that returns ID card information

IdcardInfo parameter description:

Parameter required type description

Birthday is String's date of birth

Sex is string gender

province is string issuing region, province (city/autonomous region)

city is a stricken licensing area, city (district/autonomous state)

dis is string issuing area, district (county/city/district)

Note No String other comments, generally empty

SDK and code samples

PHP SDK

Method one: Request data as a POST

//接口参数
$api_url='http://cha.ebaitian.cn/api/json';
$api_appid='1000xxxx';
$api_appkey='56cf61af4b7897e704f67deb88ae8f24';
//函数,以POST方式提交数据,PHP需要开启CURL函数;数据传输安全,建议使用
function getIDCardInfo($idcard){
global $api_url,$api_appid,$api_appkey;
$posturl=$api_url;
$data='appid='.$api_appid.'&module=getIDCardInfo&idcard='.$idcard;
$sign=hash("sha256",$data.'&appkey='.$api_appkey);
$postdata=array("appid"=>$api_appid,"appkey"=>$api_appkey,"module"=>"getIDCardInfo","idcard"=>$idcard,'sign'=>$sign);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $posturl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$output = curl_exec($curl);
curl_close($curl);
$obj=json_decode($output);
$result=$obj->result;
if($result==1){
$value=$obj->idcardInfo->birthday;
$value.=','.$obj->idcardInfo->sex;
$value.=','.$obj->idcardInfo->province;
$value.=','.$obj->idcardInfo->city;
$value.=','.$obj->idcardInfo->dis;
}else{
$value=$obj->flag;
}
return $value;
}
//调用函数
$idcard='420101199001010000';
echo getIDCardInfo($idcard);
exit;           

Method two: Request data in GET mode

//接口参数
$api_url='http://cha.ebaitian.cn/api/json';
$api_appid='1000xxxx';
$api_appkey='56cf61af4b7897e704f67deb88ae8f24';
//函数,以GET方式提交数据
function getIDCardInfo($idcard){
global $api_url,$api_appid,$api_appkey;
$data='appid='.$api_appid.'&module=getIDCardInfo&idcard='.$idcard;
$sign=hash("sha256",$data.'&appkey='.$api_appkey);
$info_get=file_get_contents($api_url.'?type=get&'.$data.'&sign='.$sign);
$info_json=json_decode($info_get, true);
$result=$info_json['result'];
if($result==1){
$value=$info_json['idcardInfo']['birthday'];
$value.=','.$info_json['idcardInfo']['sex'];
$value.=','.$info_json['idcardInfo']['province'];
$value.=','.$info_json['idcardInfo']['city'];
$value.=','.$info_json['idcardInfo']['dis'];
}else{
$value=$info_json['flag'];
}
return $value;
}
//调用函数
$idcard='420101199001010000';
echo getIDCardInfo($idcard);
exit;           

Java SDK

//以下示例是以 GET 方式请求数据
public class QueryHelper {
public static String apiurl="http://cha.ebaitian.cn/api/json";
public static String appid="1000xxxx";
public static String appkey="56cf61af4b7897e704f67deb88ae8f24";
public static String module="getIDCardInfo";
public static String getSHA256Str(String str){
MessageDigest messageDigest;
String encdeStr = "";
try {
messageDigest = MessageDigest.getInstance("SHA-256");
byte[] hash = messageDigest.digest(str.getBytes("UTF-8"));
encdeStr = Hex.encodeHexString(hash);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return encdeStr;
}
public static String get(String urlString) {
try {
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5 * 1000);
conn.setReadTimeout(5 * 1000);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setInstanceFollowRedirects(false);
conn.setRequestMethod("GET");
int responseCode = conn.getResponseCode();
if (responseCode == 200) {
StringBuilder builder = new StringBuilder();
BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream(),"utf-8"));
for (String s = br.readLine(); s != null; s = br.readLine()) {
builder.append(s);
}
br.close();
return builder.toString();
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static String queryIDCard(String idcard){
String sign=getSHA256Str("appid="+appid+"&module="+module+"&idcard="+idcard+"&appkey="+appkey);
String url=apiurl+"?type=get&appid="+appid+"&module="+module+"&idcard="+idcard+"&sign="+sign;
return get(url);
}
}
//使用示例
QueryHelper.queryIDCard("420101199001010000");           

Python SDK

#!/usr/bin/python
# -*- coding: utf-8 -*-
import httplib2
import hashlib
from urllib.parse import urlencode #python3
#from urllib import urlencode #python2
apiurl='http://cha.ebaitian.cn/api/json'
appid='1000xxxx'
appkey='56cf61af4b7897e704f67deb88ae8f24'
module='getIDCardInfo'
idcard='420101199001010000'
data='appid='+appid+'&module='+module+'&idcard='+idcard
sign_data=data+'&appkey='+appkey
# from Crypto.Cipher import AES
# from Crypto.Hash import SHA256
# 256
hash_256 = hashlib.sha256()
hash_256.update(sign_data.encode('utf-8'))
sign = hash_256.hexdigest()
postdata = urlencode({'appid':appid,'module':module,'idcard':idcard,'sign':sign})
url = apiurl+'?'+postdata
http = httplib2.Http()
response, content = http.request(url,'GET')
print(content.decode("utf-8"))
Node.js SDK           

Method one: Request data as a POST

//以 POST 方式提交
var http = require('http');
var querystring = require('querystring');
//参数设置
var appid = '1000xxxx';
var appkey = '56cf61af4b7897e704f67deb88ae8f24';
var module = 'getIDCardInfo';
//目标查询身份证号码
var idcard='420101199001010000';
//签名,SHA256 不可直接调用;函数参考下载地址:
https://github.com/alexweber/jquery.sha256
var sign = SHA256('appid='+appid+'&module='+module+'&idcard='+idcard+'&appkey='+appkey);
//这是需要提交的数据
var post_data = {
appid: appid,
module: module,
idcard: idcard,
sign: sign
};
var content = querystring.stringify(post_data);
var options = {
hostname: 'cha.ebaitian.cn',
port: 80,
path: '/api/json',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
};
var req = http.request(options, function (res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
//JSON.parse(chunk)
});
});
req.on('error', function (e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
req.write(content);
req.end();           

Method two: Request data in GET mode

//以 GET 方式提交
var http = require('http');
var querystring = require('querystring');
//参数设置
var appid = '1000xxxx';
var appkey = '56cf61af4b7897e704f67deb88ae8f24';
var module = 'getIDCardInfo';
//目标查询身份证号码
var idcard='420101199001010000';
//签名,SHA256 不可直接调用;函数参考下载地址:
https://github.com/alexweber/jquery.sha256
var sign = SHA256('appid='+appid+'&module='+module+'&idcard='+idcard+'&appkey='+appkey);
//这是需要提交的数据
var data = {
appid: appid,
module: module,
idcard: idcard,
sign: sign
};
var content = querystring.stringify(data);
var options = {
hostname: 'cha.ebaitian.cn',
port: 80,
path: '/api/json?' + content,
method: 'GET'
};
var req = http.request(options, function (res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function (e) {
console.log('problem with request: ' + e.message);
});
req.end();           

C# SDK

using System;
using System.Collections.Generic;
using System.Web;
using System.Net;
using System.Text;
public class getIDCardInfo{
public static string getInfo(string appid, string appkey, string module, string idcard){
string url = string.Format("http://cha.ebaitian.cn/api/json?type=get&appid={0}&module={1}&idcard={2}&sgin={3}", appid, module, idcard, sgin);
using (WebClient client = new WebClient()){
client.Encoding = Encoding.UTF8;
return client.DownloadString(url);
}
}
}
string idcardInfo = getIDCardInfo.getInfo("1000xxxx", "getIDCardInfo", "420101199001010000", "ecab4881ee80ad3d76bb1da68387428ca752eb885e52621a3129dcf4d9bc4fd4", Request.UserHostAddress);
Console.WriteLine(idcardInfo);
Response.Write(idcardInfo);           

JavaScript SDK

方法一:以 POST 方式请求数据
//使用 JQuery 请先加载最新的 JQuery 插件
//参数设置
var apiurl = 'http://cha.ebaitian.cn/api/json';
var appid = '1000xxxx';
var appkey = '56cf61af4b7897e704f67deb88ae8f24';
var module = 'getIDCardInfo';
//目标查询身份证号码
var idcard='420101199001010000';
//签名,SHA256 不可直接调用;函数参考下载地址:
https://github.com/alexweber/jquery.sha256
var sign = SHA256('appid='+appid+'&module='+module+'&idcard='+idcard+'&appkey='+appkey);
//提交数据
$.ajax({
url:apiurl,
type:'post',
dataType:'json',
data:{
appid:appid,
module:module,
idcard:idcard,
sign:sign
},
success:function(res){
console.log(res);
}
});           

Method two: Request data in GET mode

//使用 JQuery 请先加载最新的 JQuery 插件
//参数设置
var apiurl = 'http://cha.ebaitian.cn/api/json';
var appid = '1000xxxx';
var appkey = '56cf61af4b7897e704f67deb88ae8f24';
var module = 'getIDCardInfo';
//目标查询身份证号码
var idcard='420101199001010000';
//签名,SHA256 不可直接调用;函数参考下载地址:
https://github.com/alexweber/jquery.sha256
var sign = SHA256('appid='+appid+'&module='+module+'&idcard='+idcard+'&appkey='+appkey);
//提交数据
$.ajax({
url:apiurl,
type:'post',
dataType:'json',
data:{
appid:appid,
module:module,
idcard:idcard,
sign:sign
},
success:function(res){
console.log(res);
}
});           

ASP SDK

'设置参数
dim apiurl, appid, appkey, module, idcard, sign
apiurl="http://cha.ebaitian.cn/api/json"
appid="1000xxxx'
appkey="56cf61af4b7897e704f67deb88ae8f24"
module="getIDCardInfo"
idcard="420101199001010000"
'签名,SHA256 不可直接调用;函数参考地址:
https://blog.csdn.net/yesoce/article/details/128546
sgin=SHA256("appid=&appid&"&module="&module&"&idcard="&idcard&"&appkey="&appkey)
'异步提交数据
function PostHTTPPage(url,data)
dim Http
set Http=server.createobject("MSXML2.SERVERXMLHTTP.3.0")
Http.open "POST",url,false
Http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
Http.send(data)
if Http.readystate<>4 then
exit function
End if
PostHTTPPage=bytesToBSTR(Http.responseBody,"UTF-8")
set http=nothing
if err.number<>0 then err.Clear
End function
'提交数据
dim postdata, strTest
postdata="appid=&appid&"&module="&module&"&idcard="&idcard&"&sign="&sign
strTest=PostHTTPPage(apiurl,postdata)
'返回结果
response.write(strTest)
response.end           

frequently asked questions

The API interface parameter is empty

This error returns JSON data as follows:

Copy

{

"result":0,

"description": "API interface parameter is empty",

"flag":"appid:sign"

}

Workaround:

1) Please check whether the appid and sign are empty;

2) Make sure that the appid is obtained from the official website to obtain the correct interface authorization;

3) Make sure that the sign calculation is generated correctly.

The API interface parameter is not valid

This error returns JSON data as follows:

Copy

{

"result":0,

"description": "Invalid API interface parameter",

"flag":"appid"

}

Workaround:

1) Please check whether the appid is correct;

2) Make sure that the appid is obtained from the official website to obtain the correct interface authorization.

The API interface authorization has expired

This error returns JSON data as follows:

Copy

{

"result":0,

"description": "API interface authorization expired",

"flag":"end:2018-12-31 23:59:59"

}

Workaround:

1) Check whether the authorization period of the appid corresponding to the interface has expired;

2) If the interface authorization expires, please go to the official website to update (free users directly update, no need to renew) or renew (for commercial paying users).

Signature error

This error returns JSON data as follows:

Copy

{

"result":0,

"description": "Signature error",

"flag":"getIDCardInfo->sign"

}

Workaround:

1) Please check whether the sign signature calculation is correct;

2) Signature sign is generated according to the formula $sign=sha256(appid=$appid&module=getIDCardInfo&idcard=$idcard&appkey=$appkey); Among them: appkey is the AppKey of the authorized interface, please fill in the AppKey you applied for on the official website of I want to check.

Requests are restricted

This error returns JSON data as follows:

Copy

{

"result":0,

"description": "Request restricted",

"flag":"getIDCardInfo->daylimit"

}

Workaround:

1) The authorized interface has exceeded the maximum limit of the current interface product request;

2) Please upgrade your interface products according to the actual usage needs.