✏️ 正在编辑: InTouch.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/library/Core/Service/InTouch.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php /** * Classe responsável pela integração com o sistema da InTouch */ class Core_Service_InTouch extends Core_Service_ConsultaConsignado { private $_usuario = null; private $_senha = null; private $_cliente = null; private $_ativo = false; private $_url = 'http://wsi2.unitfour.com.br/intouchws.asmx?WSDL'; function __construct(array $options = array()) { if (!$options) { $config = new Zend_Config_Ini( CLIENT_PATH . '/configs/application.ini', APPLICATION_ENV); if( !empty($config->intouch) && !empty($config->intouch->usuario) ){ $options = $config->intouch->toArray(); } } if( $options ){ $this->setOptions($options); } } public function setOptions(array $options) { $this->_usuario = $options['usuario']; $this->_senha = $options['senha']; $this->_cliente = $options['cliente']; if( !empty($this->_usuario) && !empty($this->_senha) && !empty($this->_cliente) ){ $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( 'timeout' => 500000 ) ) ); $client = new SoapClient($this->getUrl(), array( 'trace' => true, 'connection_timeout' => 500000, 'cache_wsdl' => WSDL_CACHE_BOTH, 'keep_alive' => true, )); return $client; } protected function getToken() { $namespace = new Zend_Session_Namespace('InTouch'); $namespace->token = null; if (!$namespace->token) { if ($this->_usuario == null || $this->_senha == null || $this->_cliente == null) { return; } $params = new stdClass(); $params->usuario = $this->_usuario; $params->senha = $this->_senha; $params->cliente = $this->_cliente; $client = $this->getClient(); $token = $client->GerarToken($params); if (strstr($token->GerarTokenResult, 'Cliente, usuário e/ou senha inválido(s).')) { // $namespace->token = null; return; } $namespace->token = $token->GerarTokenResult; } return isset($namespace->token) ? $namespace->token : null; } protected function localizaPessoas($cpf) { $token = $this->getToken(); if (!$token) return; $params = new stdClass(); $params->documento = $cpf; $params->token = $token; $client = $this->getClient(); $result = $client->LocalizaPessoasTk($params); if (strstr($result->LocalizaPessoasTkResult, '<ERRO>')) { throw new Core_Exception( 'InTouch: ' . strip_tags($result->LocalizaPessoasTkResult) ); } return $this->extractDados($result->LocalizaPessoasTkResult); } protected function localizaDadosConsignado($valorPesquisa, $pesquisaPor) { if (!$this->_verificaPermissoes()) { $msgErro = 'Você não possui créditos para realizar consultas.'; throw new Core_Exception($msgErro); } $token = $this->getToken(); if (!$token) return; $params = new stdClass(); $params->valorPesquisa = $valorPesquisa; $params->pesquisaPor = $pesquisaPor; $params->token = $token; $client = $this->getClient(); $result = $client->LocalizarConsignado2TK($params); if (strstr($result->LocalizarConsignado2TkResult, '<ERRO>')) { throw new Core_Exception( 'InTouch: ' . strip_tags($result->LocalizarConsignado2TkResult) ); } return $result->LocalizarConsignado2TkResult; } public function getSiape($matricula, $cpf){ throw new Core_Exception("Não é possivel realizar consulta de Siape pelo InTouch."); } /** * Retorna informações de um cliente * * @param string $cpf * @return array */ public function getDadosPorCpf($cpf) { if (!$cpf) return; $cpf = $this->formatarCpf($cpf); return $this->localizaPessoas($cpf); } /* public function getDadosPorCpf($cpf) { $result = '<?xml version="1.0" encoding="ISO-8859-1" ?> <CONSULTA_PF> <CADASTROUNIT> <DOCUMENTO>01011370441</DOCUMENTO> <NOME>JAIME DA COSTA PEREIRA NETO</NOME> <ID_UNIT>278701145</ID_UNIT> </CADASTROUNIT> <DADOS_CADASTRAIS> <CPF>01011370441</CPF> <NOME>JAIME DA COSTA PEREIRA NETO</NOME> <NOME_ULTIMO>PEREIRA</NOME_ULTIMO> <SEXO>M</SEXO> <NOME_MAE>TEREZA NEUMAN CANDIDO PEREIRA</NOME_MAE> <DATANASC>18/11/1980</DATANASC> <IDADE>33</IDADE> <SIGNO>ESCORPIÃO</SIGNO> <SITUACAO_RECEITA>REGULAR</SITUACAO_RECEITA> </DADOS_CADASTRAIS> <TELEFONES> <RANKING>0</RANKING> <TELEFONE>(83) 33371771</TELEFONE> </TELEFONES> <TELEFONES> <RANKING>2</RANKING> <TELEFONE>(83) 32270783</TELEFONE> </TELEFONES> <TELEFONES> <RANKING>2</RANKING> <TELEFONE>(83) 88449499</TELEFONE> </TELEFONES> <TELEFONES> <RANKING>2</RANKING> <TELEFONE>(83) 87329229</TELEFONE> </TELEFONES> <ENDERECOS> <RANKING>1</RANKING> <LOGRADOURO>AV CAIRU 369 AP 402 ED IMPERIAL PRAIA</LOGRADOURO> <NUMERO>369</NUMERO> <COMPLEMENTO>AP 402 ED IMPERIAL PRAIA</COMPLEMENTO> <BAIRRO>BRANCO</BAIRRO> <CEP>58045100</CEP> <CIDADE>JOAO PESSOA</CIDADE> <UF>PB</UF> </ENDERECOS> <ENDERECOS> <RANKING>2</RANKING> <LOGRADOURO>R ELISIO JORGE BRITO 148 201</LOGRADOURO> <NUMERO>148</NUMERO> <COMPLEMENTO>201</COMPLEMENTO> <BAIRRO>JD OCEANIA</BAIRRO> <CEP>58037685</CEP> <CIDADE>JOAO PESSOA</CIDADE> <UF>PB</UF> </ENDERECOS> <ENDERECOS> <RANKING>3</RANKING> <LOGRADOURO>AV ENG JOSE CELINO FILHO 245 AP 503 A</LOGRADOURO> <NUMERO>245</NUMERO> <COMPLEMENTO>AP 503 A</COMPLEMENTO> <BAIRRO>MIRANTE</BAIRRO> <CEP>58407664</CEP> <CIDADE>CAMPINA GRANDE</CIDADE> <UF>PB</UF> </ENDERECOS> <EMAILS> <RANKING>0</RANKING> <EMAIL>JAIMECPN@GMAIL.COM</EMAIL> <PARTICULAR>SIM</PARTICULAR> </EMAILS> <PARTICIPACAO_EMPRESA> <NOME /> <ID_UNIT /> <DOCUMENTO /> <PCT_PARTICIPACAO /> <DATA_ENTRADA /> </PARTICIPACAO_EMPRESA> </CONSULTA_PF>'; return $this->extract($result); } * */ protected function extractDados($xml) { $xmlData = new SimpleXMLElement($xml); $dados = array(); if (count($xmlData) > 0) { $dados['cpf'] = current($xmlData->DADOS_CADASTRAIS->CPF); $dados['nome'] = current($xmlData->DADOS_CADASTRAIS->NOME); $dados['sexo'] = current($xmlData->DADOS_CADASTRAIS->SEXO); $dados['mae'] = current($xmlData->DADOS_CADASTRAIS->NOME_MAE); $dados['datanasc'] = current($xmlData->DADOS_CADASTRAIS->DATANASC); $dados['enderecos'] = array(); $dados['telefones'] = array(); $dados['emails'] = array(); foreach ($xmlData->TELEFONES as $registro) { $dados['telefones'][] = [ "numero" => current($registro->TELEFONE), "whatsapp" => !empty(current($registro->WHATSAPP)) ? true : false ]; } foreach ($xmlData->EMAILS as $registro) { $dados['emails'][] = current($registro->EMAIL); } foreach ($xmlData->ENDERECOS as $registro) { $dados['enderecos'][] = array( 'logradouro' => current($registro->LOGRADOURO), 'numero' => current($registro->NUMERO), 'complemento' => current($registro->COMPLEMENTO), 'bairro' => current($registro->BAIRRO), 'cep' => current($registro->CEP), 'cidade' => current($registro->CIDADE), 'uf' => current($registro->UF) ); } } return $dados; } /** * Retorna um array com informações do cliente e do(s) empréstimo(s) * * @param string $cpf * @return array */ public function getConsignadoPorCpf($cpf) { if (!$cpf) return; $cpf = $this->formatarCpf($cpf); $xml = $this->localizaDadosConsignado($cpf, 'CPF'); //armazena a consulta na sessão para não consultar novamente no webservice $ns = new Zend_Session_Namespace('consulta_intouch'); $ns->unsetAll(); $ns->consulta_intouch = $xml; $xmlData = new SimpleXMLElement($xml); $result = array(); if (count($xmlData) > 0) { foreach($xmlData->DADOS_PRINCIPAIS as $registro) { $result[] = array( 'beneficio' => current($registro->Beneficio), 'nome' => current($registro->Nome), 'data_nascimento' => current($registro->Nascimento), 'especie' => current($registro->Tipo), 'cidade' => null, 'uf' => null, ); } } return $result; } /** * Retorna um array com informações do cliente e do(s) empréstimo(s) * * @param int $nBeneficio * @return array */ public function getConsignadoPorBeneficio($nBeneficio) { $ns = new Zend_Session_Namespace('consulta_intouch'); if( $ns->consulta_intouch != null){ $xml = $ns->consulta_intouch; }else{ $xml = $this->localizaDadosConsignado($nBeneficio, 'NB'); } $ns->unsetAll(); return $this->extractConsignado($xml, $nBeneficio); } protected function extractConsignado($xml, $nBeneficio) { $xmlData = new SimpleXMLElement($xml); $dados = array(); if (count($xmlData) > 0) { foreach ($xmlData->DADOS_PRINCIPAIS as $registro){ if( $registro->Beneficio == $nBeneficio ){ $dadosPrincipais = $registro; break; } } $datanasc = ''; if (current($dadosPrincipais->Nascimento)) { $nasc = new Zend_Date(substr(current($dadosPrincipais->Nascimento), 0, 10), 'yyyy-MM-dd'); $datanasc = $nasc->get('dd/MM/yyyy'); } $dados = array( 'beneficio' => current($dadosPrincipais->Beneficio), 'nascto' => $datanasc, 'nome' => current($dadosPrincipais->Nome), 'banco_pagto' => current($dadosPrincipais->CodigoBanco), 'agencia_pagto' => current($dadosPrincipais->CodigoAgencia), 'nome_ag_pagto' => current($dadosPrincipais->Agencia), 'tipo_pagto' => current($dadosPrincipais->MeioPagamento), 'orgao_pagador' => current($dadosPrincipais->IdOrgaoPagador), 'cpf' => current($dadosPrincipais->Cpf), 'margem' => current($dadosPrincipais->ValorMargem), 'margem_cartao' => null, 'margem_cartao_rmc' => null, 'matricula' => null, 'tipo' => current($dadosPrincipais->Tipo), 'especie' => current($dadosPrincipais->Tipo), 'especie_descricao' => utf8_decode(current($dadosPrincipais->Descricao)), 'mr' => current($dadosPrincipais->ValorBeneficio), 'conta_pagto' => '', 'endereco' => '', 'bairro' => '', 'cidade' => '', 'uf' => '', 'cep' => '', 'dib' => '', 'representante_legal' => '', // campos específicos do InTouch 'oml' => current($dadosPrincipais->Oml), 'estado_oml' => current($dadosPrincipais->EstadoOml), 'nit' => current($dadosPrincipais->NIT), 'sexo' => current($dadosPrincipais->Sexo), 'tipo' => current($dadosPrincipais->Tipo), 'descricao' => current($dadosPrincipais->Descricao), 'situacao' => current($dadosPrincipais->Situacao), 'banco_nome' => current($dadosPrincipais->NomeBanco), 'inclusao' => current($dadosPrincipais->Inclusao), 'competencia' => current($dadosPrincipais->Competencia), 'valor_creditos' => current($dadosPrincipais->ValorCreditos), 'descontos' => current($dadosPrincipais->ValorDebitos), 'valor_consignado' => current($dadosPrincipais->ValorConsignado), 'qtd_consignados' => current($dadosPrincipais->QtdConsignados), 'cartao_rmc' => current($dadosPrincipais->CartaoRMC), 'consignavel' => current($dadosPrincipais->Consignavel), 'itens' => array( 'telefones' => array( // array('telefone'=>'', 'status'=>'', 'origem'=>''), ), 'emprestimos' => array(), 'enderecos' => array(), ), 'detalhamento' => current($dadosPrincipais->INSS_HTML_DETALHAMENTO), 'origem' => 'InTouch', ); foreach($xmlData->CREDITOS as $credito) { if (current($credito->Codigo) == '101' && $credito->Beneficio == $nBeneficio) { $dados['mr'] = current($credito->Valor); } } $totalParcelas = 0; $totalCartao = 0; foreach($xmlData->DEBITOS as $debito) { if( $debito->Beneficio == $nBeneficio ){ $inicioContrato = new Zend_Date(substr(current($debito->InicioContrato), 0, 10), 'yyyy-MM-dd'); $fimContrato = new Zend_Date(substr(current($debito->FimContrato), 0, 10), 'yyyy-MM-dd'); $valorParcela = current($debito->Valor); $dados['itens']['emprestimos'][] = array( 'banco' => current($debito->IdBanco), 'valor_parcela' => $valorParcela, 'quitacao' => current($debito->ValorQuitacao), 'prazo' => current($debito->Prazo), 'mes' => $inicioContrato->get('MM'), 'ano' => $inicioContrato->get('yyyy'), 'mr' => $dados['mr'], 'qtypagas' => current($debito->QtdParcPagas), 'contrato' => current($debito->NumeroContrato), 'inicio_contrato' => $inicioContrato->get('dd/MM/yyyy'), 'fim_contrato' => $fimContrato->get('dd/MM/yyyy'), 'vlremprestimo' => current($debito->ValorContrato), 'nome_banco' => current($debito->Nome), 'tipo' => "EMPRESTIMO", // campos específicos do InTouch 'cod_compensacao' => current($debito->CodCompensacao), 'nome_banco_abrv' => current($debito->NomeAbreviado), ); $totalParcelas += $valorParcela; } } $dados['total_consignado'] = $totalParcelas; $dados['total_cartao'] = $totalCartao; $dados['complemento_acompanhamento'] = 0; $dados['imposto_renda_retido'] = 0; $dados['contribuicao_contag'] = 0; $dados['orgao_consulta'] = 'INSS'; } return $dados; } protected function formatarCpf($value) { $value = str_replace(array('-', '.'), array('', ''), $value); while (strlen($value) < 11) { $value = '0' . $value; } return trim($value); } }
💾 保存文件
← 返回文件管理器