✏️ 正在编辑: Catta.php
路径:
/srv/systems_dir/yuppiecred-bkp/library/Core/Service/Catta.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php /** * Classe responsável pela integração com o sistema da InTouch */ class Core_Service_Catta { private $_key = null; private $_ativo = false; private $_url = 'http://www.catta.com.br/api/v1/busca/cpf_cnpj?'; function __construct(array $options = array()) { if (!$options) { $config = new Zend_Config_Ini( CLIENT_PATH . '/configs/application.ini', APPLICATION_ENV); if( !empty($config->catta) && !empty($config->catta->key) ){ $options = $config->catta->toArray(); } } if( $options ){ $this->setOptions($options); } } public function setOptions(array $options) { $this->_key = $options['key']; if( !empty($this->_key) ){ $this->_ativo = true; } return $this; } function getAtivo() { return $this->_ativo; } function setAtivo($ativo) { $this->_ativo = $ativo; } protected function getUrl() { return $this->_url; } public function getDadosPorCpf($cpf) { //verifica se os dados do confirme online estão setados if ($this->_key == null){ return null; } $cpf = $this->formatarCpf($cpf); $params = array( 'key=' . $this->_key, "cpf_cnpj=" . $cpf ); $queryString = implode('&', $params); $url = $this->getUrl() . $queryString; $result = file_get_contents($url); if ($result == 'Chave de API invalida') { throw new Core_Exception($result); } return $this->extract($result); } protected function extract($xml) { try{ $xmlData = new SimpleXMLElement($xml); } catch (Exception $e){ throw new Core_Exception("Catta: " . $xml); } $dados = array( 'cpf' => '', 'nome' => '', 'sexo' => '', 'mae' => '', 'datanasc' => '', 'enderecos' => array(), 'emails' => array(), 'telefones' => array() ); // TODO Extração incompleta. Inserir outros dados no array. if (count($xmlData->telefoneList) > 0) { $dados['pessoa'] = $xmlData->pessoa; $dados['datanasc'] = $xmlData->nascimento; foreach ($xmlData->telefoneList->telefone as $telefone) { if (!$telefone->naoPerturbe) { $dados['telefones'][] = '(' . $telefone->ddd . ') ' . $telefone->telefone; } } } return $dados; } protected function formatarCpf($value) { $value = str_replace(array('-', '.'), array('', ''), $value); while (strlen($value) < 11) { $value = '0' . $value; } return trim($value); } }
💾 保存文件
← 返回文件管理器