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.
 
 

380 lines
10 KiB

<?php
require_once 'Integracao.php';
include 'config.php';
/**
* DESCRICAO DO DESENVOLVEDOR
*
* @documentation http://IP:PORTA/main.php/api/doc/md/L2RvYy9SRUFETUUubWQ
* @author Jose Henrique Joanoni
* @function developer
* @company SimplesIP
* @version 1.0.2
*/
class CNTSistemas extends Integracao {
private $token;
private $url;
private $metodo;
private $query;
private $curl;
private $debug;
private $tipoRequisicao;
private $params = array();
private $ssl = false;
########################################################################
## FUNCOES DA API ##
########################################################################
/**
* Metodo para consulta de clientes via telefone.
*
* @param string $phone
* @return boolean
*/
public function identificarTelefone($phone)
{
$this->debug = debug_backtrace();
if($this->getArgs(func_get_args())){
$this->params = array(
"Telefone" => $this->phoneMask($phone)
);
$this->setMetodo('Pessoa');
return $this->setParams();
}else{
return false;
}
}
/**
* Metodo para consulta de documento como CPF/CNPJ
*
* @param string $documento
* @return boolean
*/
public function identificarDocumento($documento) {
$this->debug = debug_backtrace();
if ($this->getArgs(func_get_args())) {
$this->params = array(
"CpfCnpj" => $documento
);
$this->setMetodo('Pessoa');
return $this->setParams();
} else {
return false;
}
}
/**
* Metodo para verificacao de pendencias financeiras mediante historico financeiro
*
* @param string $IdPessoa
* @return boolean
*/
public function verificaPendencia($IdPessoa)
{
$this->debug = debug_backtrace();
if($this->getArgs(func_get_args())){
$this->params = array(
"IdPessoa" => $IdPessoa
);
$this->setMetodo('HistoricoFinanceiro');
return $this->setParams();
}else{
return false;
}
}
/**
* Metodo para recuperacao da segunda via de boleto do cliente.
*
* @param int $id_pessoa
* @param string $cpf_cnpj
* @return boolean
*/
public function segundaViaBoleto($id_pessoa)
{
$this->debug = debug_backtrace();
if ($this->getArgs(func_get_args())) {
$this->params = array(
"IdPessoa" => $id_pessoa
);
$this->setMetodo('SegundaViaBoleto');
return $this->setParams();
} else {
return false;
}
}
/**
* Metodo para envio de boletos ao cliente.
*
* @param int $id_loja
* @param int $id_conta_receber
* @return boolean
*/
public function enviaBoleto($id_loja, $id_conta_receber)
{
$this->debug = debug_backtrace();
if($this->getArgs(func_get_args())){
$this->params = array(
"IdLoja" => $id_loja,
"IdContaReceber" => $id_conta_receber
);
$this->setMetodo('EnviaBoleto');
return $this->setParams();
}else{
return false;
}
}
public function contratosCliente($id_pessoa)
{
$this->debug = debug_backtrace();
if($this->getArgs(func_get_args())){
$this->params = array(
"IdPessoa" => $id_pessoa
);
$this->setMetodo('Contrato');
return $this->setParams();
}else{
return false;
}
}
public function servicoCliente($id_servico)
{
$this->debug = debug_backtrace();
if($this->getArgs(func_get_args())){
$this->params = array(
"IdServico" => $id_servico
);
$this->setMetodo('Servico');
return $this->setParams();
}else{
return false;
}
}
public function cidadeNome($id_pais,$id_estado,$id_cidade)
{
$this->debug = debug_backtrace();
if($this->getArgs(func_get_args())){
$this->params = array(
"IdPais" => $id_pais,
"IdEstado" => $id_estado,
"IdCidade" => $id_cidade
);
$this->setMetodo('Cidade');
return $this->setParams();
}else{
return false;
}
}
/**
* Metodo para abertura de Order de Servi<EFBFBD>o
*
* @param int $id_loja
* @param int $id_conta_receber
* @return boolean
*/
public function ordemServico($assunto, $mensagem, $idPessoa)
{
$this->debug = debug_backtrace();
if($this->getArgs(func_get_args())){
$this->params = array(
"IdLoja" => 1,
"IdProtocoloTipo" => 10006,
"Assunto" => utf8_encode($assunto),
"Mensagem" => utf8_encode($mensagem),
"EnviarSMS" => 1,
"EnviarEmail" => 1,
"IdPessoa" => $idPessoa,
"IdLocalAbertura" => 1
);
$this->setMetodo('OrdemServico');
return $this->setParams();
}else{
return false;
}
}
/**
* Metodo para desbloqueio
*
* @param int $id_loja
* @param int $id_conta_receber
* @return boolean
*/
public function confirmaPagamentoConsulta($id_pessoa)
{
$this->debug = debug_backtrace();
if($this->getArgs(func_get_args())){
$this->params = array(
"IdPessoa" => $id_pessoa
);
$this->setMetodo('ConfirmarPagamento');
return $this->setParams();
}else{
return false;
}
}
public function confirmaPagamentoCadastro($md5)
{
$this->debug = debug_backtrace();
if($this->getArgs(func_get_args())){
$this->params = array(
"MD5" => $md5
);
$this->setMetodo('ConfirmarPagamento');
$this->setTipoRequisicao('insert');
return $this->setParams();
}else{
return false;
}
}
########################################################################
## FUNCOES DEFAULT DA CLASSE ##
########################################################################
/**
* Coleta as informacoes iniciais para o inicio da integracao com a API.
*
* @param string $token
* @param string $url
* @param boolean $log
*/
public function __construct($token = CONF_TOKEN_API, $url = CONF_URL_API, $log = CONF_LOGGER_ATIVO) {
$this->token = $token;
if(end(str_split($url)) != '/'){
$url .= '/';
}
if (strpos($url, 'https')) {
$this->ssl = true;
}
$this->url = $url.'main.php/api/cnt-manager/';
$this->integracaoReg();
$this->setLog($log);
$this->log->info("Iniciando integracao", debug_backtrace());
}
/**
* Parametriza o metodo utilizado para a consulta.
*
* @param type $metodo
*/
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;
}
private function setTipoRequisicao($tipoRequisicao) {
return $this->tipoRequisicao .= $tipoRequisicao;
}
/**
* Constroi de forma dinamica a string para ser passada para a execucao do Curl
*
* @void
*/
private function curl() {
/*
* Final da linha para pegar os dados da variavel
*/
$this->curl = curl_init();
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curl, CURLOPT_VERBOSE, false);
curl_setopt($this->curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($this->curl, CURLOPT_USERPWD, 'api:' . $this->token);
curl_setopt($this->curl, CURLOPT_USERAGENT, 'cnt-manager/api');
curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, $this->ssl);
curl_setopt($this->curl, CURLOPT_HEADER, false);
curl_setopt($this->curl, CURLOPT_NOBODY, false);
$tipoRequisicao = (isset($this->tipoRequisicao)) ? $this->tipoRequisicao : 'fetch';
curl_setopt($this->curl, CURLOPT_URL, $this->url . $this->metodo . '/'. $tipoRequisicao);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $this->params);
$this->log->debug("Curl: {$this->curl}", debug_backtrace());
}
/**
* Recebe array de forma de indice e valor
*
* @example array("qtype" => 'test_api', "query" => '123', "oper" => '=')
*
* @obs sempre chamar a fun<EFBFBD><EFBFBD>o debug_backtrace() para ser dispon<EFBFBD>vel em log
*
* @param type $params
* @debug_track function debug_backtrace()
*/
private function setParams() {
$this->curl();
unset($this->params);
return $this->exec();
}
/**
* Recebe as informa<EFBFBD><EFBFBD>es e realiza a execucao da API
*
* @void
*/
private function exec() {
/**
* Caso tenha problema de requisi<EFBFBD><EFBFBD>o
*/
$content = curl_exec($this->curl);
if (curl_errno($this->curl)) {
$this->log->error(curl_error($this->curl), debug_backtrace());
curl_close($this->curl);
$this->audioError();
return false;
}
curl_close($this->curl);
return $this->response($content);
}
/**
* Prepara dos dados para ser transmitidos para o metodo a ser retornado a
* integracao.
*
* @return array
*/
private function response($data) {
$this->log->debug("Reponse API: " . print_r(json_decode($data,true), true), $this->debug);
if ($data) {
return json_decode($data,true);
} else {
return false;
}
}
}