✏️ 正在编辑: MultiBr.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/library/Core/Service/MultiBr.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php /** * Classe responsável pela integração com o sistema da MultiBR */ class Core_Service_MultiBr extends Core_Service_ConsultaConsignado { private $_username = null; private $_password = null; private $_key = null; private $_contentType = 'json'; private $_context = null; private $_uniqueKey = null; const CONTENT_TYPE_JSON = 'json'; const CONTENT_TYPE_XML = 'xml'; function __construct(array $options = null) { if( !$this->_verificaPermissoes() ){ $msgErro = 'Você não possui créditos para realizar consultas.'; throw new Core_Exception($msgErro); } $config = new Zend_Config_Ini( CLIENT_PATH . '/configs/application.ini', APPLICATION_ENV); $this->_username = $config->multibr->username; $this->_password = $config->multibr->password; $this->_uniqueKey = $config->multibr->key; $this->_context = stream_context_create(array( 'http' => array( 'header' => 'Authorization: Basic ' . base64_encode($this->_username . ':' . $this->_password) ) )); $url = 'http://68.183.227.240/sys/api/login' . '?username=' . $this->_username . '&password=' . $this->_password . '&contentType=' . $this->_contentType; $json = file_get_contents($url, false, $this->_context); $content = Zend_Json::decode($json); if( !isset($content['key']) ){ throw new Core_Exception($content['msg']); } $this->_key = $content['key']; } /** * Retorna um array com informações do cliente e do(s) empréstimo(s) * @param int $nBeneficio * @return array|null */ public function getConsignadoPorBeneficio($nBeneficio) { if( $nBeneficio ){ $json = file_get_contents('http://68.183.227.240/sys/api/b_pesq' . '?key=' . $this->_key . '&contentType=' . $this->_contentType . '&nb=' . $nBeneficio, false, $this->_context); Yuppie_Log::write("Retorno consulta b_pesq MultiBR => " . print_r($json, true), $this); if (empty($json)) { throw new Core_Exception("Nenhuma informação retornada"); } $array = json_decode($json, true); $dados = $array['dados_cadastrais'][0]; $totalParcelas = 0; $dados['matricula'] = null; $dados['situacao'] = null; $dtNascimento = new Zend_Date($dados['nascto'], 'yyyyMMdd'); $dados['nascto'] = $dtNascimento->get("dd/MM/yyyy"); $dados['dib'] = (new Zend_Date($dados['dib'], 'yyyyMMdd'))->get('dd/MM/yyyy'); $dados['itens']['telefones'] = isset($array['fone']) ? $array['fone'] : null; if( count($dados['itens']['telefones']) > 0 ){ $fones = array(); foreach ( $dados['itens']['telefones'] as $fone ) { $fones[] = $fone['telefone']; } $dados['itens']['telefones'] = $fones; } $dados['itens']['enderecos'][] = array( 'logradouro' => $dados['endereco'], 'numero' => '', 'complemento' => '', 'bairro' => $dados['bairro'], 'cep' => $dados['cep'], 'cidade' => $dados['cidade'], 'uf' => $dados['uf'] ); if( isset($array['consighome_vlfin']) ){ foreach ( $array['consighome_vlfin'] as $registro ) { $dataInicio = $dataFinal = ''; if( isset($registro['contrato_info']) ){ $dt = new Zend_Date($registro['contrato_info']['iniciorepasse']); $dataInicio = $dt->get('dd/MM/yyyy'); $dt2 = new Zend_Date($registro['contrato_info']['finalrepasse']); $dataFinal = $dt2->get('dd/MM/yyyy'); } $dados['itens']['emprestimos'][] = array( 'situacao' => '', 'tipo' => isset($registro[0]) ? $registro[0]['tipooperacao'] : null, 'banco' => $registro['banco'], 'contrato' => $registro['contrato'], 'vlremprestimo' => 0, 'inicio_contrato' => $dataInicio, 'fim_contrato' => $dataFinal, 'prazo' => $registro['prazo'], 'qtypagas' => $registro['qtypagas'], 'valor_parcela' => $registro['valor_parcela'], 'quitacao' => $registro['quitacao'], 'taxa' => $registro['taxajuros'], 'rco' => $registro['contrato_info']['rco'] ); $totalParcelas += $registro['valor_parcela']; } } if( isset($array['consighome']) ){ foreach ( $array['consighome'] as $registro ) { $dados['itens']['reserva_cartao'][] = array( 'situacao' => '', 'tipo' => "RESERVA CARTAO", 'banco' => $registro['banco_numero'], 'nome_banco' => '', 'contrato' => '', 'limite_cartao' => 0, 'data_inclusao' => '', 'valor_reservado' => 0, 'valor_parcela' => $registro['valor_parcela'], ); } } $dados['margem'] = $array['margem'][0]['margem'] ? $array['margem'][0]['margem'] : 0; $dados['margem_cartao'] = 0; $dados['margem_cartao_rmc'] = 0; $dados['complemento_acompanhamento'] = 0; $dados['descontos'] = 0; $dados['imposto_renda_retido'] = 0; $dados['contribuicao_contag'] = 0; $dados['total_consignado'] = $totalParcelas; $dados['origem'] = 'MultiBr'; $dados['orgao_consulta'] = 'INSS'; $dados['especie'] = $dados['esp']; $dados['especie_descricao'] = isset($array['adicionais']['especie_desc']) ? $array['adicionais']['especie_desc'] : null; $dados['rep_legal'] = trim($dados['representante_legal']) != "" ? "SIM" : "NÃO"; $dados['obito'] = ""; $dados['detallhamento'] = $this->getDetalhamentoCredito($dados['beneficio'], $dados['nascto'], $dados['nome'], $dados['cpf']); return $dados; } } public function getConsignadoPorCpf($cpf) { $cpf = String_Refatorar::formatarCpf($cpf); if( $cpf ){ $beneficios = file_get_contents( 'http://68.183.227.240/sys/api/b_cpf' . '?key=' . $this->_key . '&cpf=' . $cpf, false, $this->_context); $result = explode(';', trim($beneficios, ' ;')); $this->setCpf($cpf); $rest = array(); if( is_array($result) ){ foreach ( $result as $r ) { $rest[] = array( 'cpf' => $this->getCpf(), 'beneficio' => $r, 'nome' => null, 'data_nascimento' => null, 'especie' => null, 'cidade' => null, 'uf' => null, ); } } else { $rest = array( 0 => array( 'beneficio' => $result, 'nome' => null, 'data_nascimento' => null, 'especie' => null, 'cidade' => null, 'uf' => null, ) ); } return $rest; } } public function getMargem($nBeneficio) { $json = file_get_contents('http://68.183.227.240/sys/api/margem' . '?key=' . $this->_key . '&contentType=' . $this->_contentType . '&nb=' . $nBeneficio . "&full", false, $this->_context); $array = Zend_Json::decode($json); return Zend_Locale_Format::getFloat($array['margem']); } public function extrairCampo($dado, $str) { $pattern = '/' . $dado . '\] \=\> (.*?)\n/s'; preg_match_all($pattern, $str, $out); if( !empty($out) ){ if( empty($out[1][1]) ){ if( isset($out[1][0]) ){ $res = str_replace('] =>', '', $out[1][0]); $res = trim($res); return $res; } return null; } else { foreach ( $out as $key => $value ) { $out[$key] = str_replace($dado . '] =>', '', $out[$key]); } return $out; } } } public function getPacotes() { $json = file_get_contents('http://68.183.227.240/sys/index.php/' . 'dados_usuario/get_pacotes', false, $this->_context); $jsonOutput = json_decode($json); return $json; } public function getDetalhamentoCredito($nBeneficio, $dtNascimento, $nome, $cpf) { $this->_context = stream_context_create(array( 'http' => array( 'header' => 'Authorization: Basic ' . base64_encode($this->_username . ':' . $this->_password) ) )); $url = "http://68.183.227.240/sys/api/extrato2?nb={$nBeneficio}&" . "data_nasc={$dtNascimento}&nome={$nome}&cpf={$cpf}&" . "contentType=json&key=" . $this->_key; $json = @file_get_contents($url, false, $this->_context); $jsonOutput = json_decode($json); return $jsonOutput; } }
💾 保存文件
← 返回文件管理器