IdVerify.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. ini_set('default_socket_timeout',3);
  44. $soap = new \SoapClient ( $wsdlURL );
  45. //请求查询
  46. //queryBatch
  47. $data = $soap->querySingle ( $params );
  48. //@todo 解密数据 //queryBatchReturn
  49. $resultXML = $DES->decrypt ( $data->querySingleReturn );
  50. $resultXML = mb_convert_encoding ( $resultXML, "UTF-8", "GBK" );
  51. $resultObj=simplexml_load_string($resultXML);
  52. return $resultObj;
  53. }
  54. public function check($name,$id){
  55. try {
  56. $result=$this->getData(sprintf('%s,%s,%s',$name,$id,session_create_id()));
  57. }catch (\Exception $e){
  58. throw_user("请求验证身份失败");
  59. }
  60. if(empty($result)){
  61. throw_user('请求失败(gzt)');
  62. }
  63. if($result->message->status>0){
  64. throw_user($result->message->value);
  65. }
  66. if($result->policeCheckInfos->policeCheckInfo->compStatus!=3){
  67. throw_user(sprintf('身份证号码有误(%s)',$result->policeCheckInfos->policeCheckInfo->compResult));
  68. }
  69. }
  70. /**
  71. * 格式化参数
  72. * @param array $params 参数数组
  73. * @return string
  74. */
  75. function formatParam($queryType, $params) {
  76. $supportClass = array ("1A020201" => "Name,CardNum" );
  77. if (empty ( $supportClass[$queryType] )) {
  78. return - 1;
  79. }
  80. $keys = array ();
  81. $values = array ();
  82. foreach ( $params as $key => $value ) {
  83. $keys [] = $key;
  84. $values [] = strtoupper ( $value );
  85. }
  86. $param = str_replace ( $keys, $values, $supportClass[$queryType] );
  87. return $param;
  88. }
  89. /**
  90. * 取得生日(由身份证号)
  91. * @param int $id 身份证号
  92. * @return string
  93. */
  94. function getBirthDay($id) {
  95. switch (strlen ( $id )) {
  96. case 15 :
  97. $year = "19" . substr ( $id, 6, 2 );
  98. $month = substr ( $id, 8, 2 );
  99. $day = substr ( $id, 10, 2 );
  100. break;
  101. case 18 :
  102. $year = substr ( $id, 6, 4 );
  103. $month = substr ( $id, 10, 2 );
  104. $day = substr ( $id, 12, 2 );
  105. break;
  106. }
  107. $birthday = array (
  108. 'year' => $year,
  109. 'month' => $month,
  110. 'day' => $day
  111. );
  112. return $birthday;
  113. }
  114. /**
  115. * 取得性别(由身份证号)--可能不准
  116. * @param int $id 身份证号
  117. * @return string
  118. */
  119. function getSex($id) {
  120. switch (strlen ( $id )) {
  121. case 15 :
  122. $sexCode = substr ( $id, 14, 1 );
  123. break;
  124. case 18 :
  125. $sexCode = substr ( $id, 16, 1 );
  126. break;
  127. }
  128. if ($sexCode % 2) {
  129. return "男";
  130. } else {
  131. return "女";
  132. }
  133. }
  134. /**
  135. * 格式化数据
  136. * @param string $type
  137. * @param srring $data
  138. * @return array
  139. */
  140. function formatData($type, $data) {
  141. switch ($type) {
  142. case "1A020201" :
  143. $detailInfo = $data ['policeCheckInfos']['policeCheckInfo'];
  144. $birthDay = $this->getBirthDay ( $detailInfo['identitycard'] );
  145. $sex = $this->getSex ( $detailInfo ['identitycard'] );
  146. $info = array (
  147. 'name' => $detailInfo ['name'],
  148. 'identitycard' => $detailInfo ['identitycard'],
  149. 'sex' => $sex,
  150. 'compStatus' => $detailInfo ['compStatus'],
  151. 'compResult' => $detailInfo ['compResult'],
  152. 'policeadd' => $detailInfo ['policeadd'],
  153. //'checkPhoto' => $detailInfo ['checkPhoto'],
  154. 'birthDay' => $birthDay,
  155. 'idcOriCt2' => $detailInfo ['idcOriCt2'],
  156. 'resultStatus' => $detailInfo ['compStatus']
  157. );
  158. break;
  159. default :
  160. $info = array (false );
  161. break;
  162. }
  163. return $info;
  164. }
  165. }