-
Notifications
You must be signed in to change notification settings - Fork 8
/
consulta_token.php
75 lines (61 loc) · 1.68 KB
/
consulta_token.php
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
<?php
/** ARQUIVO DE CONSULTA DE TOKEN **/
class ConsultaToken {
private $token;
private $url;
private $client_id;
private $client_secret;
/**
* metodo de inicialização
**/
public function __construct($tipo_ambiente, $client_secret, $client_id) {
$this->client_secret = $client_secret;
$this->client_id = $client_id;
//setando o tipo do ambiente
if($tipo_ambiente = 1) {
//ambiente desenvolvimento
$this->url = 'https://oauth.itau.com.br/identity/connect/token';
}else if($tipo_ambiente = 2) {
//ambiente produção
$this->url = "https://autorizador-boletos.itau.com.br";
}else {
return json_encode(false);
}
//consultando token
$this->getRequestToken();
}
public function getRequestToken() {
try {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "scope=readonly&grant_type=client_credentials&client_id=" . $this->client_id . "&client_secret=" . $this->client_secret,
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error # Token:" . $err;
} else {
$this->setToken(json_decode($response));
}
} catch (Exception $e) {
}
}
public function getToken() {
return $this->token;
}
public function setToken($token) {
$this->token = $token;
}
}