From d3979a64f11ad78739846caecbc664f962b80a02 Mon Sep 17 00:00:00 2001 From: awade Date: Thu, 9 Feb 2023 14:42:35 -0400 Subject: [PATCH] ipcall --- IPCall/IPCall.php | 169 ++++++++++++++++++++++++++++++++++++++ IPCall/enviarSMS.php | 19 +++++ IPCall/gerarProtocolo.php | 27 ++++++ IPCall/smsteste.php | 8 ++ IPCall/teste.php | 11 +++ 5 files changed, 234 insertions(+) create mode 100644 IPCall/IPCall.php create mode 100644 IPCall/enviarSMS.php create mode 100644 IPCall/gerarProtocolo.php create mode 100644 IPCall/smsteste.php create mode 100644 IPCall/teste.php diff --git a/IPCall/IPCall.php b/IPCall/IPCall.php new file mode 100644 index 0000000..ca405f7 --- /dev/null +++ b/IPCall/IPCall.php @@ -0,0 +1,169 @@ +debug = debug_backtrace(); + if ($this->getArgs(func_get_args())) { + $this->params['cliente'] = $empresa; + $this->setMetodo('blank_gerador_protocolo'); + return $this->setParams(); + } else { + return false; + } + } + + public function sendsms($cliente, $numero, $protocolo){ + $this->debug = debug_backtrace(); + if ($this->getArgs(func_get_args())) { + $this->params['cliente'] = $cliente; + $this->params['numero'] = $numero; + $this->params['protocolo'] = $protocolo; + $this->setMetodo('api_sms_pbx'); + 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() { + $this->url = CONF_URL_API; + $this->setLog(CONF_LOGGER_ATIVO); + $this->integracaoReg(); + $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; + } + + /** + * Informa o tipo de requisicao que sera feita pela cURL + * @param bool $request + */ + private function request($request = null) { + + } + + /** + * Constroi de forma dinamica a string para ser passada para a execucao do Curl + * + * @void + */ + private function curl() { + $this->curl = curl_init(); + curl_setopt($this->curl, CURLOPT_URL, $this->url . "/" . $this->metodo . "/"); + curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($this->curl, CURLOPT_POST, true); + curl_setopt($this->curl, CURLOPT_POSTFIELDS, $this->params); + /* + * Final da linha para pegar os dados da variavel + */ + $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 funcoes debug_backtrace() para ser disponivel em log + * + * @param type $params + * @debug_track function debug_backtrace() + */ + private function setParams() { + $this->params = http_build_query($this->params); + $this->curl(); + unset($this->params); + return $this->exec(); + } + + /** + * Recebe as informacoes e realiza a execucao da API + * + * @void + */ + private function exec() { + /** + * Caso tenha problema de requisicao + */ + $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($data, true), $this->debug); + if ($data) { + return json_decode($data, true); + } else { + return false; + } + } + + } + \ No newline at end of file diff --git a/IPCall/enviarSMS.php b/IPCall/enviarSMS.php new file mode 100644 index 0000000..799fc84 --- /dev/null +++ b/IPCall/enviarSMS.php @@ -0,0 +1,19 @@ +get_variable('PROTOCOLO_ANS', true); +$clientid = $agi->get_variable('CLIENTID', true); + +$ipcall->log()->debug("enviarSMS | " . print_r([ + 'protocolo' => $protocolo, + 'clientid' => $clientid +], true)); + +if($protocolo && $clientid){ + $ipcall->sendsms($clientid, $numero, $protocolo); +} + +?> \ No newline at end of file diff --git a/IPCall/gerarProtocolo.php b/IPCall/gerarProtocolo.php new file mode 100644 index 0000000..729a194 --- /dev/null +++ b/IPCall/gerarProtocolo.php @@ -0,0 +1,27 @@ +agi()->get_variable('NOMENCLATURA', true); + +$resp = $ipcall->db()->getServiceByUniqueid($uid); + +if($resp['serv_id']){ + $protocolo = $ipcall->gerarProtocolo($resp['serv_id']); + + $ipcall->agi()->set_variable('PROTOCOLO_ANS', $protocolo["protocolo_ans"]); + $ipcall->agi()->set_variable('CLIENTID', $resp['serv_id']); + + if($protocolo['codigo'] == '200'){ + $redirecionamento_dados = $ipcall->db()->redirectUraDestino("REDIR_PROTOCOLO_ANS", "SUCESSO", $nomenclatura); + }else { + $redirecionamento_dados = $ipcall->db()->redirectUraDestino("REDIR_PROTOCOLO_ANS", "FALHA", $nomenclatura); + } +} else { + $redirecionamento_dados = $ipcall->db()->redirectUraDestino("REDIR_PROTOCOLO_ANS", "OUTRO", $nomenclatura); +} + +$ipcall->executarFluxo($redirecionamento_dados["TIPO"], $redirecionamento_dados["NOME"]); + +?> \ No newline at end of file diff --git a/IPCall/smsteste.php b/IPCall/smsteste.php new file mode 100644 index 0000000..8a63146 --- /dev/null +++ b/IPCall/smsteste.php @@ -0,0 +1,8 @@ +sendsms('2', '83988166902', '1234567890'); + +?> \ No newline at end of file diff --git a/IPCall/teste.php b/IPCall/teste.php new file mode 100644 index 0000000..55c486f --- /dev/null +++ b/IPCall/teste.php @@ -0,0 +1,11 @@ +agi()->get_variable('NOMENCLATURA', true); +$resp = $ipcall->gerarProtocolo(2); + +print_r($resp); + +?> \ No newline at end of file