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