//https://www.juhe.cn/docs/api/id/287 //如需请求加密接口,加密方式请参考https://www.sdk.cn/details/d591E8oY9X9r67veZz $apiurl="http://apis.juhe.cn/idimage/verify";//请求地址 $key = "b6c247bcf84383ec06da1da1fa4ff110";//32位的KEY $imgurl='public/sfz2.jpg'; $image = imgtobase64($imgurl,false);//真实姓名 $side="front";// front:正面识别;back:反面识别; $params=compact('key','image','side');//组合请求参数 $content=juhecurl($apiurl,$params,1);//获取接口返回内容json字符串 $result = json_decode($content,true);//解析成数组 /*echo '
'; echo print_r($result); echo '错误代码:'.$result['error_code']; echo '真实姓名:'.$result['result']['realname'];*/ if($result){ if($result['error_code']=='0'){ /* if($result['result']['res'] == '1'){ echo "身份证号码和真实姓名一致"; }else{ echo "身份证号码和真实姓名不一致"; }*/ echo ''; print_r($result); echo '真实姓名:'.$result['result']['realname']; }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 ) { echo $paramsString; 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; } //支持远程和本地 function imgtobase64($img='',$isgs=true){ if($isgs){ $imageInfo = getimagesize($img); return 'data:' . $imageInfo['mime'] . ';base64,' . chunk_split(base64_encode(file_get_contents($img))); } //不包含data:image/jpeg;base64, $imageInfo = getimagesize($img); return chunk_split(base64_encode(file_get_contents($img))); }