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