@@ -2,21 +2,21 @@ 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 = 'hFvMqLauMtnodakokftuKETbIsVLxpqfjAXiRoih'; |
|
8 | - const USERAGENT = 'Jodel/4.41.0 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
|
9 | - const CLIENT_TYPE = 'android_4.41.0'; |
|
5 | + const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
6 | + const APIURL = 'https://api.go-tellm.com/api'; |
|
7 | + const SECRET = 'hFvMqLauMtnodakokftuKETbIsVLxpqfjAXiRoih'; |
|
8 | + const USERAGENT = 'Jodel/4.41.0 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
|
9 | + const CLIENT_TYPE = 'android_4.41.0'; |
|
10 | 10 | |
11 | - private $accessToken = null; |
|
12 | - private $payLoad; |
|
13 | - public $expects = ''; |
|
14 | - public $version = 'v2'; |
|
15 | - public $hasPayload = FALSE; |
|
11 | + private $accessToken = null; |
|
12 | + private $payLoad; |
|
13 | + public $expects = ''; |
|
14 | + public $version = 'v2'; |
|
15 | + public $hasPayload = FALSE; |
|
16 | 16 | |
17 | - public function execute() |
|
18 | - { |
|
19 | - $result = new \stdClass(); |
|
17 | + public function execute() |
|
18 | + { |
|
19 | + $result = new \stdClass(); |
|
20 | 20 | |
21 | 21 | $this->payLoad = $this->getPayload(); |
22 | 22 | $device_uid = ''; |
@@ -25,16 +25,16 @@ discard block |
||
25 | 25 | } |
26 | 26 | |
27 | 27 | |
28 | - $this->payLoad = json_encode($this->payLoad); |
|
29 | - $header = $this->getSignHeaders(); |
|
30 | - $url = $this->getFullUrl(); |
|
28 | + $this->payLoad = json_encode($this->payLoad); |
|
29 | + $header = $this->getSignHeaders(); |
|
30 | + $url = $this->getFullUrl(); |
|
31 | 31 | |
32 | - if ($this->getAccessToken()) { |
|
33 | - $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
34 | - } |
|
35 | - //Comment out to debug the Request: |
|
32 | + if ($this->getAccessToken()) { |
|
33 | + $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
34 | + } |
|
35 | + //Comment out to debug the Request: |
|
36 | 36 | |
37 | - /* |
|
37 | + /* |
|
38 | 38 | printf("URL: "); |
39 | 39 | var_dump($url); |
40 | 40 | echo "<br />"; |
@@ -45,115 +45,115 @@ discard block |
||
45 | 45 | var_dump($this->payLoad); |
46 | 46 | echo "<br />"; |
47 | 47 | */ |
48 | - /* |
|
48 | + /* |
|
49 | 49 | $options = array( |
50 | 50 | 'timeout' => 100, |
51 | 51 | 'connect_timeout' => 100, |
52 | 52 | 'proxy' => '186.103.169.165:8080', |
53 | 53 | );*/ |
54 | 54 | |
55 | - switch ($this->getMethod()) { |
|
56 | - case 'POST': |
|
57 | - $result = Requests::post($url, $header, $this->payLoad); |
|
58 | - break; |
|
59 | - case 'GET': |
|
60 | - if($this->hasPayload) |
|
61 | - { |
|
62 | - $result = Requests::get($url, $header, $this->payLoad); |
|
63 | - } |
|
64 | - else |
|
65 | - { |
|
66 | - $result = Requests::get($url, $header); |
|
67 | - } |
|
68 | - break; |
|
69 | - case 'PUT': |
|
70 | - $result = Requests::put($url, $header, $this->payLoad); |
|
71 | - break; |
|
72 | - } |
|
55 | + switch ($this->getMethod()) { |
|
56 | + case 'POST': |
|
57 | + $result = Requests::post($url, $header, $this->payLoad); |
|
58 | + break; |
|
59 | + case 'GET': |
|
60 | + if($this->hasPayload) |
|
61 | + { |
|
62 | + $result = Requests::get($url, $header, $this->payLoad); |
|
63 | + } |
|
64 | + else |
|
65 | + { |
|
66 | + $result = Requests::get($url, $header); |
|
67 | + } |
|
68 | + break; |
|
69 | + case 'PUT': |
|
70 | + $result = Requests::put($url, $header, $this->payLoad); |
|
71 | + break; |
|
72 | + } |
|
73 | 73 | |
74 | - http_response_code($result->status_code); |
|
74 | + http_response_code($result->status_code); |
|
75 | 75 | |
76 | - switch ($result->status_code) { |
|
77 | - case 200: |
|
78 | - $result = json_decode($result->body, true); |
|
79 | - break; |
|
80 | - case 204: |
|
81 | - $result = 'Success'; |
|
82 | - http_response_code(200); |
|
83 | - break; |
|
84 | - case 400: |
|
85 | - $result = json_decode($result->body, true); |
|
86 | - error_log('Error 400 - ' . print_r($result, true)); |
|
87 | - break; |
|
88 | - case 401: |
|
89 | - $resultOld = $result; |
|
90 | - $result = json_decode($result->body, true); |
|
76 | + switch ($result->status_code) { |
|
77 | + case 200: |
|
78 | + $result = json_decode($result->body, true); |
|
79 | + break; |
|
80 | + case 204: |
|
81 | + $result = 'Success'; |
|
82 | + http_response_code(200); |
|
83 | + break; |
|
84 | + case 400: |
|
85 | + $result = json_decode($result->body, true); |
|
86 | + error_log('Error 400 - ' . print_r($result, true)); |
|
87 | + break; |
|
88 | + case 401: |
|
89 | + $resultOld = $result; |
|
90 | + $result = json_decode($result->body, true); |
|
91 | 91 | |
92 | - if(is_array($result) && $result['error'] == 'length') |
|
93 | - { |
|
92 | + if(is_array($result) && $result['error'] == 'length') |
|
93 | + { |
|
94 | 94 | |
95 | - } |
|
96 | - else |
|
97 | - { |
|
98 | - error_log('Error 401 - ' . print_r($resultOld, true)); |
|
99 | - } |
|
100 | - break; |
|
101 | - case 404: |
|
102 | - error_log('Error 404 - ' . print_r($result, true)); |
|
103 | - $result = json_decode($result->body, true); |
|
104 | - break; |
|
95 | + } |
|
96 | + else |
|
97 | + { |
|
98 | + error_log('Error 401 - ' . print_r($resultOld, true)); |
|
99 | + } |
|
100 | + break; |
|
101 | + case 404: |
|
102 | + error_log('Error 404 - ' . print_r($result, true)); |
|
103 | + $result = json_decode($result->body, true); |
|
104 | + break; |
|
105 | 105 | case 477: |
106 | - $result = json_decode($result->body, true); |
|
107 | - error_log('Error 477 - ' . print_r($result, true)); |
|
108 | - break; |
|
109 | - case 429: |
|
110 | - error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true)); |
|
111 | - exit("Error 429: Too Many Requests"); |
|
112 | - break; |
|
113 | - case 403: |
|
114 | - error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true)); |
|
115 | - $result = json_decode($result->body, true); |
|
116 | - break; |
|
117 | - case 502: |
|
118 | - error_log('Error 502 - ' . print_r($result, true)); |
|
119 | - $result = json_decode($result->body, true); |
|
120 | - header('location:'.$_SERVER['PHP_SELF']); |
|
121 | - break; |
|
122 | - case 503: |
|
123 | - error_log('Error 503 - ' . print_r($result, true)); |
|
124 | - $result = json_decode($result->body, true); |
|
106 | + $result = json_decode($result->body, true); |
|
107 | + error_log('Error 477 - ' . print_r($result, true)); |
|
108 | + break; |
|
109 | + case 429: |
|
110 | + error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true)); |
|
111 | + exit("Error 429: Too Many Requests"); |
|
112 | + break; |
|
113 | + case 403: |
|
114 | + error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true)); |
|
115 | + $result = json_decode($result->body, true); |
|
116 | + break; |
|
117 | + case 502: |
|
118 | + error_log('Error 502 - ' . print_r($result, true)); |
|
119 | + $result = json_decode($result->body, true); |
|
120 | + header('location:'.$_SERVER['PHP_SELF']); |
|
121 | + break; |
|
122 | + case 503: |
|
123 | + error_log('Error 503 - ' . print_r($result, true)); |
|
124 | + $result = json_decode($result->body, true); |
|
125 | 125 | |
126 | - if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable') |
|
127 | - { |
|
128 | - header('location:'.$_SERVER['PHP_SELF']); |
|
129 | - } |
|
130 | - break; |
|
131 | - default: |
|
132 | - error_log('Error '.$result->status_code.' - unknown error'); |
|
133 | - $result = json_decode($result->body, true); |
|
134 | - } |
|
126 | + if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable') |
|
127 | + { |
|
128 | + header('location:'.$_SERVER['PHP_SELF']); |
|
129 | + } |
|
130 | + break; |
|
131 | + default: |
|
132 | + error_log('Error '.$result->status_code.' - unknown error'); |
|
133 | + $result = json_decode($result->body, true); |
|
134 | + } |
|
135 | 135 | |
136 | - //important for account refresh |
|
137 | - if($device_uid != '') |
|
138 | - { |
|
136 | + //important for account refresh |
|
137 | + if($device_uid != '') |
|
138 | + { |
|
139 | 139 | $result[0] = $result; |
140 | 140 | $result[1] = $device_uid; |
141 | - } |
|
141 | + } |
|
142 | 142 | |
143 | 143 | |
144 | - /* |
|
144 | + /* |
|
145 | 145 | var_dump($result); |
146 | 146 | */ |
147 | 147 | |
148 | - return $result; |
|
149 | - } |
|
150 | - abstract function getPayload(); |
|
151 | - /** |
|
152 | - * Gets Sign headers |
|
153 | - * @return array headers |
|
154 | - */ |
|
155 | - private function getSignHeaders() |
|
156 | - { |
|
148 | + return $result; |
|
149 | + } |
|
150 | + abstract function getPayload(); |
|
151 | + /** |
|
152 | + * Gets Sign headers |
|
153 | + * @return array headers |
|
154 | + */ |
|
155 | + private function getSignHeaders() |
|
156 | + { |
|
157 | 157 | if($this->getAccessToken() == null) { |
158 | 158 | $payload_accessToken = ""; |
159 | 159 | } |
@@ -162,54 +162,54 @@ discard block |
||
162 | 162 | } |
163 | 163 | |
164 | 164 | |
165 | - $headers = array( |
|
166 | - "Connection" => "keep-alive", |
|
167 | - "Accept-Encoding" => "gzip", |
|
168 | - "Content-Type" => "application/json; charset=UTF-8", |
|
169 | - "User-Agent" => self::USERAGENT |
|
170 | - ); |
|
171 | - $timestamp = new DateTime(); |
|
172 | - $timestamp = $timestamp->format(DateTime::ATOM); |
|
173 | - $timestamp = substr($timestamp, 0, -6); |
|
174 | - $timestamp .= "Z"; |
|
175 | - $urlParts = parse_url($this->getFullUrl()); |
|
176 | - $url2 = ""; |
|
177 | - $req = [$this->getMethod(), |
|
178 | - $urlParts['host'], |
|
179 | - "443", |
|
180 | - $urlParts['path'], |
|
181 | - $payload_accessToken, |
|
182 | - $timestamp, |
|
183 | - $url2, |
|
184 | - $this->payLoad]; |
|
185 | - $reqString = implode("%", $req); |
|
186 | - $secret = self::SECRET; |
|
187 | - $signature = hash_hmac('sha1', $reqString, $secret); |
|
188 | - $signature = strtoupper($signature); |
|
189 | - $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
190 | - $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
191 | - $headers['X-Timestamp'] = $timestamp; |
|
192 | - $headers['X-Api-Version'] = '0.2'; |
|
193 | - return $headers; |
|
194 | - } |
|
195 | - private function getFullUrl() |
|
196 | - { |
|
197 | - return self::APIURL . $this->getApiEndPoint(); |
|
198 | - } |
|
199 | - abstract function getApiEndPoint(); |
|
200 | - abstract function getMethod(); |
|
201 | - /** |
|
202 | - * @return string |
|
203 | - */ |
|
204 | - private function getAccessToken() |
|
205 | - { |
|
206 | - return $this->accessToken; |
|
207 | - } |
|
208 | - /** |
|
209 | - * @param string $accessToken |
|
210 | - */ |
|
211 | - public function setAccessToken($accessToken) |
|
212 | - { |
|
213 | - $this->accessToken = $accessToken; |
|
214 | - } |
|
165 | + $headers = array( |
|
166 | + "Connection" => "keep-alive", |
|
167 | + "Accept-Encoding" => "gzip", |
|
168 | + "Content-Type" => "application/json; charset=UTF-8", |
|
169 | + "User-Agent" => self::USERAGENT |
|
170 | + ); |
|
171 | + $timestamp = new DateTime(); |
|
172 | + $timestamp = $timestamp->format(DateTime::ATOM); |
|
173 | + $timestamp = substr($timestamp, 0, -6); |
|
174 | + $timestamp .= "Z"; |
|
175 | + $urlParts = parse_url($this->getFullUrl()); |
|
176 | + $url2 = ""; |
|
177 | + $req = [$this->getMethod(), |
|
178 | + $urlParts['host'], |
|
179 | + "443", |
|
180 | + $urlParts['path'], |
|
181 | + $payload_accessToken, |
|
182 | + $timestamp, |
|
183 | + $url2, |
|
184 | + $this->payLoad]; |
|
185 | + $reqString = implode("%", $req); |
|
186 | + $secret = self::SECRET; |
|
187 | + $signature = hash_hmac('sha1', $reqString, $secret); |
|
188 | + $signature = strtoupper($signature); |
|
189 | + $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
190 | + $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
191 | + $headers['X-Timestamp'] = $timestamp; |
|
192 | + $headers['X-Api-Version'] = '0.2'; |
|
193 | + return $headers; |
|
194 | + } |
|
195 | + private function getFullUrl() |
|
196 | + { |
|
197 | + return self::APIURL . $this->getApiEndPoint(); |
|
198 | + } |
|
199 | + abstract function getApiEndPoint(); |
|
200 | + abstract function getMethod(); |
|
201 | + /** |
|
202 | + * @return string |
|
203 | + */ |
|
204 | + private function getAccessToken() |
|
205 | + { |
|
206 | + return $this->accessToken; |
|
207 | + } |
|
208 | + /** |
|
209 | + * @param string $accessToken |
|
210 | + */ |
|
211 | + public function setAccessToken($accessToken) |
|
212 | + { |
|
213 | + $this->accessToken = $accessToken; |
|
214 | + } |
|
215 | 215 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | const USERAGENT = 'Jodel/4.41.0 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
9 | 9 | const CLIENT_TYPE = 'android_4.41.0'; |
10 | 10 | |
11 | - private $accessToken = null; |
|
11 | + private $accessToken = NULL; |
|
12 | 12 | private $payLoad; |
13 | 13 | public $expects = ''; |
14 | 14 | public $version = 'v2'; |
@@ -75,19 +75,19 @@ discard block |
||
75 | 75 | |
76 | 76 | switch ($result->status_code) { |
77 | 77 | case 200: |
78 | - $result = json_decode($result->body, true); |
|
78 | + $result = json_decode($result->body, TRUE); |
|
79 | 79 | break; |
80 | 80 | case 204: |
81 | 81 | $result = 'Success'; |
82 | 82 | http_response_code(200); |
83 | 83 | break; |
84 | 84 | case 400: |
85 | - $result = json_decode($result->body, true); |
|
86 | - error_log('Error 400 - ' . print_r($result, true)); |
|
85 | + $result = json_decode($result->body, TRUE); |
|
86 | + error_log('Error 400 - ' . print_r($result, TRUE)); |
|
87 | 87 | break; |
88 | 88 | case 401: |
89 | 89 | $resultOld = $result; |
90 | - $result = json_decode($result->body, true); |
|
90 | + $result = json_decode($result->body, TRUE); |
|
91 | 91 | |
92 | 92 | if(is_array($result) && $result['error'] == 'length') |
93 | 93 | { |
@@ -95,33 +95,33 @@ discard block |
||
95 | 95 | } |
96 | 96 | else |
97 | 97 | { |
98 | - error_log('Error 401 - ' . print_r($resultOld, true)); |
|
98 | + error_log('Error 401 - ' . print_r($resultOld, TRUE)); |
|
99 | 99 | } |
100 | 100 | break; |
101 | 101 | case 404: |
102 | - error_log('Error 404 - ' . print_r($result, true)); |
|
103 | - $result = json_decode($result->body, true); |
|
102 | + error_log('Error 404 - ' . print_r($result, TRUE)); |
|
103 | + $result = json_decode($result->body, TRUE); |
|
104 | 104 | break; |
105 | 105 | case 477: |
106 | - $result = json_decode($result->body, true); |
|
107 | - error_log('Error 477 - ' . print_r($result, true)); |
|
106 | + $result = json_decode($result->body, TRUE); |
|
107 | + error_log('Error 477 - ' . print_r($result, TRUE)); |
|
108 | 108 | break; |
109 | 109 | case 429: |
110 | - error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true)); |
|
110 | + error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, TRUE), TRUE)); |
|
111 | 111 | exit("Error 429: Too Many Requests"); |
112 | 112 | break; |
113 | 113 | case 403: |
114 | - error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true)); |
|
115 | - $result = json_decode($result->body, true); |
|
114 | + error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, TRUE), TRUE)); |
|
115 | + $result = json_decode($result->body, TRUE); |
|
116 | 116 | break; |
117 | 117 | case 502: |
118 | - error_log('Error 502 - ' . print_r($result, true)); |
|
119 | - $result = json_decode($result->body, true); |
|
118 | + error_log('Error 502 - ' . print_r($result, TRUE)); |
|
119 | + $result = json_decode($result->body, TRUE); |
|
120 | 120 | header('location:'.$_SERVER['PHP_SELF']); |
121 | 121 | break; |
122 | 122 | case 503: |
123 | - error_log('Error 503 - ' . print_r($result, true)); |
|
124 | - $result = json_decode($result->body, true); |
|
123 | + error_log('Error 503 - ' . print_r($result, TRUE)); |
|
124 | + $result = json_decode($result->body, TRUE); |
|
125 | 125 | |
126 | 126 | if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable') |
127 | 127 | { |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | break; |
131 | 131 | default: |
132 | 132 | error_log('Error '.$result->status_code.' - unknown error'); |
133 | - $result = json_decode($result->body, true); |
|
133 | + $result = json_decode($result->body, TRUE); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | //important for account refresh |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | */ |
155 | 155 | private function getSignHeaders() |
156 | 156 | { |
157 | - if($this->getAccessToken() == null) { |
|
157 | + if($this->getAccessToken() == NULL) { |
|
158 | 158 | $payload_accessToken = ""; |
159 | 159 | } |
160 | 160 | else { |