|
|
<?php |
|
|
|
|
|
require_once 'Integracao.php'; |
|
|
include 'config.php'; |
|
|
|
|
|
/** |
|
|
* Classe para utilizar as API da empresa IXCSoft |
|
|
* |
|
|
* @documentation: http://wiki.ixcsoft.com.br/index.php/Recursos_da_API |
|
|
* @documentation: https://wikiapiprovedor.ixcsoft.com.br/# |
|
|
* |
|
|
* @author Lucas Awade |
|
|
* @function developer |
|
|
* @company SimplesIP |
|
|
* @version 1.0.1 |
|
|
*/ |
|
|
class IxcSoft extends Integracao |
|
|
{ |
|
|
|
|
|
private $token; |
|
|
private $url_api; |
|
|
private $selfSigned; |
|
|
private $metodo; |
|
|
|
|
|
######################################################################## |
|
|
## VARIAVEIS DA CLASSE ## |
|
|
######################################################################## |
|
|
private $query; |
|
|
private $curl; |
|
|
private $post = false; |
|
|
private $params = array(); |
|
|
private $debug; |
|
|
private $ssl = false; |
|
|
|
|
|
######################################################################## |
|
|
## RECURSOS DA API ## |
|
|
######################################################################## |
|
|
|
|
|
function listarBoleto($codCliente) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
if ($this->getArgs(func_get_args())) { |
|
|
$this->params = array( |
|
|
"qtype" => 'fn_areceber.id_cliente', |
|
|
"query" => $codCliente, |
|
|
"oper" => '=', |
|
|
"rp" => "2", |
|
|
"sortname" => 'fn_areceber.data_vencimento', |
|
|
"sortorder" => 'asc', |
|
|
"grid_param" => $this->gridParams( |
|
|
array( |
|
|
array( |
|
|
"TB" => "fn_areceber.liberado", |
|
|
"OP" => "=", |
|
|
"P" => "S", |
|
|
"C" => "AND" |
|
|
), |
|
|
array( |
|
|
"TB" => "fn_areceber.status", |
|
|
"OP" => "!=", |
|
|
"P" => "C" |
|
|
), |
|
|
array( |
|
|
"TB" => "fn_areceber.status", |
|
|
"OP" => "!=", |
|
|
"P" => "R" |
|
|
) |
|
|
) |
|
|
) |
|
|
); |
|
|
$this->setMetodo('fn_areceber'); |
|
|
return $this->setParams(); |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
function listarTodosBoletos($codCliente) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
if ($this->getArgs(func_get_args())) { |
|
|
$this->params = array( |
|
|
"qtype" => 'fn_areceber.id_cliente', |
|
|
"query" => $codCliente, |
|
|
"oper" => '=', |
|
|
"rp" => "2", |
|
|
"sortname" => 'fn_areceber.data_vencimento', |
|
|
"sortorder" => 'asc' |
|
|
|
|
|
); |
|
|
$this->setMetodo('fn_areceber'); |
|
|
return $this->setParams(); |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
function listarClientes() |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
$this->params = array( |
|
|
"qtype" => "cliente.id", |
|
|
"query" => "", |
|
|
"oper" => "!=", |
|
|
"page" => "1", |
|
|
"rp" => "20", |
|
|
"sortname" => "cliente.id", |
|
|
"sortorder" => "desc", |
|
|
); |
|
|
$this->setMetodo('cliente'); |
|
|
return $this->setParams(); |
|
|
} |
|
|
|
|
|
|
|
|
public function buscarCliente($cpf_cnpj) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
if ($this->getArgs(func_get_args())) { |
|
|
if (strlen($cpf_cnpj) == 11 || strlen($cpf_cnpj) == 14) { |
|
|
$this->params = array( |
|
|
"qtype" => "cliente.cnpj_cpf", |
|
|
"query" => "{$this->mask_cpf_cnpj($cpf_cnpj)}", |
|
|
"oper" => "=", |
|
|
"sortname" => "cliente.id", |
|
|
"sortorder" => "asc", |
|
|
); |
|
|
$this->setMetodo('cliente'); |
|
|
return $this->setParams(); |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
public function buscarClienteTelefone($tipo, $telefone) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
if ($this->getArgs(func_get_args())) { |
|
|
if (strlen($telefone) == 10 || strlen($telefone) == 11 || strlen($telefone) == 14) { |
|
|
$this->params = array( |
|
|
"qtype" => "cliente.$tipo", |
|
|
"query" => "{$this->mask_phone_tel($telefone)['telefone']}", |
|
|
"oper" => "=", |
|
|
"sortname" => "cliente.id", |
|
|
"sortorder" => "asc" |
|
|
); |
|
|
$this->setMetodo('cliente'); |
|
|
return $this->setParams(); |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Status de bloqueio: |
|
|
* CA - Bloqueio automatico |
|
|
* CM - Bloqueio Manual |
|
|
* A - Ativo |
|
|
* AA - Aguardando assinatura |
|
|
* D - Desativado |
|
|
* DE - Data Expirou |
|
|
* |
|
|
* @param int $id_cliente |
|
|
* @return boolean |
|
|
*/ |
|
|
function listarContrato($id_cliente) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
if ($this->getArgs(func_get_args())) { |
|
|
$this->params = array( |
|
|
"qtype" => 'cliente_contrato.id_cliente', |
|
|
"query" => "$id_cliente", |
|
|
"oper" => '=', |
|
|
"sortname" => 'cliente_contrato.id', |
|
|
"sortorder" => 'asc' |
|
|
); |
|
|
$this->setMetodo('cliente_contrato'); |
|
|
return $this->setParams(); |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
/* |
|
|
* Lista Clientes Conexoes |
|
|
*/ |
|
|
|
|
|
function listarConexoes($id_cliente) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
if ($this->getArgs(func_get_args())) { |
|
|
$this->params = array( |
|
|
"qtype" => 'radusuarios.id_cliente', |
|
|
"query" => "$id_cliente", |
|
|
"oper" => '=', |
|
|
"sortorder" => 'asc' |
|
|
); |
|
|
$this->setMetodo('radusuarios'); |
|
|
return $this->setParams(); |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} |
|
|
/* |
|
|
* Lista Ordens de Servi<EFBFBD>o |
|
|
*/ |
|
|
|
|
|
function listarOrdensServico($id_cliente) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
if ($this->getArgs(func_get_args())) { |
|
|
$this->params = array( |
|
|
"qtype" => 'su_oss_chamado.id_cliente', |
|
|
"query" => "$id_cliente", |
|
|
"oper" => '=', |
|
|
"sortorder" => 'asc' |
|
|
); |
|
|
$this->setMetodo('su_oss_chamado'); |
|
|
return $this->setParams(); |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
/* |
|
|
* Lista Clientes ONLINE |
|
|
*/ |
|
|
|
|
|
function formaPagamento($id_cliente) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
if ($this->getArgs(func_get_args())) { |
|
|
$this->params = array( |
|
|
"qtype" => 'cliente_contrato_tipo.id', |
|
|
"query" => "$id_cliente", |
|
|
"oper" => '=', |
|
|
"sortorder" => 'asc' |
|
|
); |
|
|
$this->setMetodo('cliente_contrato_tipo'); |
|
|
return $this->setParams(); |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
/* |
|
|
* Alterar Status do Acesso |
|
|
Liberar : cliente_contrato_15464 |
|
|
|
|
|
Aguardando Assinatura: cliente_contrato_23529 |
|
|
|
|
|
Avisar atraso: cliente_contrato_15463 |
|
|
|
|
|
Bloquear: cliente_contrato_15300 |
|
|
|
|
|
Retirar redu<EFBFBD><EFBFBD>o: cliente_contrato_29157 |
|
|
* */ |
|
|
function retirarReducao($contrato) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
if ($this->getArgs(func_get_args())) { |
|
|
$this->params = array( |
|
|
"id_contrato" => $contrato |
|
|
); |
|
|
$this->setMetodo('cliente_contrato_29157'); |
|
|
return $this->setParams(); |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
function desbloqueiaCliente($contrato) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
if ($this->getArgs(func_get_args())) { |
|
|
$this->params = array( |
|
|
"id" => $contrato |
|
|
); |
|
|
$this->setMetodo('desbloqueio_confianca'); |
|
|
return $this->setParams(); |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
/* |
|
|
* @param codigo_cliente string |
|
|
*/ |
|
|
function consultaFaturasVencidas($codigo_cliente) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
if ($this->getArgs(func_get_args())) { |
|
|
$faturas = $this->listarTodosBoletos($codigo_cliente)['registros']; |
|
|
$faturasVencidas = []; |
|
|
$diasVencido = []; |
|
|
|
|
|
foreach ($faturas as $invoice) { |
|
|
$diasVenc = $this->diasDatas(strtotime($invoice['data_vencimento'] . ' 23:59:59'),time()); |
|
|
if (strtotime($diasVenc) > 14 && $invoice['valor_aberto'] > 0) { |
|
|
$diasVencido[] = $diasVenc; |
|
|
} |
|
|
|
|
|
if (strtotime($invoice['data_vencimento'] . ' 23:59:59') < time() && $invoice['valor_aberto'] > 0) { |
|
|
$faturasVencidas[] = $invoice; |
|
|
} |
|
|
} |
|
|
return $diasVencido; |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function diasDatas($data_inicial , $data_final) { // Para esta função a data inicial e final tem que estar em Time Stamp. |
|
|
$diferenca = $data_final - $data_inicial; |
|
|
$dias = floor($diferenca / (60 * 60 * 24)); |
|
|
return $dias; |
|
|
} |
|
|
|
|
|
function enviaBoleto($type, $codigo_cliente) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
if ($this->getArgs(func_get_args())) { |
|
|
$response = false; |
|
|
$faturas = $this->listarBoleto($codigo_cliente)['registros']; |
|
|
$this->setMetodo('get_boleto'); |
|
|
|
|
|
foreach ($faturas as $invoice) { |
|
|
if (strtotime($invoice['data_vencimento'] . ' 23:59:59') < strtotime("+" . CONF_FATURA_DIAS_APOS . " month", time()) && $invoice['valor_aberto'] > 0) { |
|
|
$this->params = array( |
|
|
"boletos" => $invoice['id'], |
|
|
"juro" => "N", |
|
|
"multa" => "N", |
|
|
"atualiza_boleto" => "N", |
|
|
"tipo_boleto" => $type |
|
|
); |
|
|
if ($type == 'sms') { |
|
|
$request = $this->setParamsReturnAll(); |
|
|
} else { |
|
|
$request = $this->setParams(); |
|
|
} |
|
|
|
|
|
if ($request['registros'][0]['sucesso'] == 1 || strpos($request, 'sucesso')) { |
|
|
$response = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
return $response; |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
function abrirAtendimento($id_cliente, $titulo, $prioridade, $id_setor, $mensagem, $id_assunto, $id_tecnico = null) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
if ($this->getArgs(func_get_args())) { |
|
|
$protocolo = $this->gerarProtocolo(); |
|
|
$this->params = array( |
|
|
"tipo" => 'C', |
|
|
"protocolo" => $protocolo, |
|
|
"id_cliente" => $id_cliente, |
|
|
"titulo" => $titulo, |
|
|
"prioridade" => $prioridade, |
|
|
"id_ticket_setor" => $id_setor, |
|
|
"id_ticket_origem" => 'I', |
|
|
"interacao_pendente" => 'N', |
|
|
"origem_endereco" => 'M', |
|
|
"menssagem" => $mensagem, |
|
|
"su_status" => 'N', |
|
|
"status" => 'T', |
|
|
"id_assunto" => $id_assunto, |
|
|
"id_responsavel_tecnico" => $id_tecnico |
|
|
); |
|
|
$this->setMetodo('su_ticket'); |
|
|
$this->getPost(); |
|
|
return $this->setParams(null, debug_backtrace()); |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
function gerarProtocolo() |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
$this->setMetodo('gerar_protocolo_atendimento'); |
|
|
return $this->setParams(); |
|
|
} |
|
|
|
|
|
function verificaBloqueioInternet($idcliente) |
|
|
{ |
|
|
$pendencias = array(); |
|
|
$contratos = $this->listarContrato($idcliente); |
|
|
|
|
|
foreach ($contratos['registros'] as $value) { |
|
|
if ($value['status_internet'] == 'FA') { |
|
|
array_push($pendencias, 'INADIMPLENTE'); |
|
|
} else if ($value['status_internet'] == 'CA' || $value['status_internet'] == 'CM') { |
|
|
array_push($pendencias, 'BLOQUEADO'); |
|
|
} else { |
|
|
array_push($pendencias, 'ATIVO'); |
|
|
} |
|
|
} |
|
|
return $pendencias; |
|
|
} |
|
|
|
|
|
function cidadeNome($cod) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
$this->params = array( |
|
|
"qtype" => 'cidade.id', |
|
|
"query" => "$cod", |
|
|
"oper" => '=', |
|
|
"sortname" => 'cidade.id', |
|
|
"sortorder" => 'desc' |
|
|
); |
|
|
$this->setMetodo('cidade'); |
|
|
return $this->setParams(); |
|
|
} |
|
|
|
|
|
|
|
|
function consultaManutencao($latitude, $longitude) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
$this->params = array( |
|
|
"latitude" => $latitude, |
|
|
"longitude" => $longitude, |
|
|
); |
|
|
$this->setMetodo('consultar_regiao_manutencao'); |
|
|
return $this->setParams(); |
|
|
} |
|
|
|
|
|
|
|
|
function infoIdTransmissor($cod) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
$this->params = array( |
|
|
'qtype' => 'radpop_radio.id', |
|
|
'query' => $cod, |
|
|
'oper' => '=', |
|
|
'page' => '1', |
|
|
'rp' => '20', |
|
|
'sortname' => 'radpop_radio.id', |
|
|
'sortorder' => 'desc' |
|
|
); |
|
|
$this->setMetodo('radpop_radio'); |
|
|
return $this->setParams(); |
|
|
} |
|
|
|
|
|
|
|
|
function ordemViaPop($idpop) |
|
|
{ |
|
|
$this->debug = debug_backtrace(); |
|
|
$this->params = array( |
|
|
'qtype' => 'su_oss_chamado.id', |
|
|
'query' => '0', |
|
|
'oper' => '>', |
|
|
'page' => '1', |
|
|
'rp' => '20', |
|
|
'sortname' => 'su_oss_chamado.id', |
|
|
'sortorder' => 'desc', |
|
|
'grid_param' => $this->gridParams(array( |
|
|
array('TB' => 'su_oss_chamado.mensagem', 'OP' => 'L', 'P' => 'MASSIVA_CONCENTRADOR_ID =' . $idpop), |
|
|
array('TB' => 'su_oss_chamado.status', 'OP' => '!=', 'P' => 'F') |
|
|
)) |
|
|
); |
|
|
$this->setMetodo('su_oss_chamado'); |
|
|
return $this->setParams(); |
|
|
} |
|
|
|
|
|
function falhaMassivaAlternativa($documento) |
|
|
{ |
|
|
$retorno = $this->buscarCliente($documento); |
|
|
$idtransmissor = $this->listarConexoes($retorno['registros'][0]['id']); |
|
|
//$idpop = $this->infoIdTransmissor($idtransmissor['registros'][0]['id_transmissor']); |
|
|
//$popOS = $this->ordemViaPop($idpop['registros'][0]['id_pop']); |
|
|
$popOS = $this->ordemViaPop($idtransmissor['registros'][0]['id_concentrador']); |
|
|
|
|
|
return $popOS; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
######################################################################## |
|
|
## FUNCOES DO SISTEMA ## |
|
|
######################################################################## |
|
|
|
|
|
function __construct($token = CONF_TOKEN_API, $url_api = CONF_URL_API, $log = CONF_LOGGER_ATIVO, $selfSigned = true) |
|
|
{ |
|
|
$this->token = base64_encode($token); |
|
|
|
|
|
if (end(str_split($url_api)) != '/') { |
|
|
$url_api .= '/'; |
|
|
} |
|
|
|
|
|
$this->url_api = $url_api . 'webservice/v1/'; |
|
|
|
|
|
if (strpos($url_api, 'https')) { |
|
|
$this->selfSigned = true; |
|
|
$this->ssl = true; |
|
|
} else { |
|
|
$this->selfSigned = false; |
|
|
} |
|
|
|
|
|
$this->setLog($log); |
|
|
$this->integracaoReg(); |
|
|
$this->log->info("Iniciando integracao com IXCSoft", debug_backtrace()); |
|
|
} |
|
|
|
|
|
private function setMetodo($metodo) |
|
|
{ |
|
|
$this->metodo = $metodo; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Escreve a query para ser passada para o curl |
|
|
* |
|
|
* @param string $query |
|
|
*/ |
|
|
private function setQuery($query) |
|
|
{ |
|
|
return $this->query .= $query; |
|
|
} |
|
|
|
|
|
/** |
|
|
* retorna a string pronta da query do curl e limpa a variavel. |
|
|
* |
|
|
* @return string $query |
|
|
*/ |
|
|
private function getQuery() |
|
|
{ |
|
|
$query = $this->query; |
|
|
unset($this->query); |
|
|
return $query; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Habilita requisicao via POST |
|
|
* |
|
|
* @return boolean |
|
|
*/ |
|
|
private function getPost() |
|
|
{ |
|
|
return $this->post = true; |
|
|
} |
|
|
|
|
|
private function strCurl() |
|
|
{ |
|
|
$this->curl = "curl -s -k -H \"Authorization:Basic {$this->token}\" "; |
|
|
$this->curl .= sprintf("-H \"Content-Type: application/json\" -X POST %s %s ", !$this->post ? "-H \"ixcsoft:listar\"" : '', $this->query ? '-d' : ''); |
|
|
$this->curl .= $this->getQuery(); |
|
|
$this->curl .= "{$this->url_api}{$this->metodo}"; |
|
|
$this->log->debug("Curl: {$this->curl}", debug_backtrace()); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Recebe array de forma de indice e valor |
|
|
* |
|
|
* @example array("qtype" => 'test_api', "query" => '123', "oper" => '=') |
|
|
* |
|
|
* @param type $params |
|
|
*/ |
|
|
private function setParams() |
|
|
{ |
|
|
$count = 0; |
|
|
if ($this->params) { |
|
|
$this->setQuery("'{"); |
|
|
foreach ($this->params as $key => $param) { |
|
|
$count++; |
|
|
$this->setQuery("\"{$key}\": \"$param\""); |
|
|
|
|
|
if ($count == count($this->params)) { |
|
|
$this->setQuery("}' "); |
|
|
} else { |
|
|
$this->setQuery(","); |
|
|
} |
|
|
} |
|
|
} |
|
|
unset($this->params); |
|
|
$this->strCurl(); |
|
|
$result = $this->exec(); |
|
|
$ret = json_decode($result, true); |
|
|
return $ret; |
|
|
} |
|
|
|
|
|
private function setParamsReturnAll() |
|
|
{ |
|
|
$count = 0; |
|
|
if ($this->params) { |
|
|
$this->setQuery("'{"); |
|
|
foreach ($this->params as $key => $param) { |
|
|
$count++; |
|
|
$this->setQuery("\"{$key}\": \"$param\""); |
|
|
|
|
|
if ($count == count($this->params)) { |
|
|
$this->setQuery("}' "); |
|
|
} else { |
|
|
$this->setQuery(","); |
|
|
} |
|
|
} |
|
|
} |
|
|
unset($this->params); |
|
|
$this->strCurl(); |
|
|
$result = $this->exec(); |
|
|
return $result; |
|
|
} |
|
|
|
|
|
private function gridParams($params) |
|
|
{ |
|
|
$count = 0; |
|
|
$count1 = 0; |
|
|
$json = "["; |
|
|
|
|
|
foreach ($params as $array) { |
|
|
$count++; |
|
|
$json .= "{"; |
|
|
foreach ($array as $key => $grid) { |
|
|
$count1++; |
|
|
$json .= "\\\"$key\\\": \\\"$grid\\\""; |
|
|
$json .= $count1 != count($array) ? "," : ''; |
|
|
} |
|
|
unset($count1); |
|
|
$json .= "}"; |
|
|
$json .= $count != count($params) ? "," : ''; |
|
|
} |
|
|
$json .= "]"; |
|
|
if ($params) { |
|
|
return $json; |
|
|
} else { |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
function exec() |
|
|
{ |
|
|
$exec = shell_exec($this->curl); |
|
|
return $this->response($exec); |
|
|
} |
|
|
|
|
|
private function response($data) |
|
|
{ |
|
|
$this->log->debug("Reponse API: " . print_r(json_decode($data, true), true), $this->debug); |
|
|
if ($data) { |
|
|
return $data; |
|
|
} else { |
|
|
return false; |
|
|
} |
|
|
} |
|
|
}
|
|
|
|