✏️ 正在编辑: ConfirmeOnline.php
路径:
/srv/systems_dir/yuppiecred/library/Core/Service/ConfirmeOnline.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php /** * Classe responsável pela integração com o sistema da InTouch */ class Core_Service_ConfirmeOnline { private $_usuario = null; private $_senha = null; private $_sigla = null; private $_ativo = false; private $_url = 'http://consulta.confirmeonline.com.br/Integracao/Consulta?wsdl'; function __construct(array $options = array()) { if (!$options) { $config = new Zend_Config_Ini( CLIENT_PATH . '/configs/application.ini', APPLICATION_ENV); if( !empty($config->confirme) && !empty($config->confirme->usuario) ){ $options = $config->confirme->toArray(); } } if( $options ){ $this->setOptions($options); } } public function setOptions(array $options) { $this->_usuario = $options['usuario']; $this->_senha = $options['senha']; $this->_sigla = $options['sigla']; if( !empty($this->_usuario) && !empty($this->_senha) && !empty($this->_sigla) ){ $this->_ativo = true; } return $this; } function getAtivo() { return $this->_ativo; } function setAtivo($ativo) { $this->_ativo = $ativo; } protected function getUrl() { return $this->_url; } protected function getClient() { ini_set('default_socket_timeout', 600); $context = stream_context_create(array( 'http'=>array( 'user_agent' => 'PHP/SOAP', 'protocol_version' => 1.0, ) )); $client = new SoapClient($this->getUrl(), array( 'trace' => true, 'soap_version' => SOAP_1_1, 'connection_timeout' => 500000, 'cache_wsdl' => WSDL_CACHE_BOTH, 'keep_alive' => true, 'stream_context' => $context, 'exception' => true, )); return $client; } public function getDadosPorCpf($cpf) { //verifica se os dados do confirme online estão setados if ($this->_usuario == null || $this->_senha == null || $this->_sigla == null){ return null; } $cpf = $this->formatarCpf($cpf); $validate = new Validators_Cpf(); if( !$validate->isValid($cpf) ){ throw new Core_Exception('O CPF informado não é válido'); } try{ $client = $this->getClient(); $result = $client->cpfcnpj( $this->_usuario, $this->_senha, $this->_sigla, $cpf ); } catch ( Exception $ex) { throw new Core_Exception("Falha de conexão com o ConfirmeOnline: {$ex->getMessage()}"); } return $this->extract($result); } protected function extract($xml) { $xmlData = new SimpleXMLElement($xml); $dados = array(); if (count($xmlData->MSG) > 0) return null; if (count($xmlData->REGISTRO) > 0) { foreach($xmlData->REGISTRO as $registro) { $dados['cpf'] = (string)current($registro->CPFCNPJ); $dados['nome'] = (string)current($registro->NOME); $dados['sexo'] = (string)current($registro->SEXO); $dados['mae'] = (string)current($registro->MAE); $dados['datanasc'] = ''; $dados['procon'] = (string)current($registro->PROCON); $dtNascimento = (string)$registro->NASC; if (!empty($dtNascimento) && Zend_Date::isDate($dtNascimento, 'yyyy-MM-dd')) { $date = new Zend_Date(current($registro->NASC), 'yyyy-MM-dd'); $dados['datanasc'] = $date->get('dd/MM/yyyy'); } if (!isset($dados['enderecos'])) { $dados['enderecos'] = []; $dados['telefones'] = []; $dados['emails'] = []; } $endereco = [ 'logradouro' => (string)current($registro->ENDERECO), 'numero' => (string)current($registro->NUMERO), 'complemento' => (string)current($registro->COMPLEMENTO), 'bairro' => (string)current($registro->BAIRRO), 'cep' => (string)current($registro->CEP), 'cidade' => (string)current($registro->CIDADE), 'uf' => (string)current($registro->UF) ]; if (!in_array($endereco, $dados['enderecos'])) { $dados['enderecos'][] = $endereco; } if (current($registro->TELEFONE) && current($registro->TELEFONE) != 'NULL' && !in_array(current($registro->TELEFONE), $dados['telefones'])) { $ddd = (string)substr(current($registro->TELEFONE), 0, 2); $tel = (string)substr(current($registro->TELEFONE), 2); $whatsapp = (string)$registro->WHATSAPP; $dados['telefones'][] = [ "numero" => "($ddd) $tel", "whatsapp" => $whatsapp == "SIM" ? true : false ]; } if (current($registro->EMAILS) && current($registro->EMAILS) != 'NULL' && !in_array(current($registro->EMAILS), $dados['emails'])) { $dados['emails'][] = current($registro->EMAILS); } }; } $dados['origem'] = "Confirme Online"; return $dados; } public function getParentes() { //verifica se os dados do confirme online estão setados if ($this->_usuario == null || $this->_senha == null || $this->_sigla == null){ return null; } $cpf = $this->formatarCpf($cpf); $client = $this->getClient(); $response = $client->Parentes( $this->_usuario, $this->_senha, $this->_sigla, $cpf ); return $response; } protected function formatarCpf($value) { $value = str_replace(array('-', '.'), array('', ''), $value); while (strlen($value) < 11) { $value = '0' . $value; } return trim($value); } }
💾 保存文件
← 返回文件管理器