废话不说 直接代码
card.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>身份证校验</title> </head> <body> <form action="card.php" method="get"> <input type="text" name="cardNo"><br> <input type="text" name="realName"><br> <input type="submit" name="查询"> </form> </body> </html>
card.php
<?php $host = "http://aliyunverifyidcard.haoservice.com"; $path = "/idcard/VerifyIdcardv2"; $method = "GET"; $realName=$_GET['realName'];//表单中获取查询名字 $cardNo=$_GET['cardNo'];//表单中获取查询的身份证号码 $appcode = "ff90fe45686e4cb8b3e260f2692798b4";//阿里云申请的appcode $headers = array(); array_push($headers, "Authorization:APPCODE " . $appcode); $querys = "cardNo=$cardNo&realName=$realName"; $bodys = ""; $url = $host . $path . "?" . $querys; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, true); if (1 == strpos("$".$host, "https://")) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys); $response = curl_exec($curl); $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $headers = substr($response, 0, $header_size); $body = substr($response, $header_size); print_r($body); //可以看见返回的格式数据 开发时可以注释 //解析 $body对象 $r=json_decode($body); echo "<hr>"; echo "查询结果:".$r->result->isok?"真":"假"; /* 如果返回结果为真 可以查询出该人一些基本信息 echo "籍贯:".$r->result->IdCardInfor->area;*/ ?>
和阿里云一样 主要解析json格式 建议先 print_r ($body) 得到返回的所有数据再进行解析。