1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| <?php
header('Content-type:text/html;charset=utf-8');
$appkey = "*********************";
$url = "http://op.juhe.cn/idcard/query";
$params = array( "idcard" => "36072219940809****", "realname" => "曹贤亮", "key" => $appkey, );
$paramstring = http_build_query($params); $content = juhecurl($url,$paramstring); $result = json_decode($content,true);
if($result){ if($result['error_code'] == '0'){ if($result['result']['res'] == '1'){ echo "身份证号码和真实姓名一致"; } else { echo "身份证号码和真实姓名不一致"; } } 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_USERAGENT , 'JuheData' ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 ); curl_setopt( $ch, CURLOPT_TIMEOUT , 60); curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true ); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if( $ispost ) { curl_setopt( $ch , CURLOPT_POST , true ); curl_setopt( $ch , CURLOPT_POSTFIELDS , $params ); curl_setopt( $ch , CURLOPT_URL , $url ); } else { if($params) { curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params ); } else { curl_setopt( $ch , CURLOPT_URL , $url); } }
$response = curl_exec( $ch );
if ($response === FALSE) { return false; }
$httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE ); $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
curl_close( $ch );
return $response; }
|