@@ -40,6 +40,6 @@ |
||
40 | 40 | ) DEFAULT CHARSET=utf8"; |
41 | 41 | if(!$db->query($query)) |
42 | 42 | { |
43 | - throw new Exception($db->error($mysqli)); |
|
43 | + throw new Exception($db->error($mysqli)); |
|
44 | 44 | } |
45 | 45 |
@@ -2,94 +2,94 @@ |
||
2 | 2 | |
3 | 3 | class AccountData |
4 | 4 | { |
5 | - /** |
|
6 | - * @var string |
|
7 | - */ |
|
8 | - public $accessToken; |
|
9 | - /** |
|
10 | - * @var string |
|
11 | - */ |
|
12 | - public $expirationDate; |
|
13 | - /** |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - public $refreshToken; |
|
17 | - /** |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - public $distinctId; |
|
21 | - /** |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - public $deviceUid; |
|
25 | - /** |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function getAccessToken(): string |
|
29 | - { |
|
30 | - return $this->accessToken; |
|
31 | - } |
|
32 | - /** |
|
33 | - * @param string $accessToken |
|
34 | - */ |
|
35 | - public function setAccessToken(string $accessToken) |
|
36 | - { |
|
37 | - $this->accessToken = $accessToken; |
|
38 | - } |
|
39 | - /** |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function getExpirationDate(): string |
|
43 | - { |
|
44 | - return $this->expirationDate; |
|
45 | - } |
|
46 | - /** |
|
47 | - * @param string $expirationDate |
|
48 | - */ |
|
49 | - public function setExpirationDate(string $expirationDate) |
|
50 | - { |
|
51 | - $this->expirationDate = $expirationDate; |
|
52 | - } |
|
53 | - /** |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public function getRefreshToken(): string |
|
57 | - { |
|
58 | - return $this->refreshToken; |
|
59 | - } |
|
60 | - /** |
|
61 | - * @param string $refreshToken |
|
62 | - */ |
|
63 | - public function setRefreshToken(string $refreshToken) |
|
64 | - { |
|
65 | - $this->refreshToken = $refreshToken; |
|
66 | - } |
|
67 | - /** |
|
68 | - * @return string |
|
69 | - */ |
|
70 | - public function getDistinctId(): string |
|
71 | - { |
|
72 | - return $this->distinctId; |
|
73 | - } |
|
74 | - /** |
|
75 | - * @param string $distinctId |
|
76 | - */ |
|
77 | - public function setDistinctId(string $distinctId) |
|
78 | - { |
|
79 | - $this->distinctId = $distinctId; |
|
80 | - } |
|
81 | - /** |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function getDeviceUid(): string |
|
85 | - { |
|
86 | - return $this->deviceUid; |
|
87 | - } |
|
88 | - /** |
|
89 | - * @param string $deviceUid |
|
90 | - */ |
|
91 | - public function setDeviceUid(string $deviceUid) |
|
92 | - { |
|
93 | - $this->deviceUid = $deviceUid; |
|
94 | - } |
|
5 | + /** |
|
6 | + * @var string |
|
7 | + */ |
|
8 | + public $accessToken; |
|
9 | + /** |
|
10 | + * @var string |
|
11 | + */ |
|
12 | + public $expirationDate; |
|
13 | + /** |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + public $refreshToken; |
|
17 | + /** |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + public $distinctId; |
|
21 | + /** |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + public $deviceUid; |
|
25 | + /** |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function getAccessToken(): string |
|
29 | + { |
|
30 | + return $this->accessToken; |
|
31 | + } |
|
32 | + /** |
|
33 | + * @param string $accessToken |
|
34 | + */ |
|
35 | + public function setAccessToken(string $accessToken) |
|
36 | + { |
|
37 | + $this->accessToken = $accessToken; |
|
38 | + } |
|
39 | + /** |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function getExpirationDate(): string |
|
43 | + { |
|
44 | + return $this->expirationDate; |
|
45 | + } |
|
46 | + /** |
|
47 | + * @param string $expirationDate |
|
48 | + */ |
|
49 | + public function setExpirationDate(string $expirationDate) |
|
50 | + { |
|
51 | + $this->expirationDate = $expirationDate; |
|
52 | + } |
|
53 | + /** |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public function getRefreshToken(): string |
|
57 | + { |
|
58 | + return $this->refreshToken; |
|
59 | + } |
|
60 | + /** |
|
61 | + * @param string $refreshToken |
|
62 | + */ |
|
63 | + public function setRefreshToken(string $refreshToken) |
|
64 | + { |
|
65 | + $this->refreshToken = $refreshToken; |
|
66 | + } |
|
67 | + /** |
|
68 | + * @return string |
|
69 | + */ |
|
70 | + public function getDistinctId(): string |
|
71 | + { |
|
72 | + return $this->distinctId; |
|
73 | + } |
|
74 | + /** |
|
75 | + * @param string $distinctId |
|
76 | + */ |
|
77 | + public function setDistinctId(string $distinctId) |
|
78 | + { |
|
79 | + $this->distinctId = $distinctId; |
|
80 | + } |
|
81 | + /** |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function getDeviceUid(): string |
|
85 | + { |
|
86 | + return $this->deviceUid; |
|
87 | + } |
|
88 | + /** |
|
89 | + * @param string $deviceUid |
|
90 | + */ |
|
91 | + public function setDeviceUid(string $deviceUid) |
|
92 | + { |
|
93 | + $this->deviceUid = $deviceUid; |
|
94 | + } |
|
95 | 95 | } |
@@ -3,18 +3,18 @@ |
||
3 | 3 | |
4 | 4 | class GetKarma extends AbstractRequest { |
5 | 5 | |
6 | - function getApiEndPoint() |
|
7 | - { |
|
8 | - return '/v2/users/karma'; |
|
9 | - } |
|
10 | - function getPayload() |
|
11 | - { |
|
12 | - return array( |
|
13 | - ); |
|
14 | - } |
|
15 | - function getMethod() |
|
16 | - { |
|
17 | - return 'GET'; |
|
18 | - } |
|
6 | + function getApiEndPoint() |
|
7 | + { |
|
8 | + return '/v2/users/karma'; |
|
9 | + } |
|
10 | + function getPayload() |
|
11 | + { |
|
12 | + return array( |
|
13 | + ); |
|
14 | + } |
|
15 | + function getMethod() |
|
16 | + { |
|
17 | + return 'GET'; |
|
18 | + } |
|
19 | 19 | } |
20 | 20 |
@@ -3,37 +3,37 @@ |
||
3 | 3 | |
4 | 4 | class SetLocation extends AbstractRequest { |
5 | 5 | /** |
6 | - * @var Location |
|
7 | - */ |
|
8 | - public $location; |
|
9 | - /** |
|
10 | - * @return Location |
|
11 | - */ |
|
12 | - public function getLocation(): Location |
|
13 | - { |
|
14 | - return $this->location; |
|
15 | - } |
|
16 | - /** |
|
17 | - * @param Location $location |
|
18 | - */ |
|
19 | - public function setLocation(Location $location) |
|
20 | - { |
|
21 | - $this->location = $location; |
|
22 | - } |
|
6 | + * @var Location |
|
7 | + */ |
|
8 | + public $location; |
|
9 | + /** |
|
10 | + * @return Location |
|
11 | + */ |
|
12 | + public function getLocation(): Location |
|
13 | + { |
|
14 | + return $this->location; |
|
15 | + } |
|
16 | + /** |
|
17 | + * @param Location $location |
|
18 | + */ |
|
19 | + public function setLocation(Location $location) |
|
20 | + { |
|
21 | + $this->location = $location; |
|
22 | + } |
|
23 | 23 | |
24 | - function getApiEndPoint() |
|
25 | - { |
|
26 | - return '/v2/users/location'; |
|
27 | - } |
|
28 | - function getPayload() |
|
29 | - { |
|
30 | - return array( |
|
24 | + function getApiEndPoint() |
|
25 | + { |
|
26 | + return '/v2/users/location'; |
|
27 | + } |
|
28 | + function getPayload() |
|
29 | + { |
|
30 | + return array( |
|
31 | 31 | "location" => $this->getLocation()->toArray(), |
32 | - ); |
|
33 | - } |
|
34 | - function getMethod() |
|
35 | - { |
|
36 | - return 'PUT'; |
|
37 | - } |
|
32 | + ); |
|
33 | + } |
|
34 | + function getMethod() |
|
35 | + { |
|
36 | + return 'PUT'; |
|
37 | + } |
|
38 | 38 | } |
39 | 39 |
@@ -1,66 +1,66 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class CreateUser extends AbstractRequest { |
4 | - /** |
|
5 | - * @var Location |
|
6 | - */ |
|
7 | - public $location; |
|
8 | - public $deviceUid; |
|
9 | - /** |
|
10 | - * @return Location |
|
11 | - */ |
|
12 | - public function getLocation(): Location |
|
13 | - { |
|
14 | - return $this->location; |
|
15 | - } |
|
16 | - /** |
|
17 | - * @param Location $location |
|
18 | - */ |
|
19 | - public function setLocation(Location $location) |
|
20 | - { |
|
21 | - $this->location = $location; |
|
22 | - } |
|
23 | - public function getDeviceUid() |
|
24 | - { |
|
4 | + /** |
|
5 | + * @var Location |
|
6 | + */ |
|
7 | + public $location; |
|
8 | + public $deviceUid; |
|
9 | + /** |
|
10 | + * @return Location |
|
11 | + */ |
|
12 | + public function getLocation(): Location |
|
13 | + { |
|
14 | + return $this->location; |
|
15 | + } |
|
16 | + /** |
|
17 | + * @param Location $location |
|
18 | + */ |
|
19 | + public function setLocation(Location $location) |
|
20 | + { |
|
21 | + $this->location = $location; |
|
22 | + } |
|
23 | + public function getDeviceUid() |
|
24 | + { |
|
25 | 25 | return $this->deviceUid; |
26 | 26 | } |
27 | 27 | public function setDeviceUid($deviceUid) |
28 | - { |
|
28 | + { |
|
29 | 29 | $this->deviceUid = $deviceUid; |
30 | 30 | } |
31 | - public function generateDeviceUid() |
|
32 | - { |
|
33 | - return $this->random_str(64, 'abcdef0123456789'); |
|
34 | - } |
|
35 | - function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') |
|
36 | - { |
|
37 | - $str = ''; |
|
38 | - $max = mb_strlen($keyspace, '8bit') - 1; |
|
39 | - for ($i = 0; $i < $length; ++$i) { |
|
40 | - $str .= $keyspace[random_int(0, $max)]; |
|
41 | - } |
|
42 | - return $str; |
|
43 | - } |
|
44 | - function getApiEndPoint() |
|
45 | - { |
|
46 | - return '/v2/users'; |
|
47 | - } |
|
48 | - function getPayload() |
|
49 | - { |
|
31 | + public function generateDeviceUid() |
|
32 | + { |
|
33 | + return $this->random_str(64, 'abcdef0123456789'); |
|
34 | + } |
|
35 | + function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') |
|
36 | + { |
|
37 | + $str = ''; |
|
38 | + $max = mb_strlen($keyspace, '8bit') - 1; |
|
39 | + for ($i = 0; $i < $length; ++$i) { |
|
40 | + $str .= $keyspace[random_int(0, $max)]; |
|
41 | + } |
|
42 | + return $str; |
|
43 | + } |
|
44 | + function getApiEndPoint() |
|
45 | + { |
|
46 | + return '/v2/users'; |
|
47 | + } |
|
48 | + function getPayload() |
|
49 | + { |
|
50 | 50 | if(!isset($this->deviceUid)) |
51 | 51 | { |
52 | 52 | $this->setDeviceUid($this->generateDeviceUid()); |
53 | 53 | } |
54 | 54 | echo $this->getDeviceUid(); |
55 | - echo "<br>"; |
|
55 | + echo "<br>"; |
|
56 | 56 | return array( |
57 | 57 | "location" => $this->getLocation()->toArray(), |
58 | 58 | "client_id" => self::CLIENTID, |
59 | 59 | "device_uid" => $this->getDeviceUid(), |
60 | 60 | ); |
61 | - } |
|
62 | - function getMethod() |
|
63 | - { |
|
64 | - return 'POST'; |
|
65 | - } |
|
61 | + } |
|
62 | + function getMethod() |
|
63 | + { |
|
64 | + return 'POST'; |
|
65 | + } |
|
66 | 66 | } |
@@ -5,20 +5,20 @@ discard block |
||
5 | 5 | { |
6 | 6 | public $lastPostId; |
7 | 7 | |
8 | - public $url; |
|
8 | + public $url; |
|
9 | 9 | |
10 | - function setUrl ($url) |
|
11 | - { |
|
12 | - $this->url = $url; |
|
13 | - } |
|
10 | + function setUrl ($url) |
|
11 | + { |
|
12 | + $this->url = $url; |
|
13 | + } |
|
14 | 14 | |
15 | - function getUrl () |
|
16 | - { |
|
17 | - return $this->url; |
|
18 | - } |
|
15 | + function getUrl () |
|
16 | + { |
|
17 | + return $this->url; |
|
18 | + } |
|
19 | 19 | |
20 | - function setLastPostId ($lastPostId) |
|
21 | - { |
|
20 | + function setLastPostId ($lastPostId) |
|
21 | + { |
|
22 | 22 | $this->lastPostId = $lastPostId; |
23 | 23 | } |
24 | 24 | |
@@ -27,22 +27,22 @@ discard block |
||
27 | 27 | return $this->lastPostId; |
28 | 28 | } |
29 | 29 | |
30 | - function getApiEndPoint() |
|
31 | - { |
|
32 | - $apiEndPoint = $this->getUrl(); |
|
33 | - //echo $GLOBALS['lastPostId']; |
|
34 | - if ($this->getLastPostId() != "") { |
|
30 | + function getApiEndPoint() |
|
31 | + { |
|
32 | + $apiEndPoint = $this->getUrl(); |
|
33 | + //echo $GLOBALS['lastPostId']; |
|
34 | + if ($this->getLastPostId() != "") { |
|
35 | 35 | $apiEndPoint = $this->getUrl() . '/location/?after=' . $this->getLastPostId(); |
36 | 36 | } |
37 | - return $apiEndPoint; |
|
38 | - } |
|
39 | - function getPayload() |
|
40 | - { |
|
41 | - return array( |
|
42 | - ); |
|
43 | - } |
|
44 | - function getMethod() |
|
45 | - { |
|
46 | - return 'GET'; |
|
47 | - } |
|
37 | + return $apiEndPoint; |
|
38 | + } |
|
39 | + function getPayload() |
|
40 | + { |
|
41 | + return array( |
|
42 | + ); |
|
43 | + } |
|
44 | + function getMethod() |
|
45 | + { |
|
46 | + return 'GET'; |
|
47 | + } |
|
48 | 48 | } |
@@ -3,19 +3,19 @@ |
||
3 | 3 | |
4 | 4 | class Upvote extends AbstractRequest { |
5 | 5 | |
6 | - function getApiEndPoint() |
|
7 | - { |
|
8 | - return '/v2/posts/' . $_GET['postID'] . '/upvote'; |
|
9 | - } |
|
10 | - function getPayload() |
|
11 | - { |
|
12 | - return array( |
|
6 | + function getApiEndPoint() |
|
7 | + { |
|
8 | + return '/v2/posts/' . $_GET['postID'] . '/upvote'; |
|
9 | + } |
|
10 | + function getPayload() |
|
11 | + { |
|
12 | + return array( |
|
13 | 13 | "reason_code" => -1, |
14 | - ); |
|
15 | - } |
|
16 | - function getMethod() |
|
17 | - { |
|
18 | - return 'PUT'; |
|
19 | - } |
|
14 | + ); |
|
15 | + } |
|
16 | + function getMethod() |
|
17 | + { |
|
18 | + return 'PUT'; |
|
19 | + } |
|
20 | 20 | } |
21 | 21 |
@@ -2,19 +2,19 @@ discard block |
||
2 | 2 | |
3 | 3 | abstract class AbstractRequest |
4 | 4 | { |
5 | - CONST CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
6 | - CONST APIURL = 'https://api.go-tellm.com/api'; |
|
7 | - const SECRET = "VwJHzYUbPjGiXWauoVNaHoCWsaacTmnkGwNtHhjy"; |
|
8 | - const USERAGENT = "Jodel/4.27.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )"; |
|
9 | - const CLIENT_TYPE = 'android_4.27.1'; |
|
5 | + CONST CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
6 | + CONST APIURL = 'https://api.go-tellm.com/api'; |
|
7 | + const SECRET = "VwJHzYUbPjGiXWauoVNaHoCWsaacTmnkGwNtHhjy"; |
|
8 | + const USERAGENT = "Jodel/4.27.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )"; |
|
9 | + const CLIENT_TYPE = 'android_4.27.1'; |
|
10 | 10 | |
11 | - /** |
|
12 | - * @var string |
|
13 | - */ |
|
14 | - public $accessToken = null; |
|
15 | - private $payLoad; |
|
16 | - public function execute() |
|
17 | - { |
|
11 | + /** |
|
12 | + * @var string |
|
13 | + */ |
|
14 | + public $accessToken = null; |
|
15 | + private $payLoad; |
|
16 | + public function execute() |
|
17 | + { |
|
18 | 18 | $result = new \stdClass(); |
19 | 19 | |
20 | 20 | $this->payLoad = $this->getPayload(); |
@@ -24,71 +24,71 @@ discard block |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | |
27 | - $this->payLoad = json_encode($this->payLoad); |
|
28 | - $header = $this->getSignHeaders(); |
|
29 | - $url = $this->getFullUrl(); |
|
27 | + $this->payLoad = json_encode($this->payLoad); |
|
28 | + $header = $this->getSignHeaders(); |
|
29 | + $url = $this->getFullUrl(); |
|
30 | 30 | |
31 | - if ($this->getAccessToken()) { |
|
32 | - $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
33 | - } |
|
34 | - //Comment out to debug the Request: |
|
35 | - /* |
|
31 | + if ($this->getAccessToken()) { |
|
32 | + $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
33 | + } |
|
34 | + //Comment out to debug the Request: |
|
35 | + /* |
|
36 | 36 | var_dump($url); |
37 | 37 | var_dump($header); |
38 | 38 | var_dump($this->payLoad); |
39 | 39 | */ |
40 | 40 | |
41 | 41 | |
42 | - switch ($this->getMethod()) { |
|
43 | - case 'POST': |
|
44 | - $result = Requests::post($url, $header, $this->payLoad); |
|
45 | - break; |
|
46 | - case 'GET': |
|
47 | - $result = Requests::get($url, $header); |
|
48 | - break; |
|
49 | - case 'PUT': |
|
50 | - $result = Requests::put($url, $header, $this->payLoad); |
|
51 | - break; |
|
52 | - } |
|
53 | - switch ($result->status_code) { |
|
54 | - case 200: |
|
55 | - $result = json_decode($result->body, true); |
|
56 | - break; |
|
57 | - case 204: |
|
58 | - $result = "Success"; |
|
59 | - break; |
|
60 | - case 401: |
|
42 | + switch ($this->getMethod()) { |
|
43 | + case 'POST': |
|
44 | + $result = Requests::post($url, $header, $this->payLoad); |
|
45 | + break; |
|
46 | + case 'GET': |
|
47 | + $result = Requests::get($url, $header); |
|
48 | + break; |
|
49 | + case 'PUT': |
|
50 | + $result = Requests::put($url, $header, $this->payLoad); |
|
51 | + break; |
|
52 | + } |
|
53 | + switch ($result->status_code) { |
|
54 | + case 200: |
|
55 | + $result = json_decode($result->body, true); |
|
56 | + break; |
|
57 | + case 204: |
|
58 | + $result = "Success"; |
|
59 | + break; |
|
60 | + case 401: |
|
61 | 61 | throw new \Exception('Unauthorized'); |
62 | - break; |
|
63 | - case 404: |
|
64 | - echo "Es wurde bereits gevoted"; |
|
62 | + break; |
|
63 | + case 404: |
|
64 | + echo "Es wurde bereits gevoted"; |
|
65 | 65 | case 477: |
66 | - echo "Es wurde bereits gevoted"; |
|
67 | - throw new \Exception('Signing failed!'); |
|
68 | - break; |
|
69 | - default: |
|
70 | - throw new \Exception('Unknown Error: '.$result->status_code); |
|
71 | - } |
|
66 | + echo "Es wurde bereits gevoted"; |
|
67 | + throw new \Exception('Signing failed!'); |
|
68 | + break; |
|
69 | + default: |
|
70 | + throw new \Exception('Unknown Error: '.$result->status_code); |
|
71 | + } |
|
72 | 72 | |
73 | - if($device_uid != "") |
|
74 | - { |
|
73 | + if($device_uid != "") |
|
74 | + { |
|
75 | 75 | $result[0] = $result; |
76 | 76 | $result[1] = $device_uid; |
77 | 77 | } |
78 | 78 | |
79 | - /* |
|
79 | + /* |
|
80 | 80 | var_dump($result); |
81 | 81 | */ |
82 | 82 | |
83 | - return $result; |
|
84 | - } |
|
85 | - abstract function getPayload(); |
|
86 | - /** |
|
87 | - * Gets Sign headers |
|
88 | - * @return array headers |
|
89 | - */ |
|
90 | - public function getSignHeaders() |
|
91 | - { |
|
83 | + return $result; |
|
84 | + } |
|
85 | + abstract function getPayload(); |
|
86 | + /** |
|
87 | + * Gets Sign headers |
|
88 | + * @return array headers |
|
89 | + */ |
|
90 | + public function getSignHeaders() |
|
91 | + { |
|
92 | 92 | $payload_accessToken; |
93 | 93 | if($this->getAccessToken() == null) { |
94 | 94 | $payload_accessToken = ""; |
@@ -98,54 +98,54 @@ discard block |
||
98 | 98 | } |
99 | 99 | |
100 | 100 | |
101 | - $headers = array( |
|
102 | - "Connection" => "keep-alive", |
|
103 | - "Accept-Encoding" => "gzip", |
|
104 | - "Content-Type" => "application/json; charset=UTF-8", |
|
105 | - "User-Agent" => self::USERAGENT |
|
106 | - ); |
|
107 | - $timestamp = new DateTime(); |
|
108 | - $timestamp = $timestamp->format(DateTime::ATOM); |
|
109 | - $timestamp = substr($timestamp, 0, -6); |
|
110 | - $timestamp .= "Z"; |
|
111 | - $urlParts = parse_url($this->getFullUrl()); |
|
112 | - $url2 = ""; |
|
113 | - $req = [$this->getMethod(), |
|
114 | - $urlParts['host'], |
|
115 | - "443", |
|
116 | - $urlParts['path'], |
|
117 | - $payload_accessToken, |
|
118 | - $timestamp, |
|
119 | - $url2, |
|
120 | - $this->payLoad]; |
|
121 | - $reqString = implode("%", $req); |
|
122 | - $secret = self::SECRET; |
|
123 | - $signature = hash_hmac('sha1', $reqString, $secret); |
|
124 | - $signature = strtoupper($signature); |
|
125 | - $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
126 | - $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
127 | - $headers['X-Timestamp'] = $timestamp; |
|
128 | - $headers['X-Api-Version'] = '0.2'; |
|
129 | - return $headers; |
|
130 | - } |
|
131 | - public function getFullUrl() |
|
132 | - { |
|
133 | - return self::APIURL . $this->getApiEndPoint(); |
|
134 | - } |
|
135 | - abstract function getApiEndPoint(); |
|
136 | - abstract function getMethod(); |
|
137 | - /** |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public function getAccessToken() |
|
141 | - { |
|
142 | - return $this->accessToken; |
|
143 | - } |
|
144 | - /** |
|
145 | - * @param string $accessToken |
|
146 | - */ |
|
147 | - public function setAccessToken(string $accessToken) |
|
148 | - { |
|
149 | - $this->accessToken = $accessToken; |
|
150 | - } |
|
101 | + $headers = array( |
|
102 | + "Connection" => "keep-alive", |
|
103 | + "Accept-Encoding" => "gzip", |
|
104 | + "Content-Type" => "application/json; charset=UTF-8", |
|
105 | + "User-Agent" => self::USERAGENT |
|
106 | + ); |
|
107 | + $timestamp = new DateTime(); |
|
108 | + $timestamp = $timestamp->format(DateTime::ATOM); |
|
109 | + $timestamp = substr($timestamp, 0, -6); |
|
110 | + $timestamp .= "Z"; |
|
111 | + $urlParts = parse_url($this->getFullUrl()); |
|
112 | + $url2 = ""; |
|
113 | + $req = [$this->getMethod(), |
|
114 | + $urlParts['host'], |
|
115 | + "443", |
|
116 | + $urlParts['path'], |
|
117 | + $payload_accessToken, |
|
118 | + $timestamp, |
|
119 | + $url2, |
|
120 | + $this->payLoad]; |
|
121 | + $reqString = implode("%", $req); |
|
122 | + $secret = self::SECRET; |
|
123 | + $signature = hash_hmac('sha1', $reqString, $secret); |
|
124 | + $signature = strtoupper($signature); |
|
125 | + $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
126 | + $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
127 | + $headers['X-Timestamp'] = $timestamp; |
|
128 | + $headers['X-Api-Version'] = '0.2'; |
|
129 | + return $headers; |
|
130 | + } |
|
131 | + public function getFullUrl() |
|
132 | + { |
|
133 | + return self::APIURL . $this->getApiEndPoint(); |
|
134 | + } |
|
135 | + abstract function getApiEndPoint(); |
|
136 | + abstract function getMethod(); |
|
137 | + /** |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public function getAccessToken() |
|
141 | + { |
|
142 | + return $this->accessToken; |
|
143 | + } |
|
144 | + /** |
|
145 | + * @param string $accessToken |
|
146 | + */ |
|
147 | + public function setAccessToken(string $accessToken) |
|
148 | + { |
|
149 | + $this->accessToken = $accessToken; |
|
150 | + } |
|
151 | 151 | } |
@@ -3,18 +3,18 @@ |
||
3 | 3 | |
4 | 4 | class GetPostDetails extends AbstractRequest { |
5 | 5 | |
6 | - function getApiEndPoint() |
|
7 | - { |
|
8 | - return '/v2/posts/' . $_GET['postID']; |
|
9 | - } |
|
10 | - function getPayload() |
|
11 | - { |
|
12 | - return array( |
|
13 | - ); |
|
14 | - } |
|
15 | - function getMethod() |
|
16 | - { |
|
17 | - return 'GET'; |
|
18 | - } |
|
6 | + function getApiEndPoint() |
|
7 | + { |
|
8 | + return '/v2/posts/' . $_GET['postID']; |
|
9 | + } |
|
10 | + function getPayload() |
|
11 | + { |
|
12 | + return array( |
|
13 | + ); |
|
14 | + } |
|
15 | + function getMethod() |
|
16 | + { |
|
17 | + return 'GET'; |
|
18 | + } |
|
19 | 19 | } |
20 | 20 |