身份证数据查询API接口 php开发接入过程

身份证数据查询API接口 php开发接入过程

  1. 第一步建立前端提交页面

     此处一共提交的数据有四项
     1.用户名
     2.银行卡号
     3.身份证号
     4.绑定的手机号
    
     前端页面代码:
     <!DOCTYPE html>
     <html>
     <head>
         <title>身份证信息查询四联</title>
     
         <link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.css"/>
         <link rel="stylesheet" href="dist/css/bootstrapValidator.css"/>
     
         <script type="text/javascript" src="vendor/jquery/jquery.min.js"></script>
         <script type="text/javascript" src="vendor/bootstrap/js/bootstrap.min.js"></script>
         <script type="text/javascript" src="dist/js/bootstrapValidator.js"></script>
         
     </head>
     <body>
     <div class="container">
         <div class="row">
             <div class="col-lg-8 col-lg-offset-2">
                 <div class="page-header">
                     <h2>身份证信息查询四联</h2>
                 </div>
     
                 <form id="defaultForm" method="post" class="form-horizontal" action="check.php">
                       <div class="form-group">
                         <label class="col-lg-3 control-label" >银行卡帐号</label>
                         <div class="col-lg-5">
                             <input type="text" class="form-control" name="bankcard" placeholder="请输入银行卡帐号"/>
                         </div>
                     </div>
                        <div class="form-group">
                         <label class="col-lg-3 control-label"  >持卡人姓名</label>
                         <div class="col-lg-5">
                             <input type="text" class="form-control" name="username" placeholder="请输入持卡人姓名"/>
                         </div>
                     </div>
                     <div class="form-group">
                         <label class="col-lg-3 control-label"  >绑定手机号</label>
                         <div class="col-lg-5">
                             <input type="text" class="form-control" name="phonenumber" placeholder="请输入绑定手机号"/>
                         </div>
                     </div>
     
                     <div class="form-group">
                         <label class="col-lg-3 control-label"  >持卡人身份证</label>
                         <div class="col-lg-5">
                             <input type="text" class="form-control" name="idcard" placeholder="请输入持卡人身份证"/>
                         </div>
                     </div>
     
     
                     <div class="form-group">
                         <div class="col-lg-9 col-lg-offset-3">
                             <button type="submit" class="btn btn-primary">查询</button>
                         </div>
                     </div>
                 </form>
             </div>
         </div>
     </div>
     
     <script type="text/javascript">
     $(document).ready(function() {
         $('#defaultForm')
             .bootstrapValidator({
                 message: 'This value is not valid',
                 feedbackIcons: {
                     valid: 'glyphicon glyphicon-ok',
                     invalid: 'glyphicon glyphicon-remove',
                     validating: 'glyphicon glyphicon-refresh'
                 },
                 fields: {
                       bankcard: {
                         message: '银行卡号不能获取',
                         validators: {
                             notEmpty: {
                                 message: '银行卡号不能为空'
                             },
                             stringLength: {
                                 min: 15,
                                 max: 30,
                                 message: '银行卡号长度不符'
                             },
                             /*remote: {
                                 url: 'remote.php',
                                 message: 'The username is not available'
                             },*/
                             regexp: {
                                 regexp: /^[0-9_\.]+$/,
                                 message: '银行卡号不符合规范'
                             }
                         }
                     },
                     username: {
                         message: 'The username is not valid',
                         validators: {
                             notEmpty: {
                                 message: '姓名不能为空'
                             },
                             stringLength: {
                                 min: 2,
                                 max: 4,
                                 message: '超出长度'
                             },
                             /*remote: {
                                 url: 'remote.php',
                                 message: 'The username is not available'
                             },*/
                         }
                     },
                     phonenumber: {
                         message: 'The username is not valid',
                         validators: {
                             notEmpty: {
                                 message: '手机号不能为空'
                             },
                             stringLength: {
                                 min: 11,
                                 max: 11,
                                 message: '手机号长度不符合'
                             },
                             regexp: {
                                 regexp: /^[0-9_\.]+$/,
                                 message: '手机号不符合规范'
                             }
                         }
                     },
                     idcard: {
                         message: '身份证号不能获取',
                         validators: {
                             notEmpty: {
                                 message: '身份证号不能为空'
                             },
                             stringLength: {
                                 min: 15,
                                 max: 18,
                                 message: '身份证号长度不符'
                             },
                             /*remote: {
                                 url: 'remote.php',
                                 message: 'The username is not available'
                             },*/
                             regexp: {
                                 regexp: /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9X]$/,
                                 message: '银行卡号不符合规范'
                             }
                         }
                     }
                 }
             })
             .on('success.form.bv', function(e) {
                 // Prevent form submission
                 e.preventDefault();
                 //e.preventDefault();
     
                 // Get the form instance
                 var $form = $(e.target);
     
                 // Get the BootstrapValidator instance
                 
                 // Use Ajax to submit form data
                 $.post($form.attr('action'), $form.serialize(), function(result) {
                     var jsonString = JSON.stringify(result);
                     var newdata = JSON.parse(jsonString);
                     if (newdata.showapi_res_code == 0){
                         if (newdata.showapi_res_body.ret_code == 0){
                             if(newdata.showapi_res_body.code == 0){
                             alert("成功匹配");
                                 }
                             }else{
                             alert("错误 : "+newdata.showapi_res_body.msg);
                         }
                     }else{
                         alert("系统错误,查询失败");
                     }
     
                     
                     //alert (data.showapi_res_body.msg);
                 }, 'json');
                 
             });
     });
     </script>
     </body>
     </html>
     
     利用bootstrapValidator 对表单数据进行验证,post提交数据到后台check.php页面
    
  2. check.php页面接收表单数据,并提交到API服务器,获取数据

     check.php代码如下:
         <?php
         header("Content-Type:text/html;charset=UTF-8");
         date_default_timezone_set("PRC");
         
         function createParam ($paramArr,$showapi_secret) {
         $paraStr = "";
         $signStr = "";
         ksort($paramArr);
         foreach ($paramArr as $key => $val) {
         if ($key != '' && $val != '') {
         $signStr .= $key.$val;
         $paraStr .= $key.'='.urlencode($val).'&';
         }
         }
         $signStr .= $showapi_secret;//排好序的参数加上secret,进行md5
         $sign = strtolower(md5($signStr));
         $paraStr .= 'showapi_sign='.$sign;//将md5后的值作为参数,便于服务器的效验
         return $paraStr;
         }
         
         if (IS_POST) {
         $showapi_appid = '1016**';//替换此值,在官网的"我的应用"中找到相关值  
         $showapi_secret = 'd5649b8ebdd84b69****a4f0b******'; //替换此值,在官网的"我的应用"中找到相关值 
         $paramArr = array(
         'showapi_appid'=> $showapi_appid,
                         'acct_pan'=> $_POST['bankcard'],
                         'acct_name'=> $_POST['username'],
                         'phone_num'=> $_POST['phonenumber'],
                         'cert_type'=> "01",
                         'cert_id'=> $_POST['idcard'],
                         'needBelongArea'=> "true"
         
         );
         
         $param = createParam($paramArr,$showapi_secret);
         $url = 'http://route.showapi.com/1072-5?'.$param;
         $result = file_get_contents($url);
         print_r ($result);
         }
         ?>
    

3.api 数据接口 https://www.showapi.com/apiGateway/view/?apiCode=1072&pointCode=5

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容