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.
 
 

411 lines
14 KiB

<?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
* @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;
########################################################################
## 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 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;
}
}
/**
* 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;
}
}
/*
* 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;
}
}
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') < 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->setParamsFull();
}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(
"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" => 'N',
"id_assunto" => $id_assunto,
"id_responsavel_tecnico" => $id_tecnico
);
$this->setMetodo('su_ticket');
$this->getPost();
return $this->setParams();
} else {
return false;
}
}
function gerarProtocolo() {
$this->debug = debug_backtrace();
$this->setMetodo('gerar_protocolo_atendimento');
return $this->setParams(null, debug_backtrace());
}
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();
}
########################################################################
## FUNCOES DO SISTEMA ##
########################################################################
function __construct($token, $url_api, $log = false, $selfSigned = true) {
$this->token = base64_encode($token);
$this->url_api = $url_api . "/webservice/v1/";
$this->selfSigned = $selfSigned;
$this->setLog($log);
$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 setParamsFull() {
$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;
}
}
}