@@ -2,18 +2,18 @@ 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 = "dIHNtHWOxFmoFouufSflpTKYjPmCIhWUCQHgbNzR"; |
|
8 | - const USERAGENT = "Jodel/4.28.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )"; |
|
9 | - const CLIENT_TYPE = 'android_4.29.1'; |
|
5 | + CONST CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
6 | + CONST APIURL = 'https://api.go-tellm.com/api'; |
|
7 | + const SECRET = "dIHNtHWOxFmoFouufSflpTKYjPmCIhWUCQHgbNzR"; |
|
8 | + const USERAGENT = "Jodel/4.28.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )"; |
|
9 | + const CLIENT_TYPE = 'android_4.29.1'; |
|
10 | 10 | |
11 | - private $accessToken = null; |
|
12 | - private $payLoad; |
|
13 | - public $expects = ""; |
|
11 | + private $accessToken = null; |
|
12 | + private $payLoad; |
|
13 | + public $expects = ""; |
|
14 | 14 | |
15 | - public function execute() |
|
16 | - { |
|
15 | + public function execute() |
|
16 | + { |
|
17 | 17 | $result = new \stdClass(); |
18 | 18 | |
19 | 19 | $this->payLoad = $this->getPayload(); |
@@ -23,71 +23,71 @@ discard block |
||
23 | 23 | } |
24 | 24 | |
25 | 25 | |
26 | - $this->payLoad = json_encode($this->payLoad); |
|
27 | - $header = $this->getSignHeaders(); |
|
28 | - $url = $this->getFullUrl(); |
|
26 | + $this->payLoad = json_encode($this->payLoad); |
|
27 | + $header = $this->getSignHeaders(); |
|
28 | + $url = $this->getFullUrl(); |
|
29 | 29 | |
30 | - if ($this->getAccessToken()) { |
|
31 | - $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
32 | - } |
|
33 | - //Comment out to debug the Request: |
|
34 | - /* |
|
30 | + if ($this->getAccessToken()) { |
|
31 | + $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
32 | + } |
|
33 | + //Comment out to debug the Request: |
|
34 | + /* |
|
35 | 35 | var_dump($url); |
36 | 36 | var_dump($header); |
37 | 37 | var_dump($this->payLoad); |
38 | 38 | */ |
39 | 39 | |
40 | 40 | |
41 | - switch ($this->getMethod()) { |
|
42 | - case 'POST': |
|
43 | - $result = Requests::post($url, $header, $this->payLoad); |
|
44 | - break; |
|
45 | - case 'GET': |
|
46 | - $result = Requests::get($url, $header); |
|
47 | - break; |
|
48 | - case 'PUT': |
|
49 | - $result = Requests::put($url, $header, $this->payLoad); |
|
50 | - break; |
|
51 | - } |
|
52 | - switch ($result->status_code) { |
|
53 | - case 200: |
|
54 | - $result = json_decode($result->body, true); |
|
55 | - break; |
|
56 | - case 204: |
|
57 | - $result = "Success"; |
|
58 | - break; |
|
59 | - case 401: |
|
41 | + switch ($this->getMethod()) { |
|
42 | + case 'POST': |
|
43 | + $result = Requests::post($url, $header, $this->payLoad); |
|
44 | + break; |
|
45 | + case 'GET': |
|
46 | + $result = Requests::get($url, $header); |
|
47 | + break; |
|
48 | + case 'PUT': |
|
49 | + $result = Requests::put($url, $header, $this->payLoad); |
|
50 | + break; |
|
51 | + } |
|
52 | + switch ($result->status_code) { |
|
53 | + case 200: |
|
54 | + $result = json_decode($result->body, true); |
|
55 | + break; |
|
56 | + case 204: |
|
57 | + $result = "Success"; |
|
58 | + break; |
|
59 | + case 401: |
|
60 | 60 | throw new \Exception('Unauthorized'); |
61 | - break; |
|
62 | - case 404: |
|
63 | - //echo "Es wurde bereits gevoted"; |
|
61 | + break; |
|
62 | + case 404: |
|
63 | + //echo "Es wurde bereits gevoted"; |
|
64 | 64 | case 477: |
65 | - //echo "Es wurde bereits gevoted"; |
|
66 | - //throw new \Exception('Signing failed!'); |
|
67 | - break; |
|
68 | - default: |
|
69 | - throw new \Exception('Unknown Error: '.$result->status_code); |
|
70 | - } |
|
65 | + //echo "Es wurde bereits gevoted"; |
|
66 | + //throw new \Exception('Signing failed!'); |
|
67 | + break; |
|
68 | + default: |
|
69 | + throw new \Exception('Unknown Error: '.$result->status_code); |
|
70 | + } |
|
71 | 71 | |
72 | - if($device_uid != "") |
|
73 | - { |
|
72 | + if($device_uid != "") |
|
73 | + { |
|
74 | 74 | $result[0] = $result; |
75 | 75 | $result[1] = $device_uid; |
76 | 76 | } |
77 | 77 | |
78 | - /* |
|
78 | + /* |
|
79 | 79 | var_dump($result); |
80 | 80 | */ |
81 | 81 | |
82 | - return $result; |
|
83 | - } |
|
84 | - abstract function getPayload(); |
|
85 | - /** |
|
86 | - * Gets Sign headers |
|
87 | - * @return array headers |
|
88 | - */ |
|
89 | - private function getSignHeaders() |
|
90 | - { |
|
82 | + return $result; |
|
83 | + } |
|
84 | + abstract function getPayload(); |
|
85 | + /** |
|
86 | + * Gets Sign headers |
|
87 | + * @return array headers |
|
88 | + */ |
|
89 | + private function getSignHeaders() |
|
90 | + { |
|
91 | 91 | if($this->getAccessToken() == null) { |
92 | 92 | $payload_accessToken = ""; |
93 | 93 | } |
@@ -96,54 +96,54 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | |
99 | - $headers = array( |
|
100 | - "Connection" => "keep-alive", |
|
101 | - "Accept-Encoding" => "gzip", |
|
102 | - "Content-Type" => "application/json; charset=UTF-8", |
|
103 | - "User-Agent" => self::USERAGENT |
|
104 | - ); |
|
105 | - $timestamp = new DateTime(); |
|
106 | - $timestamp = $timestamp->format(DateTime::ATOM); |
|
107 | - $timestamp = substr($timestamp, 0, -6); |
|
108 | - $timestamp .= "Z"; |
|
109 | - $urlParts = parse_url($this->getFullUrl()); |
|
110 | - $url2 = ""; |
|
111 | - $req = [$this->getMethod(), |
|
112 | - $urlParts['host'], |
|
113 | - "443", |
|
114 | - $urlParts['path'], |
|
115 | - $payload_accessToken, |
|
116 | - $timestamp, |
|
117 | - $url2, |
|
118 | - $this->payLoad]; |
|
119 | - $reqString = implode("%", $req); |
|
120 | - $secret = self::SECRET; |
|
121 | - $signature = hash_hmac('sha1', $reqString, $secret); |
|
122 | - $signature = strtoupper($signature); |
|
123 | - $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
124 | - $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
125 | - $headers['X-Timestamp'] = $timestamp; |
|
126 | - $headers['X-Api-Version'] = '0.2'; |
|
127 | - return $headers; |
|
128 | - } |
|
129 | - private function getFullUrl() |
|
130 | - { |
|
131 | - return self::APIURL . $this->getApiEndPoint(); |
|
132 | - } |
|
133 | - abstract function getApiEndPoint(); |
|
134 | - abstract function getMethod(); |
|
135 | - /** |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - private function getAccessToken() |
|
139 | - { |
|
140 | - return $this->accessToken; |
|
141 | - } |
|
142 | - /** |
|
143 | - * @param string $accessToken |
|
144 | - */ |
|
145 | - public function setAccessToken($accessToken) |
|
146 | - { |
|
147 | - $this->accessToken = $accessToken; |
|
148 | - } |
|
99 | + $headers = array( |
|
100 | + "Connection" => "keep-alive", |
|
101 | + "Accept-Encoding" => "gzip", |
|
102 | + "Content-Type" => "application/json; charset=UTF-8", |
|
103 | + "User-Agent" => self::USERAGENT |
|
104 | + ); |
|
105 | + $timestamp = new DateTime(); |
|
106 | + $timestamp = $timestamp->format(DateTime::ATOM); |
|
107 | + $timestamp = substr($timestamp, 0, -6); |
|
108 | + $timestamp .= "Z"; |
|
109 | + $urlParts = parse_url($this->getFullUrl()); |
|
110 | + $url2 = ""; |
|
111 | + $req = [$this->getMethod(), |
|
112 | + $urlParts['host'], |
|
113 | + "443", |
|
114 | + $urlParts['path'], |
|
115 | + $payload_accessToken, |
|
116 | + $timestamp, |
|
117 | + $url2, |
|
118 | + $this->payLoad]; |
|
119 | + $reqString = implode("%", $req); |
|
120 | + $secret = self::SECRET; |
|
121 | + $signature = hash_hmac('sha1', $reqString, $secret); |
|
122 | + $signature = strtoupper($signature); |
|
123 | + $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
124 | + $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
125 | + $headers['X-Timestamp'] = $timestamp; |
|
126 | + $headers['X-Api-Version'] = '0.2'; |
|
127 | + return $headers; |
|
128 | + } |
|
129 | + private function getFullUrl() |
|
130 | + { |
|
131 | + return self::APIURL . $this->getApiEndPoint(); |
|
132 | + } |
|
133 | + abstract function getApiEndPoint(); |
|
134 | + abstract function getMethod(); |
|
135 | + /** |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + private function getAccessToken() |
|
139 | + { |
|
140 | + return $this->accessToken; |
|
141 | + } |
|
142 | + /** |
|
143 | + * @param string $accessToken |
|
144 | + */ |
|
145 | + public function setAccessToken($accessToken) |
|
146 | + { |
|
147 | + $this->accessToken = $accessToken; |
|
148 | + } |
|
149 | 149 | } |