123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- namespace app\service\id;
- use app\service\id\config\DES;
- use traits\think\Instance;
- /**
- * @desc 综合业务平台--查询 API
- * @author harvey
- * @since 2010-11-20
- *
- */
- class IdVerify {
- use Instance;
- /**
- * 取得数据
- * @param string $type 查询类型
- * @param string $param 查询参数
- * @return \SimpleXMLElement
- */
- function getData( $param) {
- $wsdlURL = "http://jypt.id5.cn/gztboss/services/QueryValidatorServices?wsdl";
- $partner = config('site.verify_id_gzt_account');
- $partnerPW = config('site.verify_id_gzt_password');
- $Key = "12345678";
- $iv = "12345678";
- $typeData = "1A020201";
- //var_dump ( $soap->__getTypes () );
- //exit();
- $DES = new DES ( $Key, $iv );
- //@todo 加密数据
- $partner = $DES->encrypt ( $partner );
- //echo $partner;exit;
- $partnerPW = $DES->encrypt ( $partnerPW );
- $type = $DES->encrypt ( $typeData );
- //先将中文转码
- $param = mb_convert_encoding ( $param, "GBK", "UTF-8" );
- $param = $DES->encrypt ( $param );
- $params = array (
- "userName_" => $partner,
- "password_" =>$partnerPW,
- "type_" => $type,
- "param_" => $param
- );
- ini_set('default_socket_timeout',3);
- $soap = new \SoapClient ( $wsdlURL );
- //请求查询
- //queryBatch
- $data = $soap->querySingle ( $params );
- //@todo 解密数据 //queryBatchReturn
- $resultXML = $DES->decrypt ( $data->querySingleReturn );
- $resultXML = mb_convert_encoding ( $resultXML, "UTF-8", "GBK" );
- $resultObj=simplexml_load_string($resultXML);
- return $resultObj;
- }
- public function check($name,$id){
- try {
- $result=$this->getData(sprintf('%s,%s,%s',$name,$id,session_create_id()));
- }catch (\Exception $e){
- throw_user("请求验证身份失败");
- }
- if(empty($result)){
- throw_user('请求失败(gzt)');
- }
- if($result->message->status>0){
- throw_user($result->message->value);
- }
- if($result->policeCheckInfos->policeCheckInfo->compStatus!=3){
- throw_user(sprintf('身份证号码有误(%s)',$result->policeCheckInfos->policeCheckInfo->compResult));
- }
- }
- /**
- * 格式化参数
- * @param array $params 参数数组
- * @return string
- */
- function formatParam($queryType, $params) {
- $supportClass = array ("1A020201" => "Name,CardNum" );
- if (empty ( $supportClass[$queryType] )) {
- return - 1;
- }
- $keys = array ();
- $values = array ();
- foreach ( $params as $key => $value ) {
- $keys [] = $key;
- $values [] = strtoupper ( $value );
- }
- $param = str_replace ( $keys, $values, $supportClass[$queryType] );
- return $param;
- }
- /**
- * 取得生日(由身份证号)
- * @param int $id 身份证号
- * @return string
- */
- function getBirthDay($id) {
- switch (strlen ( $id )) {
- case 15 :
- $year = "19" . substr ( $id, 6, 2 );
- $month = substr ( $id, 8, 2 );
- $day = substr ( $id, 10, 2 );
- break;
- case 18 :
- $year = substr ( $id, 6, 4 );
- $month = substr ( $id, 10, 2 );
- $day = substr ( $id, 12, 2 );
- break;
- }
- $birthday = array (
- 'year' => $year,
- 'month' => $month,
- 'day' => $day
- );
- return $birthday;
- }
- /**
- * 取得性别(由身份证号)--可能不准
- * @param int $id 身份证号
- * @return string
- */
- function getSex($id) {
- switch (strlen ( $id )) {
- case 15 :
- $sexCode = substr ( $id, 14, 1 );
- break;
- case 18 :
- $sexCode = substr ( $id, 16, 1 );
- break;
- }
- if ($sexCode % 2) {
- return "男";
- } else {
- return "女";
- }
- }
- /**
- * 格式化数据
- * @param string $type
- * @param srring $data
- * @return array
- */
- function formatData($type, $data) {
- switch ($type) {
- case "1A020201" :
- $detailInfo = $data ['policeCheckInfos']['policeCheckInfo'];
- $birthDay = $this->getBirthDay ( $detailInfo['identitycard'] );
- $sex = $this->getSex ( $detailInfo ['identitycard'] );
- $info = array (
- 'name' => $detailInfo ['name'],
- 'identitycard' => $detailInfo ['identitycard'],
- 'sex' => $sex,
- 'compStatus' => $detailInfo ['compStatus'],
- 'compResult' => $detailInfo ['compResult'],
- 'policeadd' => $detailInfo ['policeadd'],
- //'checkPhoto' => $detailInfo ['checkPhoto'],
- 'birthDay' => $birthDay,
- 'idcOriCt2' => $detailInfo ['idcOriCt2'],
- 'resultStatus' => $detailInfo ['compStatus']
- );
- break;
- default :
- $info = array (false );
- break;
- }
- return $info;
- }
- }
|