forked from blueseashore/hwpush
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGetAccessToken.php
55 lines (48 loc) · 1.31 KB
/
GetAccessToken.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
<?php
/**
* HwPush获取通信令牌类
*/
namespace hwpush;
class GetAccessToken extends Message
{
protected static $_instance;
private function __construct()
{
}
private function __clone()
{
// TODO: Implement __clone() method.
}
public static function getInstance()
{
if (!self::$_instance instanceof self) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* 获取access_token
*
* @return bool|string
*/
public function get()
{
$ch = curl_init(self::BASE_LOGIN_URL . '/oauth2/v2/token');
$data = [
'grant_type' => self::GRANT_TYPE,
'client_secret' => $this->clientSecret,
'client_id' => $this->clientId,
];
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//// 跳过证书检查
curl_setopt($ch, CURLOPT_TIMEOUT, 3600);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/x-www-form-urlencoded',
]);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}