✏️ 正在编辑: Viper.php
路径:
/srv/systems_dir/yuppiecred/library/Core/Service/Viper.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Core_Service_Viper extends Core_Service_ConsultaConsignado { private $_usuario = null; private $_url = 'http://app.viperconsig.com.br/WSInsscpf/wsdl'; function __construct(array $options = null) { if( !$this->_verificaPermissoes() ){ $msgErro = 'Você não possui créditos para realizar consultas.'; throw new Core_Exception($msgErro); } if( !$options ){ $config = new Zend_Config_Ini( CLIENT_PATH . '/configs/application.ini', APPLICATION_ENV); if($config->viper){ $options = $config->viper->toArray(); } else { $msgErro = 'Viper não está configurado.'; throw new Core_Exception($msgErro); } } $this->setOptions($options); } public function setOptions(array $options) { $this->_usuario = $options['login']; return $this; } 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 extractDados($xml) { $xmlData = $this->_isValidXml($xml); $dados = array(); if( count($xmlData) > 0 ){ $informacoesBeneficio = $xmlData->CONSULTA->INFORMACOES_BENEFICIO; $dados['situacao'] = current($informacoesBeneficio->SITUACAO_BENEFICIO); $dados['cpf'] = current($informacoesBeneficio->CPF); $dados['matricula'] = null; $dados['beneficio'] = current($xmlData->CONSULTA->BENEFICIO); $dados['nome'] = current($informacoesBeneficio->NOME); $dados['mae'] = ""; if(!empty($informacoesBeneficio->DATA_NASCIMENTO)){ $dtnasc = new Zend_Date(current($informacoesBeneficio->DATA_NASCIMENTO), 'yyyy/MM/dd'); $dados['nascto'] = $dtnasc->get("dd/MM/yyyy"); }else{ $dados['nascto'] = false; } $dados['banco_pagto'] = current($informacoesBeneficio->BANCO); $dados['agencia_pagto'] = current($informacoesBeneficio->CODIGO_AGENCIA); $dados['conta_pagto'] = current($informacoesBeneficio->CONTA_CORRENTE); $dados['orgao_pagador'] = current($informacoesBeneficio->ORGAO_PAGADOR); $dados['tipo_pagto'] = current($informacoesBeneficio->MEIO_PAGAMENTO); $dados['itens']['enderecos'][] = array( 'logradouro' => current($informacoesBeneficio->ENDERECO), 'numero' => '', 'complemento' => '', 'bairro' => current($informacoesBeneficio->BAIRRO), 'cep' => current($informacoesBeneficio->CEP), 'cidade' => current($informacoesBeneficio->CIDADE), 'uf' => current($informacoesBeneficio->ESTADO) ); $detalhamento = $xmlData->CONSULTA->DETALHAMENTO; $dados['mr'] = str_replace(array( '.', ',' ), array( '', '.' ), current($detalhamento->MENSALIDADE_REAJUSTADA)); $dados['especie'] = current($informacoesBeneficio->ESPECIE); $dados['especie_descricao'] = current($informacoesBeneficio->ESPECIE_DESCRICAO); $dados['tipo'] = current($informacoesBeneficio->ESPECIE); $dados['competencia'] = current($detalhamento->COMPETENCIA); $filterDigits = new Zend_Filter_Digits(); $dados['itens']['telefones'] = array(); $telefones = $filterDigits->filter(current($informacoesBeneficio->TELEFONE)); if( $telefones ){ array_push($dados['itens']['telefones'], $telefones); } $dados['rg'] = current($informacoesBeneficio->RG); $dados['nit'] = current($informacoesBeneficio->NIT); $dados['emails'] = array(); $dados['itens']['emprestimos'] = array(); $consignacoes = $xmlData->CONSULTA->CONSIGNACOES; $totalParcelas = 0; foreach ( $consignacoes->EMPRESTIMO_BANCARIO as $registro ) { $valorParcela = str_replace(['.', ','], ['', '.'], current($registro->VALOR_PARCELA)); $valorEmprestimo = str_replace(['.', ','], ['', '.'], current($registro->VALOR_EMPRESTIMO)); $dados['itens']['emprestimos'][] = array( 'situacao' => current($registro->SITUACAO), 'tipo' => 'EMPRESTIMO', 'banco' => current($registro->CODIGO_BANCO), 'contrato' => current($registro->CONTRATO), 'vlremprestimo' => $valorEmprestimo, 'inicio_contrato' => current($registro->DATA_INICIO), 'fim_contrato' => current($registro->DATA_TERMINO), 'prazo' => current($registro->PARCELAS), 'qtypagas' => ($registro->PARCELAS - $registro->PARCELAS_ABERTO), 'valor_parcela' => $valorParcela, 'quitacao' => str_replace(['.', ','], ['', '.'], current($registro->SALDO_APROXIMADO)), 'taxa' => $this->calcularTaxaJuros( $valorEmprestimo, $valorParcela, current($registro->PARCELAS) ), ); $totalParcelas += $valorParcela; } if( isset($consignacoes->EMPRESTIMO_OCULTO) ){ foreach ( $consignacoes->EMPRESTIMO_OCULTO as $registro ) { $valorParcela = str_replace(array( '.', ',' ), array( '', '.' ), current($registro->VALOR_PARCELA)); $dados['itens']['emprestimos_ocultos'][] = array( 'situacao' => current($registro->SITUACAO), 'tipo' => 'EMPRESTIMO OCULTO', 'banco' => current($registro->CODIGO_BANCO), 'contrato' => current($registro->CONTRATO), 'vlremprestimo' => str_replace(array( '.', ',' ), array( '', '.' ), current($registro->VALOR_EMPRESTIMO)), 'inicio_contrato' => current($registro->DATA_INICIO), 'fim_contrato' => current($registro->DATA_TERMINO), 'prazo' => current($registro->PARCELAS), 'qtypagas' => ($registro->PARCELAS - $registro->PARCELAS_ABERTO), 'valor_parcela' => str_replace(array( '.', ',' ), array( '', '.' ), current($registro->VALOR_PARCELA)), 'quitacao' => str_replace(array( '.', ',' ), array( '', '.' ), current($registro->SALDO_APROXIMADO)), ); $totalParcelas += $valorParcela; } } $totalCartao = 0; if( isset($consignacoes->RESERVA_CARTAO) ){ foreach ( $consignacoes->RESERVA_CARTAO as $registro ) { $valorReservado = str_replace(array( '.', ',' ), array( '', '.' ), $registro->VALOR_RESERVADO); $dados['itens']['reserva_cartao'][] = array( 'situacao' => $registro->SITUACAO, 'tipo' => 'RESERVA CARTAO', 'banco' => $registro->CODIGO_BANCO, 'contrato' => $registro->CONTRATO, 'nome_banco' => $registro->NOME_BANCO, 'limite_cartao' => str_replace(array( '.', ',' ), array( '', '.' ), $registro->LIMITE_CARTAO), 'data_inclusao' => $registro->DATA_INCLUSAO, 'valor_reservado' => $valorReservado, ); $totalCartao += $valorReservado; } } $dados['margem'] = str_replace(array( '.', ',' ), array( '', '.' ), current($detalhamento->VALOR_MARGEM_EMPRESTIMO)); $dados['margem_cartao'] = str_replace(array( '.', ',' ), array( '', '.' ), current($detalhamento->VALOR_MARGEM_CARTAO)); $dados['margem_cartao_rmc'] = str_replace(array( '.', ',' ), array( '', '.' ), current($detalhamento->VALOR_CARTAO_RMC)); $dados['complemento_acompanhamento'] = isset($detalhamento->COMPL_ACOMPAN) ? abs(str_replace(array( '.', ',' ), array( '', '.' ), current($detalhamento->COMPL_ACOMPAN))) : 0; $dados['descontos'] = isset($detalhamento->CONTR_SINDNAPI) ? abs(str_replace(array( '.', ',' ), array( '', '.' ), current($detalhamento->CONTR_SINDNAPI))) : 0; $dados['imposto_renda_retido'] = isset($detalhamento->I_R_RET_FONTE) ? abs(str_replace(array( '.', ',' ), array( '', '.' ), $detalhamento->I_R_RET_FONTE)) : 0; $dados['contribuicao_contag'] = isset($detalhamento->CONTRIB_CONTAG) ? abs(str_replace(array( '.', ',' ), array( '', '.' ), $detalhamento->CONTRIB_CONTAG)) : 0; try{ $dados['detalhamento'] = base64_decode($this->getDetalhamentoDataprev($xmlData->CONSULTA->BENEFICIO)); } catch (Exception $e){ $dados['detalhamento'] = $e->getMessage(); } $dados['margem_rmc'] = 0; $dados['total_consignado'] = $totalParcelas; $dados['total_cartao'] = $totalCartao; $dados['origem'] = 'Viper'; $dados['orgao_consulta'] = 'INSS'; } 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; $this->setCpf($this->formatarCpf($cpf)); $client = $this->getClient(); try{ $xml = $client->ConsultaCpf($this->getCpf(), $this->_usuario); } catch (Exception $e){ return; } $dataRead = str_replace('NULL', "", $xml); $result = $this->extractBeneficios($dataRead); return $result; } /** * @todo Ajustar para o layout do retorno do método ConsultaCpf do WS * @param string $xml * @return array */ protected function extractBeneficios($xml) { $xmlData = $this->_isValidXml($xml); $dados = array(); if( count($xmlData) > 0 ){ $dados = array(); if( $xmlData->CONSULTA->OK == "SIM" ){ foreach ( $xmlData->CONSULTA->CONSULTA_CPF->RESULTADO as $registro ) { $dados[] = array( 'cpf' => $this->getCpf(), 'beneficio' => current($registro->BENEFICIO), 'nome' => current($registro->NOME), 'data_nascimento' => current($registro->DATA_NASCIMENTO), 'especie' => current($registro->ESPECIE), 'cidade' => current($registro->MUNICIPIO), 'uf' => current($registro->UF), ); } } elseif( isset($xmlData->MSG) ){ throw new Core_Exception("VIPER: " . $xmlData->MSG); } else { throw new Core_Exception("VIPER: " . $xmlData->CONSULTA->ERRO); } } return $dados; } /** * Retorna um array com informações do cliente e do(s) empréstimo(s) * * @param int $nBeneficio * @return array */ public function getConsignadoPorBeneficio($nBeneficio) { $this->_url = "http://app.viperconsig.com.br/WSInssbenef/wsdl"; $client = $this->getClient(); try{ $xml = $client->ConsultaBen($nBeneficio, $this->_usuario); }catch(SoapFault $e){ throw new Core_Exception("Falha de comunicação com o Viper. {$e->getMessage()}"); } $fileName = $nBeneficio . "-" . Zend_Date::now()->get('ddMMyyyy') . ".xml"; file_put_contents(CLIENT_PATH . "/data/" . $fileName, $xml); $xmlData = @simplexml_load_string($xml); $msg = current($xmlData->MSG); if( !empty($msg) ){ throw new Core_Exception("Viper: " . current($xmlData->MSG)); } $dataRead = str_replace('NULL', "", $xml); return $this->extractDados($dataRead); } public function getSiape($matricula, $cpf) { $this->_url = "http://app.viperconsig.com.br/WSSiape/wsdl"; $client = $this->getClient(); $xml = $client->Consulta($matricula, $cpf, $this->_usuario); return $this->extractSiape($xml); } protected function extractSiape($xml) { $xmlData = $this->_isValidXml($xml); if( count($xmlData) <= 0 ){ throw new Core_Exception("A consulta não retornou nenhuma informação."); } if( isset($xmlData->MSG) ){ throw new Core_Exception("VIPER: " . $xmlData->MSG); } $dados = array(); if( count($xmlData) > 0 ){ $informacoes = $xmlData->CLIENTE; $dados['beneficio'] = NULL; $dados['matricula'] = current($informacoes->MATRICULA); $dados['tipo'] = current($informacoes->MATRICULA); $dados['nome'] = current($informacoes->NOME); $dados['cpf'] = current($informacoes->CPF); $dtnasc = new Zend_Date(current($informacoes->DATANASCIMENTO), 'yyyy/MM/dd'); $dados['nascto'] = $dtnasc->get("dd/MM/yyyy"); $dados['itens']['enderecos'][] = array( 'logradouro' => current($informacoes->ENDERECO), 'numero' => '', 'complemento' => '', 'bairro' => current($informacoes->BAIRRO), 'cep' => current($informacoes->CEP), 'cidade' => current($informacoes->CIDADE), 'uf' => current($informacoes->ESTADO) ); $dados['itens']['telefones'][] = current($informacoes->TELEFONE); $dados['emails'] = current($informacoes->EMAIL); $dados['rg'] = current($informacoes->RG); $dados['orgao_pagador'] = current($informacoes->ORGAO) . " - " . current($informacoes->ORGAO_NOME); $dados['mae'] = current($informacoes->NOME_MAE); $dados['data_inicio_pensao'] = current($informacoes->DATA_INI_PENSAO); $dados['banco_pagto'] = current($informacoes->BANCO); $dados['agencia_pagto'] = current($informacoes->AGENCIA); $dados['conta_pagto'] = current($informacoes->CORRENTE); $dados['margem'] = str_replace(array( '.', ',' ), array( '', '.' ), current($informacoes->MARGEM)); $consignacoes = $informacoes->EMPRESTIMO; $dados['itens']['emprestimos'] = array(); foreach ( $consignacoes as $registro ) { $dados['itens']['emprestimos'][] = array( 'nome_banco' => current($registro->BANCO), 'tipo' => 'EMPRESTIMO', 'contrato' => current($registro->CONTRATO), 'prazo' => current($registro->PRAZO), 'valor_parcela' => str_replace(array( '.', ',' ), array( '', '.' ), current($registro->VLPARC)), 'quitacao' => str_replace(array( '.', ',' ), array( '', '.' ), current($registro->SALDO)), 'vlremprestimo' => 0, 'mes' => null, 'ano' => null, 'qtypagas' => null, ); } $dados['origem'] = 'Viper'; $dados['orgao_consulta'] = 'SIAPE'; $dados['mr'] = 0; $dados['margem_cartao'] = 0; $dados['margem_cartao_rmc'] = 0; $dados['competencia'] = NULL; $dados['situacao'] = NULL; $dados['especie'] = NULL; $dados['tipo_pagto'] = NULL; $dados['margem_rmc'] = 0; } return $dados; } public function getCartaConcessao($nBeneficio) { $this->_url = "http://app.viperconsig.com.br/WSInssCarta/wsdl"; $client = $this->getClient(); $xml = $client->Consultaben($nBeneficio, $this->_usuario); $xmlData = @simplexml_load_string($xml); $msg = current($xmlData->MSG); if( !empty($msg) ){ throw new Core_Exception("Viper: " . current($xmlData->MSG)); } return $this->extractDados($xml); } public function getSituacaoBeneficio($nBeneficio) { $this->_url = "http://app.viperconsig.com.br/WSInssConsit/wsdl"; $client = $this->getClient(); $xml = $client->Consultaben($nBeneficio, $this->_usuario); $xmlData = @simplexml_load_string($xml); if( isset($xmlData->CONSULTA->SITUACAO_BENEFICIO->MSG) ){ return "VIPER: " . implode(" ", (array) $xmlData->CONSULTA->SITUACAO_BENEFICIO->MSG); } else { return "Dados não retornados"; } } public function getDetalhamentoDataprev($nBeneficio) { $this->_url = "http://app.viperconsig.com.br/wSInssExtrato/wsdl"; $client = $this->getClient(); $xml = $client->ConsultaBen($nBeneficio, $this->_usuario); $xmlData = @simplexml_load_string($xml); $msg = current($xmlData->MSG); if( !empty($msg) ){ throw new Core_Exception("Viper: " . current($xmlData->MSG)); } return $this->extractDetalhamento($xml); } protected function extractDetalhamento($xml) { $xmlData = $this->_isValidXml($xml); if( count($xmlData) > 0 ){ if( $xmlData->CONSULTA->EXTRATO_PAGAMENTO && $xmlData->CONSULTA->EXTRATO_PAGAMENTO->TEXTO_DT ){ return $xmlData->CONSULTA->EXTRATO_PAGAMENTO->TEXTO_DT; } elseif( isset($xmlData->CONSULTA->EXTRATO_PAGAMENTO->MSG) ){ throw new Core_Exception("VIPER: " . $xmlData->CONSULTA->EXTRATO_PAGAMENTO->MSG); } else { throw new Core_Exception("VIPER: " . "Não foi possível puxar o detalhamento."); } } return "Detalhamento indisponível."; } }
💾 保存文件
← 返回文件管理器