request = new RequestURL(); $this->setToken(); $this->setUrl(CONF_WHATSAPP_AUTH_URL); } function response($result) { if ($result) { if (json_decode($result, true) !== null) { return json_decode($result, true); } return $result; } else { return false; } } function exec($typeAuth = 'Bearer') { $this->setQuery(json_encode($this->params)); //SET QUERY $this->request->setUrl($this->url . $this->metodo, false); $header = array(); $header[] = "Authorization: $typeAuth {$this->token}"; if ($this->requestType == 'POST') { $header[] = 'Content-Type: application/json'; $this->request->post_field($this->getQuery(), true); } $this->request->header($header); $this->request->method_request($this->requestType); logger('request')->info(print_r($header, true)); logger('request')->info($this->requestType); return $this->request->exec_request(); } /** * Recebe o tipo de Requisi��o GET/POST * * @return boolean */ function requestType($req = null) { if (!$req) { return $this->requestType; } if (strtoupper($req) == "GET") { return $this->requestType = "GET"; } else if (strtoupper($req) == "POST") { return $this->requestType = "POST"; } } /** * Verifica se todos os parametros passados foram completados. * * @param array $args * @return true|false */ function getArgs($args) { foreach ($args as $value) { if (!$value) { return false; } } return true; } function setMetodo($metodo) { $this->metodo = $metodo; } /** * Escreve a query para ser passada para o curl * * @param string $query */ function setQuery($query) { return $this->query .= $query; } /** * retorna a string pronta da query do curl e limpa a variavel. * * @return string $query */ function getQuery() { $query = $this->query; unset($this->query); return $query; } function setToken($token = CONF_WHATSAPP_AUTH_TOKEN) { $this->token = $token; } public function setUrl($url) { $this->url = $url; } }