Viewing file: inc_sicrediConsultaWS.php (4.12 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
require_once 'HTTP/Request2.php';
date_default_timezone_set('America/Sao_Paulo');
$conteudo = NULL;
$request = NULL;
$retorno_02 = NULL;
$retorno_03 = NULL;
$retorno_04 = NULL;
// ########## CONSULTA A CHAVE DE TRANSACAO LIBERADA ##########
$sqlC = "
SELECT CTW_ChaveTransacao
FROM IRP_RegistroChaveTransacaoWS
WHERE CTW_AtivoSN = 'S'
";
$rs_queryC = mysql_query($sqlC);
$rst_queryC = mysql_fetch_array($rs_queryC);
$chaveTransacao = $rst_queryC["CTW_ChaveTransacao"];
// ########## FIM CONSULTA A CHAVE DE TRANSACAO LIBERADA ##########
$conteudo = array(
'agencia' => '0751',
'posto' => '02',
'cedente' => "$cedente",
'nossoNumero' => "$nossoNumero",
);
// ########## SICREDI | CONSULTA ##########
$request = new HTTP_Request2('https://cobrancaonline.sicredi.com.br/sicredi-cobranca-ws-ecomm-api/ecomm/v1/boleto/consulta',
HTTP_Request2::METHOD_GET, array('use_brackets' => true));
$request->setConfig(
array(
'ssl_verify_peer' => FALSE,
'ssl_verify_host' => FALSE
));
$url = $request->getUrl();
$request->setHeader(
array(
'token' => "$chaveTransacao",
'Content-Type' => 'application/json'
)
);
$url->setQueryVariables($conteudo);
try {
$response = $request->send();
$stringRetorno = $response->getBody();
}
catch (HttpException $ex)
{
//$stringRetorno = var_dump($ex);
}
//echo "<pre>";
//print_r($stringRetorno);
//echo "<pre>";
//echo "\n\n";
$retorno_01 = str_replace('{', '', $stringRetorno);
$retorno_01 = str_replace('[', '', $retorno_01);
$retorno_01 = str_replace('}', '', $retorno_01);
$retorno_01 = str_replace(']', '', $retorno_01);
$retorno_01 = str_replace(',"', '#', $retorno_01);
$retorno_01 = str_replace('"', '', $retorno_01);
$retorno_02 = explode('#', $retorno_01);
for($i=0; $i<23; $i++)
{
if (isset($retorno_02[$i]))
{
$retorno_03 = explode(':', $retorno_02[$i]);
$retorno_04[$retorno_03[0]] = $retorno_03[1];
}
}
// FORMATA A STRING DE RETORNO
$stringRetornoFormatada = '';
foreach($retorno_04 as $nCampo => $valor)
{
$stringRetornoFormatada .= $nCampo . ' => ' . $valor . "
";
}
$seuNumero = $retorno_04["seuNumero"];
$nossoNumero = $retorno_04["nossoNumero"];
$valor = $retorno_04["valor"];
$valorLiquidado = $retorno_04["valorLiquidado"];
$dataEmissao = $retorno_04["dataEmissao"];
$dataVencimento = $retorno_04["dataVencimento"];
$dataLiquidacao = $retorno_04["dataLiquidacao"];
$situacao = $retorno_04["situacao"];
if (isset($retorno_04["codigo"]))
{
$codigo = $retorno_04["codigo"];
}else{
$codigo = NULL;
}
switch($situacao)
{
CASE "EM CARTEIRA": $situacaoBoleto = 3; break;
CASE "LIQUIDADO": $situacaoBoleto = 4; break;
CASE "REJEITADO": $situacaoBoleto = 5; break;
CASE "BAIXADO POR SOLICITACAO": $situacaoBoleto = 3; break;
}
// BOLETO NÃO EXISTE NO SICREDI
if ($codigo == "0024")
{
$situacaoBoleto = 0;
}
if ($situacaoBoleto == 0 || $situacaoBoleto == 5)
{
if ($codigo == "0024")
{
$subject = "URGENTE | ESTA SENDO CONSULTADO UM BOLETO NÃO REGISTRADO ";
}else{
$subject = "A CONSULTA DO BOLETO $seuNumero RETORNOU UM ERRO ";
}
$mailto = "marcio@netnigro.com.br";
$xheader = "From: * URGENTE ERRO | SISTEMA E-CERTIDOES * <marcio@netnigro.com.br> \n";
$xheader .= "Content-Type: text/html \n";
//$xheader .= "Bcc: cron.funarpen@netnigro.com.br\n";
$xheader .= "Return-Path: <marcio@netnigro.com.br>"."\n";
$xheader .= "X-Priority: 1\n"; // Urgent message!
$sucesso = mail("$mailto", "$subject", "$stringRetorno", $xheader);
if ($codigo == "0024")
{
die("HOUVE UM ERRO CRITICO | CONTATE URGENTEMENTE A EQUIPE DE TI ");
}
}
// ########## FIM SICREDI | CONSULTA ##########
?>
|