repositório com os arquivos utilizados para integração entre o sistema SimplesIP e diversos sistemas.
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.
 
 

162 lines
5.3 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, 'ABRE_ATENDIMENTO', $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
{
$servicoCliente = $agi->get_variable('IDCLISERVICO',true);
$nome = $agi->get_variable('NOMECLIENTE',true);
$telefone = $agi->get_variable('TELCLIENTE',true);
$email = $agi->get_variable('EMAIL',true);
__logStr("Abertura de OS", "IdServico: ". print_r($servicoCliente,true), $script, true);
__logStr("Abertura de OS", "Nome: ". print_r($nome,true), $script, true);
__logStr("Abertura de OS", "Telefone: ". print_r($telefone,true), $script, true);
__logStr("Abertura de OS", "Email: ". print_r($email,true), $script, true);
$abreOS = AbreChamado($servicoCliente, $nome, $telefone, $email);
__logStr("Abertura de OS", "Retorno da abertura de OS: ". print_r($abreOS,true), $script, true);
if ($abreOS['status_requisicao'] == 'suscess') {
$agi->exec_goto(GetAnuncio('ORDEM_SERVICO_ABERTA_FIBNET'));
}else{
$agi->exec_goto(GetFila('ATENDIMENTO_FIBNET'));
}
}
catch (Exception $ex)
{
$reg_msg = $ex->getMessage();
$reg_status_exec = 'Er';
__logStr("Abertura de OS", $reg_msg, $script, true);
}
@AtualizaIntegracao($uid, $reg_retorno, $reg_msg, $reg_status_exec, $retorno_cliente);
if(!$dadosIntegra)@grava_dadosIntegra($reg_retorno);
function AbreChamado($idCliServico, $nomeCliente, $telCliente, $emailCliente)
{
$clientId = "5";
$clientSecret = "B7fuHYQykrCYmtWkz7YgDcybwUk509PiF8u99oBp";
$username = "api@simplesip.com.br";
$password = "!@#simplesip_api_fibnet!@#";
if (!empty($idCliServico)) {
$requestBody = array(
"client_id" => $clientId,
"client_secret" => $clientSecret,
"username" => $username,
"password" => $password,
"grant_type" => "password"
);
try {
$req = curl_init("https://api.fibnet.hubsoft.com.br/oauth/token");
$header = array();
$header[] = 'Accept: application/json';
curl_setopt($req, CURLOPT_HTTPHEADER, $header);
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
curl_setopt($req, CURLOPT_POST, true);
curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($requestBody));
$resp = json_decode(curl_exec($req), true);
curl_close($req);
} catch (Exception $ex) {
$msg = $ex->getMessage();
return $msg;
}
}
try {
$postfields = array(
"id_cliente_servico" => $idCliServico,
"descricao" => "Aberto via URA",
"nome" => $nomeCliente,
"telefone" => $telCliente,
"email" => $emailCliente,
"abrir_os" => true
);
$tokenType = $resp['token_type'];
$accessToken = $resp['access_token'];
$authorizationToken = $tokenType . " " . $accessToken;
$url = "https://api.fibnet.hubsoft.com.br/api/v1/integracao/atendimento";
$req = curl_init($url);
$header = array();
$header[] = 'Accept: application/json';
if (!is_null($authorizationToken)) {
$header[] = 'Authorization: ' . $authorizationToken;
}
curl_setopt($req, CURLOPT_HTTPHEADER, $header);
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
curl_setopt($req, CURLOPT_POST, 1);
curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($postfields));
$result = json_decode(curl_exec($req), true);
curl_close($req);
$cliente = objectToArray($result);
if ($cliente['status'] == 'error') {
return array(utf8_decode($cliente['msg']), $cliente['errors']);
} else {
$abreOs = array(
"status_requisicao" => $cliente['status'],
"status_chamado" => utf8_decode($cliente['atendimento']['status']),
"protocolo_atendimento" => $cliente['atendimento']['protocolo'],
"id_atendimento" => $cliente['atendimento']['id_atendimento'],
"data_abertura" => $cliente['atendimento']['data_cadastro'],
"id_os" => $cliente['ordens_servico']['id_ordem_servico']
);
return $abreOs;
}
} catch (Exception $ex) {
$msg = $ex->getMessage();
return $msg;
}
}
function objectToArray($d) {
if (is_object($d)) {
$d = get_object_vars($d);
}
if (is_array($d)) {
return array_map(__FUNCTION__, $d);
} else {
return $d;
}
}