MdEstatisticasEnviarRN.php
4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?
require_once dirname(__FILE__) . '/../../../SEI.php';
class MdEstatisticasEnviarRN extends InfraRN
{
public function __construct() {
parent::__construct();
$objConfiguracaoSEI = ConfiguracaoSEI::getInstance();
$url = $objConfiguracaoSEI->getValor('MdEstatisticas', 'url', false, 'http://estatisticas.planejamento.gov.br');
$this->url = $url . '/api/estatisticas';
$this->urllogin = $url . '/login';
$this->orgaoSigla = $objConfiguracaoSEI->getValor('MdEstatisticas', 'sigla', false, '');
$this->orgaoSenha = $objConfiguracaoSEI->getValor('MdEstatisticas', 'chave', false, '');
$this->header = array('Content-Type: application/json');
}
protected function inicializarObjInfraIBanco() {
return BancoSEI::getInstance();
}
public function enviarIndicadores($indicadores) {
return $this->doPost($this->url, $indicadores);
}
public function obterUltimoAcesso() {
$data = $this->doGet($this->url . '/acessos/ultimo?sigla=' . $this->orgaoSigla, false);
return date($data);
}
public function obterUltimoRecurso() {
$data = $this->doGet($this->url . '/recursos/ultimo?sigla=' . $this->orgaoSigla, false);
return date($data);
}
public function enviarAcessos($acessos, $id) {
$url = $this->url . '/acessos';
$obj = array(
id => $id,
acessosUsuarios => $acessos
);
return $this->doPost($url, $obj, false);
}
public function enviarVelocidades($velocidades, $id) {
$url = $this->url . '/velocidades';
$obj = array(
id => $id,
velocidades => $velocidades
);
return $this->doPost($url, $obj, false);
}
public function enviarSistemasUsuarios($sistemasOperacionaisUsuarios, $id) {
$url = $this->url . '/sistemasoperacionais';
$obj = array(
id => $id,
sistemasOperacionaisUsuarios => $sistemasOperacionaisUsuarios
);
return $this->doPost($url, $obj, false);
}
public function enviarNavegadores($navegadores, $id) {
$url = $this->url . '/navegadores';
$obj = array(
id => $id,
navegadores => $navegadores
);
return $this->doPost($url, $obj, false);
}
public function enviarLogsErro($logs, $id) {
$url = $this->url . '/logserro';
$obj = array(
id => $id,
logsErro => $logs
);
return $this->doPost($url, $obj, false);
}
public function enviarRecursos($recursos, $id) {
$url = $this->url . '/recursos';
$obj = array(
id => $id,
recursos => $recursos
);
return $this->doPost($url, $obj, false);
}
public function autenticar() {
$json = array(
username => $this->orgaoSigla,
password => $this->orgaoSenha
);
$data = json_encode($json);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->urllogin);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, true);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] == 200) {
$output = explode("\r\n", $output);
foreach ($output as $value) {
if (strpos($value, 'Authorization') !== false) {
$this->header[] = $value;
return true;
}
}
}
return false;
}
private function doPost($url, $json, $isjson = true) {
$data = json_encode($json);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);
if ($isjson) {
return json_decode($output, true);
}
return $output;
}
private function doGet($url, $isjson = true) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header);
curl_setopt($ch, CURLOPT_URL, $url);
$output = curl_exec($ch);
curl_close($ch);
if ($isjson) {
return json_decode($output, true);
}
return $output;
}
}
?>