base_url = $base_url; $this->app_id = $app_id; $this->app_key = $app_key; $this->api_level = $api_level; } public function setApiBaseUrl($base_url) { $this->base_url = $base_url; } public function setAppId($app_id) { $this->app_id = $app_id; } public function setAppKey($app_key) { $this->app_key = $app_key; } public function setApiLevel($api_level) { $this->api_level = $api_level; } private function getOtp() { return sha1(date('YmdHis')); } private function getApiHash($url, $otp) { return sha1( $url . $this->app_key . $otp ); } private function go($url, $post = '') { if (empty($post)) $post = array(); $otp = $this->getOtp(); $api_hash = $this->getApiHash($url, $otp); $post['levelapi'] = $this->api_level; $post['idapi'] = $this->app_id; $post['otpapi'] = $otp; $post['authapi'] = $api_hash; $consumer = curl_init(); curl_setopt($consumer, CURLOPT_URL, $this->base_url . $url); curl_setopt($consumer, CURLOPT_HEADER, 0); curl_setopt($consumer, CURLOPT_POST, 1); curl_setopt($consumer, CURLOPT_RETURNTRANSFER, 1); curl_setopt($consumer, CURLOPT_POSTFIELDS, $post); curl_setopt($consumer, CURLOPT_SSL_VERIFYPEER, 0); $json = curl_exec($consumer); if (curl_errno($consumer)) { $response = '[AuthConsumer] Erro de acesso ao WebService: ' . curl_error($consumer); curl_close($consumer); return $response; } return $json; } public function servidorUid($uid) { $url = '/servidor/listar/uid/' . $uid; return $this->go($url); } public function servidorMatricula($matricula) { $url = '/servidor/listar/matricula/' . $matricula; return $this->go($url); } public function servidorSetor(array $setores) { $lista_setores = implode(',', $setores); $url = '/servidor/listar/setor/' . $lista_setores; return $this->go($url); } public function ausenciaMatricula($matricula, $data_inicial, $data_final) { $url = '/servidor/listar-ausencias-legais/' . $matricula . '/' . $data_inicial . '/' . $data_final; return $this->go($url); } public function autenticar($usuario, $senha) { $post = array( 'password' => base64_encode($senha), ); $url = '/servidor/autenticar/' . $usuario; return $this->go($url, $post); } public function setorNome($parte_nome) { $url = '/setor/listar/' . $parte_nome; return $this->go($url); } public function setor($codigos) { $lista_codigos = implode(',', $codigos); $url = '/setor/obter/' . $lista_codigos; return $this->go($url); } public function comarcaEntrancia($entrancia) { $url = '/comarca/listar/por-entrancia/'. $entrancia; return $this->go($url); } }