IdVerify.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace app\service\id;
  3. use app\service\id\config\DES;
  4. use traits\think\Instance;
  5. /**
  6. * @desc 综合业务平台--查询 API
  7. * @author harvey
  8. * @since 2010-11-20
  9. *
  10. */
  11. class IdVerify {
  12. use Instance;
  13. /**
  14. * 取得数据
  15. * @param string $type 查询类型
  16. * @param string $param 查询参数
  17. * @return \SimpleXMLElement
  18. */
  19. function getData( $param) {
  20. $wsdlURL = "http://jypt.id5.cn/gztboss/services/QueryValidatorServices?wsdl";
  21. $partner = config('site.verify_id_gzt_account');
  22. $partnerPW = config('site.verify_id_gzt_password');
  23. $Key = "12345678";
  24. $iv = "12345678";
  25. $typeData = "1A020201";
  26. //var_dump ( $soap->__getTypes () );
  27. //exit();
  28. $DES = new DES ( $Key, $iv );
  29. //@todo 加密数据
  30. $partner = $DES->encrypt ( $partner );
  31. //echo $partner;exit;
  32. $partnerPW = $DES->encrypt ( $partnerPW );
  33. $type = $DES->encrypt ( $typeData );
  34. //先将中文转码
  35. $param = mb_convert_encoding ( $param, "GBK", "UTF-8" );
  36. $param = $DES->encrypt ( $param );
  37. $params = array (
  38. "userName_" => $partner,
  39. "password_" =>$partnerPW,
  40. "type_" => $type,
  41. "param_" => $param
  42. );
  43. $soap = new \SoapClient ( $wsdlURL );
  44. //请求查询
  45. //queryBatch
  46. $data = $soap->querySingle ( $params );
  47. //@todo 解密数据 //queryBatchReturn
  48. $resultXML = $DES->decrypt ( $data->querySingleReturn );
  49. $resultXML = mb_convert_encoding ( $resultXML, "UTF-8", "GBK" );
  50. $resultObj=simplexml_load_string($resultXML);
  51. return $resultObj;
  52. }
  53. public function check($name,$id){
  54. $result=$this->getData(sprintf('%s,%s,%s',$name,$id,session_create_id()));
  55. if(empty($result)){
  56. throw_user('请求失败(gzt)');
  57. }
  58. if($result->message->status>0){
  59. throw_user($result->message->value);
  60. }
  61. if($result->policeCheckInfos->policeCheckInfo->compStatus!=3){
  62. throw_user(sprintf('身份证号码有误(%s)',$result->policeCheckInfos->policeCheckInfo->compResult));
  63. }
  64. }
  65. /**
  66. * 格式化参数
  67. * @param array $params 参数数组
  68. * @return string
  69. */
  70. function formatParam($queryType, $params) {
  71. $supportClass = array ("1A020201" => "Name,CardNum" );
  72. if (empty ( $supportClass[$queryType] )) {
  73. return - 1;
  74. }
  75. $keys = array ();
  76. $values = array ();
  77. foreach ( $params as $key => $value ) {
  78. $keys [] = $key;
  79. $values [] = strtoupper ( $value );
  80. }
  81. $param = str_replace ( $keys, $values, $supportClass[$queryType] );
  82. return $param;
  83. }
  84. /**
  85. * 取得生日(由身份证号)
  86. * @param int $id 身份证号
  87. * @return string
  88. */
  89. function getBirthDay($id) {
  90. switch (strlen ( $id )) {
  91. case 15 :
  92. $year = "19" . substr ( $id, 6, 2 );
  93. $month = substr ( $id, 8, 2 );
  94. $day = substr ( $id, 10, 2 );
  95. break;
  96. case 18 :
  97. $year = substr ( $id, 6, 4 );
  98. $month = substr ( $id, 10, 2 );
  99. $day = substr ( $id, 12, 2 );
  100. break;
  101. }
  102. $birthday = array (
  103. 'year' => $year,
  104. 'month' => $month,
  105. 'day' => $day
  106. );
  107. return $birthday;
  108. }
  109. /**
  110. * 取得性别(由身份证号)--可能不准
  111. * @param int $id 身份证号
  112. * @return string
  113. */
  114. function getSex($id) {
  115. switch (strlen ( $id )) {
  116. case 15 :
  117. $sexCode = substr ( $id, 14, 1 );
  118. break;
  119. case 18 :
  120. $sexCode = substr ( $id, 16, 1 );
  121. break;
  122. }
  123. if ($sexCode % 2) {
  124. return "男";
  125. } else {
  126. return "女";
  127. }
  128. }
  129. /**
  130. * 格式化数据
  131. * @param string $type
  132. * @param srring $data
  133. * @return array
  134. */
  135. function formatData($type, $data) {
  136. switch ($type) {
  137. case "1A020201" :
  138. $detailInfo = $data ['policeCheckInfos']['policeCheckInfo'];
  139. $birthDay = $this->getBirthDay ( $detailInfo['identitycard'] );
  140. $sex = $this->getSex ( $detailInfo ['identitycard'] );
  141. $info = array (
  142. 'name' => $detailInfo ['name'],
  143. 'identitycard' => $detailInfo ['identitycard'],
  144. 'sex' => $sex,
  145. 'compStatus' => $detailInfo ['compStatus'],
  146. 'compResult' => $detailInfo ['compResult'],
  147. 'policeadd' => $detailInfo ['policeadd'],
  148. //'checkPhoto' => $detailInfo ['checkPhoto'],
  149. 'birthDay' => $birthDay,
  150. 'idcOriCt2' => $detailInfo ['idcOriCt2'],
  151. 'resultStatus' => $detailInfo ['compStatus']
  152. );
  153. break;
  154. default :
  155. $info = array (false );
  156. break;
  157. }
  158. return $info;
  159. }
  160. }