申请接口
接口备注:识别身份证正面或反面的一些关键字
通过https://www.juhe.cn/docs/api/id/287自助申请开通接口,获取API请求KEY
PHP示例代码
其中将证件图片转为base64字符串请参考https://www.sdk.cn/details/vOVl36qOLmlV8E9WXJ
$apiurl="http://apis.juhe.cn/idimage/verify";//请求地址
$key = "";//32位的KEY
$image= "";//图片base64后字符串
$side="front";//正反面
$params=compact('key','image','side');//组合请求参数
$content=juhecurl($apiurl,$params,1);//post请求获取接口返回内容json字符串
$result = json_decode($content,true);//解析成数组
if($result){
if($result['error_code']=='0'){
print_r($result);
}else{
echo $result['error_code'].":".$result['reason'];
}
}else{
echo "请求失败";
}
//网络请求方法
function juhecurl($url,$params=false,$ispost=0){
$httpInfo = array();
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 3);
curl_setopt( $ch, CURLOPT_TIMEOUT , 8);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
if ($params) {
if (is_array($params)) {
$paramsString = http_build_query($params);
} else {
$paramsString = $params;
}
} else {
$paramsString = "";
}
if( $ispost )
{
curl_setopt( $ch , CURLOPT_POST , true );
curl_setopt( $ch , CURLOPT_POSTFIELDS , $paramsString);
curl_setopt( $ch , CURLOPT_URL , $url );
}
else
{
if($paramsString ){
curl_setopt( $ch , CURLOPT_URL , $url.'?'.$paramsString);
}else{
curl_setopt( $ch , CURLOPT_URL , $url);
}
}
$response = curl_exec( $ch );
if ($response === FALSE) {
//echo "cURL Error: " . curl_error($ch);
return false;
}
$httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
$httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
curl_close( $ch );
return $response;
}
JSON返回示例
身份证正面识别结果示例:
{
"reason": "成功",
"result":{
"realname": "张三",/*姓名*/
"sex": "男",/*性别*/
"nation": "侗",/*民族*/
"born": "19760613",/*出生日期*/
"address": "贵州省都匀市甘塘镇长红机器厂散居户169号",/*地址*/
"idcard": "522701197606131935",/*身份证号*/
"side": "front",/*正面*/
"orderid": 339057896/*本次查询流水号*/
},
"error_code": 0
}
------------------------------------------------------------------------------
身份证背面识别结果示例:
{
"reason": "成功",
"result":{
"begin": "20130501",/*签发日期*/
"department": "东台市公安局",/*签发机关*/
"end": "20180501",/*失效日期*/
"side": "back",/*反面*/
"orderid": 478799279/*本次查询流水号*/
},
"error_code": 0
}