本文转自SDK社区:https://www.sdk.cn/details/djgylbOGwQoybxAN1Z
一、申请接口
通过https://www.juhe.cn/docs/api/id/103自助申请开明接口,获取API申请KEY。
二、用示例代码PHP
//如需申请加密接口,加密形式请参考 https://www.sdk.cn/details/d5…
$apiurl="http://op.juhe.cn/idcard/query";//申请地址 $key = "";//32位的KEY $realname = "";//实在姓名 $idcard="";//身份证号码 $params=compact('key','realname','idcard');//组合申请参数 $content=juhecurl($apiurl,$params);//获取接口返回内容json字符串 $result = json_decode($content,true);//解析成数组 if($result){ if($result['error_code']=='0'){ if($result['result']['res'] == '1'){ echo "身份证号码和实在姓名统一"; }else{ echo "身份证号码和实在姓名不统一"; } #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; }