|
|
<?php |
|
|
require '/var/lib/asterisk/scripts/integracao/dbAbstract.php'; |
|
|
include '/var/lib/asterisk/scripts/integracao/custom/funcoesCustom.php'; |
|
|
|
|
|
$scrpt = $argv[0]; |
|
|
$config = array('itgc_host', 'itgc_port', 'itgc_database', 'itgc_user', 'itgc_password'); |
|
|
$config = GetConfigIntegracao($connPG, 'ENVIA_LINHA_DIGITAVEL', $config); |
|
|
|
|
|
$user = $config['itgc_user']; |
|
|
$passWord = $config['itgc_password']; |
|
|
$host = $config['itgc_host']; |
|
|
$port = $config['itgc_port']; |
|
|
$dataBase = $config['itgc_database']; |
|
|
$tipoDb = DB__PGSQL; |
|
|
|
|
|
$pathSom = '/var/lib/asterisk/sounds/customizados/'; |
|
|
|
|
|
/* |
|
|
* Interage com o asterisk, por funcoes agi. |
|
|
*/ |
|
|
$agi = GetAgi(); |
|
|
/* |
|
|
* Variaveis para o status da integra<EFBFBD><EFBFBD>o. |
|
|
*/ |
|
|
$reg_retorno = $numero; |
|
|
$reg_msg = ''; |
|
|
$reg_status_exec = '1'; |
|
|
$retorno_cliente = ''; |
|
|
|
|
|
/* |
|
|
* Registra o inicio da integra<EFBFBD><EFBFBD>o. As variaveis passadas na fun<EFBFBD><EFBFBD>es s<EFBFBD>o iniciali- |
|
|
* zadas em serverAgi.php. |
|
|
*/ |
|
|
@RegistraIntegracao($idMetodo, $uid, $uidOld, $numero); |
|
|
|
|
|
try { |
|
|
//$telefone = '65999797353'; |
|
|
$telefone = $agi->get_variable('TELEFONE',true); |
|
|
$nome = $agi->get_variable('NOME_RAZAOSOCIAL',true); |
|
|
$cpf = $agi->get_variable('CPF_CNPJ',true); |
|
|
$cliente = RetornaLinhaDigitavel($cpf); |
|
|
|
|
|
__logStr("Envia Linha Digitavel", "Informacoes serialize: ". print_r($cliente,true), $script, true); |
|
|
|
|
|
if (empty($cliente)) { |
|
|
$agi->exec_goto(GetAnuncio('FALHA_ENVIO_BOLETO')); |
|
|
} else { |
|
|
|
|
|
$envio = EnviaSMS($telefone, $nome, $cliente['ld_cobranca'], $cliente['data_vencimento']); |
|
|
|
|
|
if (substr($envio, 0, 4) == 'ERRO' || empty($envio)) { |
|
|
$agi->exec_goto(GetAnuncio('FALHA_ENVIO_BOLETO')); |
|
|
} else { |
|
|
|
|
|
$audio = $pathSom . 'envio_boleto_sucesso_pt1'; |
|
|
$agi->stream_file($audio); |
|
|
|
|
|
$agi->say_digits($telefone); |
|
|
|
|
|
$agi->exec_goto(GetUra('URA_FATURA_ENVIADA')); |
|
|
} |
|
|
} |
|
|
} catch (Exception $ex) { |
|
|
$reg_msg = $ex->getMessage(); |
|
|
$reg_status_exec = 'Er'; |
|
|
__logStr("Consulta de Cliente", $reg_msg . " Consulta de Cliente: $cpf", $script, true); |
|
|
} |
|
|
|
|
|
@AtualizaIntegracao($uid, $reg_retorno, $reg_msg, $reg_status_exec, $retorno_cliente); |
|
|
if (!$dadosIntegra) |
|
|
@grava_dadosIntegra($reg_retorno); |
|
|
|
|
|
function EnviaSMS($telefone, $nomeCliente, $linhaDigitavel, $vencimento) |
|
|
{ |
|
|
if (empty($telefone)) { |
|
|
throw new Exception("ERRO - telefone nao informado!"); |
|
|
} |
|
|
|
|
|
$dtVenc = date("d/m/Y", strtotime($vencimento)); |
|
|
$nomeTratado = clear_str($nomeCliente); |
|
|
try { |
|
|
if (empty($linhaDigitavel)) { |
|
|
|
|
|
$authorizationToken = "1lH2cSqk2Dv6TnT6MfHDJuCKGhkgpIr2"; |
|
|
$message = urlencode("Brasil Net Cornelio Procopio. Ola,{$nomeTratado}! sua fatura de vencimento em {$dtVenc}" |
|
|
. " nao possui linha digitavel registrada"); |
|
|
$url = "http://api.sms.eai.net.br/v1/message?recipient=55{$telefone}&text={$message}&key={$authorizationToken}"; |
|
|
} else { |
|
|
|
|
|
$authorizationToken = "1lH2cSqk2Dv6TnT6MfHDJuCKGhkgpIr2"; |
|
|
$message = urlencode("Brasil Net Cornelio Procopio. Ola,{$nomeTratado}! sua fatura, com vencimento em {$dtVenc} Linha: {$linhaDigitavel}"); |
|
|
$url = "http://api.sms.eai.net.br/v1/message?recipient=55{$telefone}&text={$message}&key={$authorizationToken}"; |
|
|
} |
|
|
|
|
|
$ch = curl_init(); |
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
|
|
$result = curl_exec($ch); |
|
|
|
|
|
file_put_contents('/var/log/asterisk/integracao.log', $url . "\r\n", FILE_APPEND); |
|
|
|
|
|
if (substr($result, 0, 3) == '400') { |
|
|
throw new Exception("ERRO - " . $result); |
|
|
} |
|
|
|
|
|
$envio = simplexml_load_string($result); |
|
|
$arDados = objectToArray($envio->mt); |
|
|
|
|
|
return $arDados; |
|
|
} catch (Exception $e) { |
|
|
return $e->getMessage(); |
|
|
} |
|
|
} |
|
|
|
|
|
function objectToArray($d) |
|
|
{ |
|
|
if (is_object($d)) { |
|
|
$d = get_object_vars($d); |
|
|
} |
|
|
if (is_array($d)) { |
|
|
return array_map(__FUNCTION__, $d); |
|
|
} else { |
|
|
return $d; |
|
|
} |
|
|
} |
|
|
|
|
|
function RetornaLinhaDigitavel($paramCpf) |
|
|
{ |
|
|
try { |
|
|
$pdo = new PDO("pgsql:dbname=mkData3.0;host=100.64.0.5;port=5432", "simplesip", "S1mPl3s_1P!!"); |
|
|
if (!$pdo) { |
|
|
throw new Exception("Erro ao conectar a base de dados!"); |
|
|
} |
|
|
|
|
|
$CPF = soNumero($paramCpf); |
|
|
$sql = $pdo->prepare("SELECT cli.nome_razaosocial, COALESCE(cli.cpf,cli.cnpj) AS cpf_cnpj, COALESCE(cli.fone01, cli.fone02) AS telefone, |
|
|
f.data_lancamento, f.valor_total, f.data_vencimento, f.liquidado, f.ld_cobranca, b.num_doc |
|
|
FROM |
|
|
mk_pessoas cli |
|
|
INNER JOIN mk_faturas f ON cli.codpessoa = f.cd_pessoa |
|
|
INNER JOIN mk_boletos_gerados b ON b.cd_fatura = f.codfatura AND b.substituido='N' |
|
|
WHERE |
|
|
excluida='N' |
|
|
AND f.liquidado='N' |
|
|
AND f.suspenso='N' |
|
|
AND to_char(f.data_vencimento,'YYYY-MM')<=to_char(now(),'YYYY-MM') |
|
|
AND to_char(f.data_vencimento,'YYYY-MM-DD')<to_char(now()-INTERVAL '20 DAY' ,'YYYY-MM-DD') |
|
|
AND REPLACE(REPLACE(REPLACE(COALESCE(cli.cnpj,cli.cpf),'-',''),'/',''),'.','')=:CPF"); |
|
|
$sql->bindValue(':CPF', $CPF, PDO::PARAM_STR); |
|
|
$sql->execute(); |
|
|
|
|
|
if ($sql->rowCount() > 0) { |
|
|
$array = $sql->fetchAll(PDO::FETCH_ASSOC); |
|
|
foreach ($array as $valor) { |
|
|
return $valor; |
|
|
} |
|
|
} |
|
|
} catch (Exception $ex) { |
|
|
throw new Exception($ex->getMessage()); |
|
|
} |
|
|
} |
|
|
|
|
|
function clear_str($string) |
|
|
{ |
|
|
|
|
|
$dirtyLetter = array('<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', |
|
|
'<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', |
|
|
'<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', |
|
|
'<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', 'O', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>'); |
|
|
|
|
|
$clearLetter = array('a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', |
|
|
'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'y', 'A', |
|
|
'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'N', |
|
|
'O', 'O', 'O', 'O', 'O', '0', 'U', 'U', 'U'); |
|
|
|
|
|
return str_replace($dirtyLetter, $clearLetter, $string); |
|
|
} |
|
|
|
|
|
?>
|
|
|
|