PABX criado para pesquisas
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

240 lines
6.9 KiB

<?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, 'DESBLOQUEIA_CLIENTE_CPF', $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ção.
*/
$reg_retorno = $numero;
$reg_msg = '';
$reg_status_exec = '1';
$retorno_cliente = '';
/*
* Registra o inicio da integração. As variaveis passadas na funções são iniciali-
* zadas em serverAgi.php.
*/
@RegistraIntegracao($idMetodo, $uid, $uidOld, $numero);
try {
$codCliente = $agi->get_variable('CODCLI', true);
$resultDetail = detalhesPlanoLista($codCliente);
$unlockClient = desbloqueiaCliente($resultDetail['codsercli']);
__logStr("Desbloqueio de Cliente", "Detalhes Plano: ". print_r($resultDetail,true), $script, true);
if ($unlockClient->statusCode == 200) {
$agi->exec_goto(GetUra('DESBLOQUEIO_SUCESSO'));
} else {
$agi->exec_goto(GetAnuncio('DESBLOQUEIO_FALHA'));
}
} catch (Exception $ex) {
$reg_msg = $ex->getMessage();
$reg_status_exec = 'Er';
__logStr("Realiza Desbloqueio de Cliente", $reg_msg . " Codigo do cliente: $codCliente", $script, true);
}
@AtualizaIntegracao($uid, $reg_retorno, $reg_msg, $reg_status_exec, $retorno_cliente);
if (!$dadosIntegra) {
@grava_dadosIntegra($reg_retorno);
}
function detalhesPlanoLista($codCli) {
if (empty($codCli)) {
return "ERRO - Codigo do cliente nao foi informado!";
}
try {
$json = sprintf('{
"request":{
"sendRequest": "integrator.server",
"method": "execute",
"submethod": "service.list",
"params": {
"_user":"AMIGALINK",
"_passwd":"SIMPLESIP",
"codcli": "%s"
}
}
}', $codCli);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://45.236.204.25/integrator.server.php",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $json,
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
throw new Exception("cURL Error #:" . $err);
}
$array = json_decode($response);
$resultado = objectToArray($array);
foreach ($resultado['data']['results'] as &$value) {
if (substr($value['descri_est'], 0, 8) == "Suspenso") {
return $value;
} else {
return null;
}
}
return $array;
} catch (Exception $ex) {
return $ex->getMessage();
}
}
function detalhesPlano($codCli) {
if (empty($codCli)) {
return "ERRO - Codigo do cliente nao foi informado!";
}
try {
$json = sprintf('{
"request":{
"sendRequest": "integrator.server",
"method": "execute",
"submethod": "services.details",
"params": {
"_user":"AMIGALINK",
"_passwd":"SIMPLESIP",
"codcli": "%s"
}
}
}', $codCli);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://45.236.204.25/integrator.server.php",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $json,
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
throw new Exception("cURL Error #:" . $err);
}
$array = json_decode($response);
$resultado = objectToArray($array);
foreach ($resultado['data']['results'] as $value) {
if ($value['descri_est'] != "Cancelado") {
$arPlano[] = $value['data']['results'];
}
}
return $arPlano;
} catch (Exception $ex) {
return $ex->getMessage();
}
}
function desbloqueiaCliente($codSerCli) {
if (empty($codSerCli)) {
return "ERRO - Codigo de servico do cliente nao foi informado";
}
try {
$json = sprintf('{
"request":{
"sendRequest": "integrator.server",
"method": "execute",
"submethod": "habilitacaoProvisoria.execute",
"params": {
"_user":"AMIGALINK",
"_passwd":"SIMPLESIP",
"codsercli": "%s"
}
}
}', $codSerCli);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://45.236.204.25/integrator.server.php",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $json,
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
throw new Exception("cURL Error #:" . $err);
}
return json_decode($response);
} catch (Exception $ex) {
return $ex->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;
}
}