forked from Claudio/integracao
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.
179 lines
5.3 KiB
179 lines
5.3 KiB
<?php |
|
|
|
require_once 'Integracao.php'; |
|
include 'config.php'; |
|
|
|
/** |
|
* Classe para utilizar as API da empresa Synsuite |
|
* |
|
* @documentation: https://documenter.getpostman.com/view/7156409/SzmY9gdZ?version=latest |
|
* https://wiki.grupovoalle.com.br/APIs |
|
* @author Lucas Awade |
|
* @function developer |
|
* @company SimplesIP |
|
* @version 1.0.0 |
|
*/ |
|
class Synsuite extends Integracao { |
|
|
|
private $token; |
|
private $url; |
|
// ***************************************************************************** |
|
// * VARIAVEIS DA CLASSE * |
|
// ***************************************************************************** |
|
private $method; |
|
private $request; |
|
private $curl; |
|
private $param = array(); |
|
|
|
// ***************************************************************************** |
|
// * RECURSOS DA API * |
|
// ***************************************************************************** |
|
|
|
function ping(){ |
|
echo "pong"; |
|
} |
|
|
|
/** |
|
* @BuscaCliente |
|
* Responsável por buscar informações do cliente através de um telefone, cpf, cnpj ou id do contrato no Synsuite. |
|
* |
|
* @param string $documento |
|
* @return array |
|
*/ |
|
function clientValidade($documento) { |
|
$this->debug = debug_backtrace(); |
|
$this->getMethod("CLIENT_VALIDATE"); |
|
$this->param['codigo'] = $documento; |
|
return $this->response(); |
|
} |
|
|
|
/** |
|
* @DesbloqueioCliente |
|
* Realiza uma tentativa de desbloqueio de contrato. |
|
* |
|
* @param string $contract |
|
* @return array |
|
*/ |
|
function unblockContract($contract) { |
|
$this->debug = debug_backtrace(); |
|
$this->getMethod('UNBLOCK_CONTRACT'); |
|
$this->param['data_unblock_contract'] = $contract; |
|
return $this->response(); |
|
} |
|
|
|
/** |
|
* @VerificaManutenção |
|
* Evento o qual realiza a abertura do protocolo referente a conexões que estão com o ponto de acesso em manutenção. |
|
* |
|
* @param string $protocol |
|
* @return array |
|
*/ |
|
function openProtocolFinancial($protocol) { |
|
$this->debug = debug_backtrace(); |
|
$this->getMethod('OPEN_PROTOCOL_FINANCIAL'); |
|
$this->param['data_open_protocol_financial'] = $protocol; |
|
return $this->response(); |
|
} |
|
|
|
/** |
|
* @EnvioBoleto |
|
* Realiza o envio dos boletos em atraso (caso existir) |
|
* |
|
* @param string $billet |
|
* @return array |
|
*/ |
|
function sendBillets($billet) { |
|
$this->debug = debug_backtrace(); |
|
$this->getMethod('SEND_BILLETS'); |
|
$this->param['data_send_billets'] = $billet; |
|
return $this->response(); |
|
} |
|
|
|
// ***************************************************************************** |
|
// * FUNCOES DA CLASSE * |
|
// ***************************************************************************** |
|
function __construct($token, $url_api, $log = false) { |
|
$this->token = $token; |
|
$this->url = $url_api; |
|
$this->setLog($log); |
|
$this->log->info("Iniciando integracao com Synsuit", debug_backtrace()); |
|
} |
|
|
|
private function getMethod($method) { |
|
$this->method = $method; |
|
} |
|
|
|
private function request($type) { |
|
$this->request = strtoupper($type); |
|
} |
|
|
|
private function response($request = "POST") { |
|
$this->request($request); |
|
$this->curl(); |
|
return $this->execute(); |
|
} |
|
|
|
private function curl() { |
|
$this->curl = curl_init(); |
|
$params = array( |
|
CURLOPT_URL => "{$this->url}{$this->method}", |
|
CURLOPT_RETURNTRANSFER => true, |
|
CURLOPT_ENCODING => "", |
|
CURLOPT_MAXREDIRS => 10, |
|
CURLOPT_TIMEOUT => 0, |
|
CURLOPT_FOLLOWLOCATION => false, |
|
CURLOPT_SSL_VERIFYHOST => 0, |
|
CURLOPT_SSL_VERIFYPEER => false, |
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
CURLOPT_CUSTOMREQUEST => $this->request, |
|
CURLOPT_HTTPHEADER => array( |
|
"Content-Type: application/json" |
|
) |
|
); |
|
if ($this->request == strtoupper("POST")) { |
|
$params[CURLOPT_POSTFIELDS] = $this->command(); |
|
} |
|
curl_setopt_array($this->curl, $params); |
|
} |
|
|
|
private function command() { |
|
$size = 0; |
|
$command = "{"; |
|
foreach ($this->param as $key => $value) { |
|
$command .= "\n" . sprintf('"%s":"%s"', $key, $value); |
|
if (count($this->param) != $size) { |
|
$command .= ","; |
|
} |
|
$size++; |
|
} |
|
$command .= "\n" . sprintf('"token":"%s"', $this->token) . "\n}"; |
|
unset($this->param); |
|
return $command; |
|
} |
|
|
|
private function execute() { |
|
$response = curl_exec($this->curl); |
|
if (curl_error($this->curl)) { |
|
curl_close($this->curl); |
|
return false; |
|
} |
|
curl_close($this->curl); |
|
return $this->retorno($response); |
|
} |
|
|
|
/** |
|
* Prepara dos dados para ser transmitidos para o metodo a ser retornado a |
|
* integracao. |
|
* |
|
* @return array |
|
*/ |
|
private function retorno($data) { |
|
$this->log->debug("Reponse: " . print_r(json_decode($data,true), true), $this->debug); |
|
if ($data) { |
|
return json_decode($data,true); |
|
} else { |
|
return false; |
|
} |
|
} |
|
|
|
}
|
|
|