✏️ 正在编辑: Assert.php
路径:
/srv/systems_dir/yuppiecred-bkp/library/Core/Service/Assert.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Core_Service_Assert { private $_key; private $_ativo = false; private $_url = 'http://ws.consulta.plus/v3/contato/TELEFONIA_ASSERT/'; function __construct(array $options = array()) { if( !$options ){ $config = new Zend_Config_Ini( CLIENT_PATH . '/configs/application.ini', APPLICATION_ENV); if( !empty($config->consultaplus) && !empty($config->consultaplus->key) ){ $options = $config->consultaplus->toArray(); } } if( $options ){ $this->setOptions($options); } } public function setOptions(array $options) { $this->_key = $options['key']; if( !is_null($this->_key) ){ $this->_ativo = true; } return $this; } function getAtivo() { return $this->_ativo; } function setAtivo($ativo) { $this->_ativo = $ativo; } protected function getUrl() { return $this->_url; } protected function getKey() { return $this->_key; } /** * Retorna informações de um cliente * * @param string $cpf * @return array */ public function getDadosPorCpf($cpf) { if( empty($cpf) ) return; return $this->localizaPessoas(String_Refatorar::formatarCpf($cpf)); } protected function localizaPessoas($cpf) { $token = $this->getKey(); if( !$token ) return; $url = $this->getUrl() . "{$cpf}?apiKey={$token}"; $response = $this->getResponse($url); if(empty($response)){ return; } return $this->extractDados($response); } protected function extractDados($json) { $dados = array(); if( !empty($json) ){ $dados['cpf'] = $json->cadastrais->cpf; $dados['nome'] = $json->cadastrais->nome; $dados['sexo'] = $json->cadastrais->sexo; if( Zend_Date::isDate($json->cadastrais->nascimento, 'yyyy-MM-dd') ){ $dt = new Zend_Date($json->cadastrais->nascimento); $dados['datanasc'] = $dt->get('dd/MM/yyyy'); } $dados['enderecos'] = array(); $dados['telefones'] = array(); $dados['emails'] = array(); $dados['origem'] = "Assert"; $telefones = isset($json->telefones) ? $json->telefones : array(); foreach ($telefones as $registro){ $dados['telefones'][] = $registro->ddd . $registro->telefone; } $emails = isset($json->emails) ? $json->emails : array(); foreach ( $emails as $registro ) { $dados['emails'][] = $registro->email; } $enderecos = isset($json->enderecos) ? $json->enderecos : array(); foreach ( $enderecos as $registro ) { $dados['enderecos'][] = array( 'logradouro' => $registro->logradouro, 'numero' => $registro->numero, 'complemento' => $registro->complemento, 'bairro' => $registro->bairro, 'cep' => $registro->cep, 'cidade' => $registro->cidade, 'uf' => $registro->uf ); } } return $dados; } public function getResponse($url) { $headers = array( 'User-Agent: ' . Zend_Http_UserAgent::DEFAULT_HTTP_USER_AGENT, ); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_HTTPHEADER => $headers, CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $url, CURLOPT_POST => false, CURLOPT_ENCODING => "UTF-8" ) ); $json = json_decode(curl_exec($curl)); curl_close($curl); return $json; } }
💾 保存文件
← 返回文件管理器