@@ -2,508 +2,508 @@ |
||
2 | 2 | |
3 | 3 | class JodelAccount |
4 | 4 | { |
5 | - public $accessToken; |
|
6 | - public $expirationDate; |
|
7 | - public $refreshToken; |
|
8 | - public $distinctId; |
|
9 | - public $deviceUid; |
|
10 | - |
|
11 | - //is the Account a Bot or Spider? |
|
12 | - public $isBot; |
|
5 | + public $accessToken; |
|
6 | + public $expirationDate; |
|
7 | + public $refreshToken; |
|
8 | + public $distinctId; |
|
9 | + public $deviceUid; |
|
10 | + |
|
11 | + //is the Account a Bot or Spider? |
|
12 | + public $isBot; |
|
13 | 13 | |
14 | - // array of voted Jodels |
|
15 | - public $votes; |
|
16 | - |
|
17 | - //Location of the Account |
|
18 | - public $location; |
|
19 | - |
|
20 | - function __construct($deviceUid = NULL, $isBot = FALSE) |
|
21 | - { |
|
22 | - if($deviceUid == NULL) |
|
23 | - { |
|
24 | - $this->deviceUid = $this->createAccount(); |
|
25 | - } |
|
26 | - else |
|
27 | - { |
|
28 | - $this->deviceUid = $deviceUid; |
|
29 | - } |
|
30 | - |
|
31 | - $this->isBot = $isBot; |
|
32 | - $this->location = $this->getLocation(); |
|
33 | - |
|
34 | - if(!$this->isTokenFresh()) |
|
35 | - { |
|
36 | - $this->refreshToken(); |
|
37 | - } |
|
38 | - $this->accessToken = $this->getAccessToken(); |
|
39 | - } |
|
40 | - |
|
41 | - function isAccountVerified() |
|
42 | - { |
|
43 | - $accountCreator = new GetUserConfig(); |
|
44 | - $accountCreator->setAccessToken($this->accessToken); |
|
45 | - $data = $accountCreator->execute(); |
|
46 | - |
|
47 | - return $data['verified']; |
|
48 | - } |
|
49 | - |
|
50 | - function locationEquals($city) |
|
51 | - { |
|
52 | - $url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($city) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w'; |
|
53 | - $result = Requests::post($url); |
|
54 | - if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST') |
|
55 | - { |
|
56 | - error_log('Error locationEquals'); |
|
57 | - return FALSE; |
|
58 | - } |
|
59 | - else |
|
60 | - { |
|
61 | - $name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name']; |
|
62 | - $lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat']; |
|
63 | - $lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng']; |
|
64 | - } |
|
65 | - |
|
66 | - $db = new DatabaseConnect(); |
|
67 | - $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
14 | + // array of voted Jodels |
|
15 | + public $votes; |
|
16 | + |
|
17 | + //Location of the Account |
|
18 | + public $location; |
|
19 | + |
|
20 | + function __construct($deviceUid = NULL, $isBot = FALSE) |
|
21 | + { |
|
22 | + if($deviceUid == NULL) |
|
23 | + { |
|
24 | + $this->deviceUid = $this->createAccount(); |
|
25 | + } |
|
26 | + else |
|
27 | + { |
|
28 | + $this->deviceUid = $deviceUid; |
|
29 | + } |
|
30 | + |
|
31 | + $this->isBot = $isBot; |
|
32 | + $this->location = $this->getLocation(); |
|
33 | + |
|
34 | + if(!$this->isTokenFresh()) |
|
35 | + { |
|
36 | + $this->refreshToken(); |
|
37 | + } |
|
38 | + $this->accessToken = $this->getAccessToken(); |
|
39 | + } |
|
40 | + |
|
41 | + function isAccountVerified() |
|
42 | + { |
|
43 | + $accountCreator = new GetUserConfig(); |
|
44 | + $accountCreator->setAccessToken($this->accessToken); |
|
45 | + $data = $accountCreator->execute(); |
|
46 | + |
|
47 | + return $data['verified']; |
|
48 | + } |
|
49 | + |
|
50 | + function locationEquals($city) |
|
51 | + { |
|
52 | + $url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($city) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w'; |
|
53 | + $result = Requests::post($url); |
|
54 | + if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST') |
|
55 | + { |
|
56 | + error_log('Error locationEquals'); |
|
57 | + return FALSE; |
|
58 | + } |
|
59 | + else |
|
60 | + { |
|
61 | + $name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name']; |
|
62 | + $lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat']; |
|
63 | + $lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng']; |
|
64 | + } |
|
65 | + |
|
66 | + $db = new DatabaseConnect(); |
|
67 | + $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
68 | 68 | |
69 | - $location = new Location(); |
|
69 | + $location = new Location(); |
|
70 | 70 | |
71 | - if ($result->num_rows > 0) |
|
72 | - { |
|
73 | - // output data of each row |
|
74 | - while($row = $result->fetch_assoc()) |
|
75 | - { |
|
76 | - $location->setLat($row['lat']); |
|
77 | - $location->setLng($row['lng']); |
|
78 | - $location->setCityName($row['name']); |
|
79 | - } |
|
80 | - } |
|
81 | - else |
|
82 | - { |
|
83 | - error_log("Error no Location found - getLocation"); |
|
84 | - } |
|
85 | - |
|
86 | - if($location->getLat() == $lat && $location->getLng() == $lng && $location->getCityName() == $name) |
|
87 | - { |
|
88 | - return TRUE; |
|
89 | - } |
|
90 | - else |
|
91 | - { |
|
92 | - return FALSE; |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - function setLocation() |
|
97 | - { |
|
98 | - //Is Channel or City |
|
99 | - if(substr($_GET['city'], 0, 1) === '#') |
|
100 | - { |
|
101 | - return htmlspecialchars($_GET['city']) . " " . $this->location->cityName; |
|
102 | - } |
|
103 | - else |
|
104 | - { |
|
105 | - $url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($_GET['city']) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w'; |
|
106 | - $result = Requests::post($url); |
|
107 | - if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST') |
|
108 | - { |
|
109 | - return "0 results"; |
|
110 | - } |
|
111 | - else |
|
112 | - { |
|
113 | - $name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name']; |
|
114 | - $lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat']; |
|
115 | - $lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng']; |
|
116 | - |
|
117 | - $location = new Location(); |
|
118 | - $location->setLat($lat); |
|
119 | - $location->setLng($lng); |
|
120 | - $location->setCityName($name); |
|
121 | - $accountCreator = new UpdateLocation(); |
|
122 | - $accountCreator->setLocation($location); |
|
123 | - $accountCreator->setAccessToken($this->accessToken); |
|
124 | - $data = $accountCreator->execute(); |
|
125 | - |
|
126 | - //safe location to db |
|
127 | - $db = new DatabaseConnect(); |
|
128 | - |
|
129 | - if($data == 'Success') |
|
130 | - { |
|
131 | - $result = $db->query("UPDATE accounts |
|
71 | + if ($result->num_rows > 0) |
|
72 | + { |
|
73 | + // output data of each row |
|
74 | + while($row = $result->fetch_assoc()) |
|
75 | + { |
|
76 | + $location->setLat($row['lat']); |
|
77 | + $location->setLng($row['lng']); |
|
78 | + $location->setCityName($row['name']); |
|
79 | + } |
|
80 | + } |
|
81 | + else |
|
82 | + { |
|
83 | + error_log("Error no Location found - getLocation"); |
|
84 | + } |
|
85 | + |
|
86 | + if($location->getLat() == $lat && $location->getLng() == $lng && $location->getCityName() == $name) |
|
87 | + { |
|
88 | + return TRUE; |
|
89 | + } |
|
90 | + else |
|
91 | + { |
|
92 | + return FALSE; |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + function setLocation() |
|
97 | + { |
|
98 | + //Is Channel or City |
|
99 | + if(substr($_GET['city'], 0, 1) === '#') |
|
100 | + { |
|
101 | + return htmlspecialchars($_GET['city']) . " " . $this->location->cityName; |
|
102 | + } |
|
103 | + else |
|
104 | + { |
|
105 | + $url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($_GET['city']) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w'; |
|
106 | + $result = Requests::post($url); |
|
107 | + if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST') |
|
108 | + { |
|
109 | + return "0 results"; |
|
110 | + } |
|
111 | + else |
|
112 | + { |
|
113 | + $name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name']; |
|
114 | + $lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat']; |
|
115 | + $lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng']; |
|
116 | + |
|
117 | + $location = new Location(); |
|
118 | + $location->setLat($lat); |
|
119 | + $location->setLng($lng); |
|
120 | + $location->setCityName($name); |
|
121 | + $accountCreator = new UpdateLocation(); |
|
122 | + $accountCreator->setLocation($location); |
|
123 | + $accountCreator->setAccessToken($this->accessToken); |
|
124 | + $data = $accountCreator->execute(); |
|
125 | + |
|
126 | + //safe location to db |
|
127 | + $db = new DatabaseConnect(); |
|
128 | + |
|
129 | + if($data == 'Success') |
|
130 | + { |
|
131 | + $result = $db->query("UPDATE accounts |
|
132 | 132 | SET name='" . $name . "', |
133 | 133 | lat='" . $lat . "', |
134 | 134 | lng='" . $lng . "' |
135 | 135 | WHERE access_token='" . $this->accessToken . "'"); |
136 | 136 | |
137 | - if($result === false) |
|
138 | - { |
|
139 | - echo "Updating location failed: (" . $db->errno . ") " . $db->error; |
|
140 | - } |
|
141 | - else |
|
142 | - { |
|
143 | - user_log('User with JodelDeviceId:' . $this->deviceUid . ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] changed to Location: ' . $name); |
|
144 | - } |
|
145 | - } |
|
146 | - |
|
147 | - return $name; |
|
148 | - } |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - function getLocation() |
|
153 | - { |
|
154 | - $db = new DatabaseConnect(); |
|
155 | - $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
137 | + if($result === false) |
|
138 | + { |
|
139 | + echo "Updating location failed: (" . $db->errno . ") " . $db->error; |
|
140 | + } |
|
141 | + else |
|
142 | + { |
|
143 | + user_log('User with JodelDeviceId:' . $this->deviceUid . ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] changed to Location: ' . $name); |
|
144 | + } |
|
145 | + } |
|
146 | + |
|
147 | + return $name; |
|
148 | + } |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + function getLocation() |
|
153 | + { |
|
154 | + $db = new DatabaseConnect(); |
|
155 | + $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
156 | 156 | |
157 | - $location = new Location(); |
|
157 | + $location = new Location(); |
|
158 | 158 | |
159 | - if ($result->num_rows > 0) |
|
160 | - { |
|
161 | - // output data of each row |
|
162 | - while($row = $result->fetch_assoc()) |
|
163 | - { |
|
164 | - $location->setLat($row['lat']); |
|
165 | - $location->setLng($row['lng']); |
|
166 | - $location->setCityName($row['name']); |
|
167 | - } |
|
168 | - } |
|
169 | - else |
|
170 | - { |
|
171 | - echo "Error: 0 results"; |
|
172 | - error_log("Error no Location found - getLocation"); |
|
173 | - } |
|
174 | - |
|
175 | - return $location; |
|
176 | - } |
|
177 | - |
|
178 | - function verifyCaptcha() |
|
179 | - { |
|
180 | - if(isset($_GET['deviceUid'])) |
|
181 | - { |
|
182 | - $deviceUid = $_GET['deviceUid']; |
|
183 | - } |
|
184 | - if(isset($_POST['deviceUid'])) |
|
185 | - { |
|
186 | - $deviceUid = $_POST['deviceUid']; |
|
187 | - } |
|
188 | - $jodelAccountForVerify = new JodelAccount($deviceUid); |
|
189 | - |
|
190 | - $solution = $_GET['solution']; |
|
191 | - $solution = array_map('intval', explode('-', $solution)); |
|
192 | - |
|
193 | - $accountCreator = new PostCaptcha(); |
|
194 | - $accountCreator->setAccessToken($jodelAccountForVerify->accessToken); |
|
195 | - $accountCreator->captchaKey = $_GET['key']; |
|
196 | - $accountCreator->captchaSolution = $solution; |
|
197 | - $verified = $accountCreator->execute(); |
|
198 | - |
|
199 | - if(isset($verified->status_code)) |
|
200 | - { |
|
201 | - return $verified->status_code; |
|
202 | - } |
|
203 | - return $verified['verified']; |
|
204 | - } |
|
205 | - |
|
206 | - //ToDo Spider Check |
|
207 | - function votePostId($postId, $vote) |
|
208 | - { |
|
209 | - if(!$this->isBot) |
|
210 | - { |
|
211 | - if(!$this->isAccountVerified()) |
|
212 | - { |
|
213 | - $view = new View(); |
|
214 | - $view->showCaptcha($this->accessToken, $this->deviceUid); |
|
215 | - } |
|
216 | - |
|
217 | - if(!$this->hasVoted($postId)) |
|
218 | - { |
|
219 | - if($vote == "up") |
|
220 | - { |
|
221 | - $accountCreator = new Upvote(); |
|
222 | - } |
|
223 | - else if($vote == "down") |
|
224 | - { |
|
225 | - $accountCreator = new Downvote(); |
|
226 | - } |
|
227 | - |
|
228 | - $accountCreator->setAccessToken($this->accessToken); |
|
229 | - $accountCreator->postId = htmlspecialchars($postId); |
|
230 | - $data = $accountCreator->execute(); |
|
231 | - |
|
232 | - error_log('Could not vote: ' . print_r($data, true)); |
|
233 | - |
|
234 | - if(array_key_exists('post', $data)) |
|
235 | - { |
|
236 | - $this->addVoteWithPostIdAndType($postId, $vote); |
|
237 | - return TRUE; |
|
238 | - } |
|
239 | - else if(array_key_exists('error', $data)) |
|
240 | - { |
|
241 | - error_log('Could not vote - Error: ' . $data['error']); |
|
242 | - } |
|
243 | - else |
|
244 | - { |
|
245 | - error_log('Could not vote: ' . print_r($data, true)); |
|
246 | - return FALSE; |
|
247 | - } |
|
248 | - } |
|
249 | - else |
|
250 | - { |
|
251 | - return FALSE; |
|
252 | - } |
|
253 | - } |
|
254 | - |
|
255 | - return FALSE; |
|
256 | - } |
|
257 | - |
|
258 | - //ToDo Spider Check |
|
259 | - function sendJodel($location, $view) |
|
260 | - { |
|
261 | - if(!$this->isAccountVerified()) |
|
262 | - { |
|
263 | - showCaptcha($this->accessToken); |
|
264 | - } |
|
265 | - |
|
266 | - $accountCreator = new SendJodel(); |
|
267 | - |
|
268 | - if(isset($_POST['ancestor'])) |
|
269 | - { |
|
270 | - $ancestor = $_POST['ancestor']; |
|
271 | - $accountCreator->ancestor = $ancestor; |
|
272 | - } |
|
273 | - if(isset($_POST['color'])) |
|
274 | - { |
|
275 | - $color = $_POST['color']; |
|
276 | - switch ($color) { |
|
277 | - case '8ABDB0': |
|
278 | - $color = '8ABDB0'; |
|
279 | - break; |
|
280 | - case '9EC41C': |
|
281 | - $color = '9EC41C'; |
|
282 | - break; |
|
283 | - case '06A3CB': |
|
284 | - $color = '06A3CB'; |
|
285 | - break; |
|
286 | - case 'FFBA00': |
|
287 | - $color = 'FFBA00'; |
|
288 | - break; |
|
289 | - case 'DD5F5F': |
|
290 | - $color = 'DD5F5F'; |
|
291 | - break; |
|
292 | - case 'FF9908': |
|
293 | - $color = 'FF9908'; |
|
294 | - break; |
|
295 | - default: |
|
296 | - $color = '8ABDB0'; |
|
297 | - break; |
|
298 | - } |
|
299 | - $accountCreator->color = $color; |
|
300 | - } |
|
301 | - |
|
302 | - $accountCreatorLocation = new UpdateLocation(); |
|
303 | - $accountCreatorLocation->setLocation($location); |
|
304 | - $accountCreatorLocation->setAccessToken($this->accessToken); |
|
305 | - $data = $accountCreatorLocation->execute(); |
|
159 | + if ($result->num_rows > 0) |
|
160 | + { |
|
161 | + // output data of each row |
|
162 | + while($row = $result->fetch_assoc()) |
|
163 | + { |
|
164 | + $location->setLat($row['lat']); |
|
165 | + $location->setLng($row['lng']); |
|
166 | + $location->setCityName($row['name']); |
|
167 | + } |
|
168 | + } |
|
169 | + else |
|
170 | + { |
|
171 | + echo "Error: 0 results"; |
|
172 | + error_log("Error no Location found - getLocation"); |
|
173 | + } |
|
174 | + |
|
175 | + return $location; |
|
176 | + } |
|
177 | + |
|
178 | + function verifyCaptcha() |
|
179 | + { |
|
180 | + if(isset($_GET['deviceUid'])) |
|
181 | + { |
|
182 | + $deviceUid = $_GET['deviceUid']; |
|
183 | + } |
|
184 | + if(isset($_POST['deviceUid'])) |
|
185 | + { |
|
186 | + $deviceUid = $_POST['deviceUid']; |
|
187 | + } |
|
188 | + $jodelAccountForVerify = new JodelAccount($deviceUid); |
|
189 | + |
|
190 | + $solution = $_GET['solution']; |
|
191 | + $solution = array_map('intval', explode('-', $solution)); |
|
192 | + |
|
193 | + $accountCreator = new PostCaptcha(); |
|
194 | + $accountCreator->setAccessToken($jodelAccountForVerify->accessToken); |
|
195 | + $accountCreator->captchaKey = $_GET['key']; |
|
196 | + $accountCreator->captchaSolution = $solution; |
|
197 | + $verified = $accountCreator->execute(); |
|
198 | + |
|
199 | + if(isset($verified->status_code)) |
|
200 | + { |
|
201 | + return $verified->status_code; |
|
202 | + } |
|
203 | + return $verified['verified']; |
|
204 | + } |
|
205 | + |
|
206 | + //ToDo Spider Check |
|
207 | + function votePostId($postId, $vote) |
|
208 | + { |
|
209 | + if(!$this->isBot) |
|
210 | + { |
|
211 | + if(!$this->isAccountVerified()) |
|
212 | + { |
|
213 | + $view = new View(); |
|
214 | + $view->showCaptcha($this->accessToken, $this->deviceUid); |
|
215 | + } |
|
216 | + |
|
217 | + if(!$this->hasVoted($postId)) |
|
218 | + { |
|
219 | + if($vote == "up") |
|
220 | + { |
|
221 | + $accountCreator = new Upvote(); |
|
222 | + } |
|
223 | + else if($vote == "down") |
|
224 | + { |
|
225 | + $accountCreator = new Downvote(); |
|
226 | + } |
|
227 | + |
|
228 | + $accountCreator->setAccessToken($this->accessToken); |
|
229 | + $accountCreator->postId = htmlspecialchars($postId); |
|
230 | + $data = $accountCreator->execute(); |
|
231 | + |
|
232 | + error_log('Could not vote: ' . print_r($data, true)); |
|
233 | + |
|
234 | + if(array_key_exists('post', $data)) |
|
235 | + { |
|
236 | + $this->addVoteWithPostIdAndType($postId, $vote); |
|
237 | + return TRUE; |
|
238 | + } |
|
239 | + else if(array_key_exists('error', $data)) |
|
240 | + { |
|
241 | + error_log('Could not vote - Error: ' . $data['error']); |
|
242 | + } |
|
243 | + else |
|
244 | + { |
|
245 | + error_log('Could not vote: ' . print_r($data, true)); |
|
246 | + return FALSE; |
|
247 | + } |
|
248 | + } |
|
249 | + else |
|
250 | + { |
|
251 | + return FALSE; |
|
252 | + } |
|
253 | + } |
|
254 | + |
|
255 | + return FALSE; |
|
256 | + } |
|
257 | + |
|
258 | + //ToDo Spider Check |
|
259 | + function sendJodel($location, $view) |
|
260 | + { |
|
261 | + if(!$this->isAccountVerified()) |
|
262 | + { |
|
263 | + showCaptcha($this->accessToken); |
|
264 | + } |
|
265 | + |
|
266 | + $accountCreator = new SendJodel(); |
|
267 | + |
|
268 | + if(isset($_POST['ancestor'])) |
|
269 | + { |
|
270 | + $ancestor = $_POST['ancestor']; |
|
271 | + $accountCreator->ancestor = $ancestor; |
|
272 | + } |
|
273 | + if(isset($_POST['color'])) |
|
274 | + { |
|
275 | + $color = $_POST['color']; |
|
276 | + switch ($color) { |
|
277 | + case '8ABDB0': |
|
278 | + $color = '8ABDB0'; |
|
279 | + break; |
|
280 | + case '9EC41C': |
|
281 | + $color = '9EC41C'; |
|
282 | + break; |
|
283 | + case '06A3CB': |
|
284 | + $color = '06A3CB'; |
|
285 | + break; |
|
286 | + case 'FFBA00': |
|
287 | + $color = 'FFBA00'; |
|
288 | + break; |
|
289 | + case 'DD5F5F': |
|
290 | + $color = 'DD5F5F'; |
|
291 | + break; |
|
292 | + case 'FF9908': |
|
293 | + $color = 'FF9908'; |
|
294 | + break; |
|
295 | + default: |
|
296 | + $color = '8ABDB0'; |
|
297 | + break; |
|
298 | + } |
|
299 | + $accountCreator->color = $color; |
|
300 | + } |
|
301 | + |
|
302 | + $accountCreatorLocation = new UpdateLocation(); |
|
303 | + $accountCreatorLocation->setLocation($location); |
|
304 | + $accountCreatorLocation->setAccessToken($this->accessToken); |
|
305 | + $data = $accountCreatorLocation->execute(); |
|
306 | 306 | |
307 | 307 | if($data != 'Success') |
308 | 308 | { |
309 | 309 | error_log('Could not set location befor Post: ' . print_r($data, true)); |
310 | 310 | } |
311 | 311 | |
312 | - $accountCreator->location = $this->location; |
|
312 | + $accountCreator->location = $this->location; |
|
313 | 313 | |
314 | - $accountCreator->setAccessToken($this->accessToken); |
|
315 | - $data = $accountCreator->execute(); |
|
316 | - |
|
317 | - error_log(print_r($data, true)); |
|
318 | - |
|
319 | - if(isset($_POST['ancestor'])) |
|
320 | - { |
|
321 | - header('Location: ' . $view->toUrl()); |
|
322 | - exit; |
|
323 | - } |
|
324 | - else |
|
325 | - { |
|
326 | - header('Location: ' . $view->baseUrl); |
|
327 | - exit; |
|
328 | - } |
|
329 | - } |
|
330 | - |
|
331 | - function isTokenFresh() |
|
332 | - { |
|
333 | - $db = new DatabaseConnect(); |
|
334 | - $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
335 | - |
|
336 | - if ($result->num_rows > 0) |
|
337 | - { |
|
338 | - // output data of each row |
|
339 | - while($row = $result->fetch_assoc()) |
|
340 | - { |
|
341 | - $expiration_date = $row["expiration_date"]; |
|
342 | - } |
|
343 | - } |
|
344 | - else |
|
345 | - { |
|
346 | - error_log('0 results'); |
|
347 | - } |
|
348 | - |
|
349 | - if($expiration_date <= time()) |
|
350 | - { |
|
351 | - return FALSE; |
|
352 | - } |
|
314 | + $accountCreator->setAccessToken($this->accessToken); |
|
315 | + $data = $accountCreator->execute(); |
|
316 | + |
|
317 | + error_log(print_r($data, true)); |
|
318 | + |
|
319 | + if(isset($_POST['ancestor'])) |
|
320 | + { |
|
321 | + header('Location: ' . $view->toUrl()); |
|
322 | + exit; |
|
323 | + } |
|
324 | + else |
|
325 | + { |
|
326 | + header('Location: ' . $view->baseUrl); |
|
327 | + exit; |
|
328 | + } |
|
329 | + } |
|
330 | + |
|
331 | + function isTokenFresh() |
|
332 | + { |
|
333 | + $db = new DatabaseConnect(); |
|
334 | + $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
335 | + |
|
336 | + if ($result->num_rows > 0) |
|
337 | + { |
|
338 | + // output data of each row |
|
339 | + while($row = $result->fetch_assoc()) |
|
340 | + { |
|
341 | + $expiration_date = $row["expiration_date"]; |
|
342 | + } |
|
343 | + } |
|
344 | + else |
|
345 | + { |
|
346 | + error_log('0 results'); |
|
347 | + } |
|
348 | + |
|
349 | + if($expiration_date <= time()) |
|
350 | + { |
|
351 | + return FALSE; |
|
352 | + } |
|
353 | 353 | |
354 | - return TRUE; |
|
355 | - } |
|
356 | - |
|
357 | - function refreshToken() |
|
358 | - { |
|
359 | - $accountCreator = new CreateUser(); |
|
360 | - $accountCreator->setAccessToken($this->accessToken); |
|
361 | - $accountCreator->setDeviceUid($this->deviceUid); |
|
362 | - $accountCreator->setLocation($this->location); |
|
363 | - $data = $accountCreator->execute(); |
|
364 | - |
|
365 | - $access_token = (string)$data[0]['access_token']; |
|
366 | - $expiration_date = $data[0]['expiration_date']; |
|
367 | - $device_uid = (string)$data[1]; |
|
354 | + return TRUE; |
|
355 | + } |
|
356 | + |
|
357 | + function refreshToken() |
|
358 | + { |
|
359 | + $accountCreator = new CreateUser(); |
|
360 | + $accountCreator->setAccessToken($this->accessToken); |
|
361 | + $accountCreator->setDeviceUid($this->deviceUid); |
|
362 | + $accountCreator->setLocation($this->location); |
|
363 | + $data = $accountCreator->execute(); |
|
364 | + |
|
365 | + $access_token = (string)$data[0]['access_token']; |
|
366 | + $expiration_date = $data[0]['expiration_date']; |
|
367 | + $device_uid = (string)$data[1]; |
|
368 | 368 | |
369 | - $db = new DatabaseConnect(); |
|
370 | - $result = $db->query("UPDATE accounts |
|
369 | + $db = new DatabaseConnect(); |
|
370 | + $result = $db->query("UPDATE accounts |
|
371 | 371 | SET access_token='" . $access_token . "', |
372 | 372 | expiration_date='" . $expiration_date . "' |
373 | 373 | WHERE device_uid='" . $device_uid . "'"); |
374 | 374 | |
375 | - if($result === false){ |
|
376 | - error_log("Adding account failed: (" . $db->errno . ") " . $db->error); |
|
377 | - } |
|
378 | - } |
|
375 | + if($result === false){ |
|
376 | + error_log("Adding account failed: (" . $db->errno . ") " . $db->error); |
|
377 | + } |
|
378 | + } |
|
379 | 379 | |
380 | 380 | |
381 | 381 | |
382 | - function getAccessToken() |
|
383 | - { |
|
384 | - $db = new DatabaseConnect(); |
|
385 | - $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
382 | + function getAccessToken() |
|
383 | + { |
|
384 | + $db = new DatabaseConnect(); |
|
385 | + $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
386 | 386 | |
387 | - $accessToken; |
|
387 | + $accessToken; |
|
388 | 388 | |
389 | - if ($result->num_rows > 0) |
|
390 | - { |
|
391 | - // output data of each row |
|
392 | - while($row = $result->fetch_assoc()) |
|
393 | - { |
|
394 | - $accessToken = $row['access_token']; |
|
395 | - } |
|
396 | - } |
|
397 | - else |
|
398 | - { |
|
399 | - error_log('Error: 0 results'); |
|
400 | - } |
|
401 | - |
|
402 | - return $accessToken; |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - function getKarma() |
|
407 | - { |
|
408 | - $accountCreator = new GetKarma(); |
|
409 | - $accountCreator->setAccessToken($this->accessToken); |
|
410 | - $data = $accountCreator->execute(); |
|
389 | + if ($result->num_rows > 0) |
|
390 | + { |
|
391 | + // output data of each row |
|
392 | + while($row = $result->fetch_assoc()) |
|
393 | + { |
|
394 | + $accessToken = $row['access_token']; |
|
395 | + } |
|
396 | + } |
|
397 | + else |
|
398 | + { |
|
399 | + error_log('Error: 0 results'); |
|
400 | + } |
|
401 | + |
|
402 | + return $accessToken; |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + function getKarma() |
|
407 | + { |
|
408 | + $accountCreator = new GetKarma(); |
|
409 | + $accountCreator->setAccessToken($this->accessToken); |
|
410 | + $data = $accountCreator->execute(); |
|
411 | 411 | |
412 | - return $data['karma']; |
|
413 | - } |
|
412 | + return $data['karma']; |
|
413 | + } |
|
414 | 414 | |
415 | - function hasVoted($postId) |
|
416 | - { |
|
417 | - $db = new DatabaseConnect(); |
|
415 | + function hasVoted($postId) |
|
416 | + { |
|
417 | + $db = new DatabaseConnect(); |
|
418 | 418 | |
419 | - $postId = $db->real_escape_string($postId); |
|
419 | + $postId = $db->real_escape_string($postId); |
|
420 | 420 | |
421 | - $result = $db->query("SELECT id FROM votes WHERE (postId = '" . $postId . "' AND device_uid = '" . $this->deviceUid . "')"); |
|
421 | + $result = $db->query("SELECT id FROM votes WHERE (postId = '" . $postId . "' AND device_uid = '" . $this->deviceUid . "')"); |
|
422 | 422 | |
423 | - if($result === false) |
|
424 | - { |
|
425 | - $error = db_error(); |
|
426 | - echo $error; |
|
427 | - error_log("Adding Vote failed: (" . $result->errno . ") " . $result->error); |
|
428 | - } |
|
429 | - |
|
430 | - if($result->num_rows == 0) |
|
431 | - { |
|
432 | - return FALSE; |
|
433 | - } |
|
434 | - else |
|
435 | - { |
|
436 | - return TRUE; |
|
437 | - } |
|
438 | - } |
|
439 | - |
|
440 | - function addVoteWithPostIdAndType($postId, $voteType) |
|
441 | - { |
|
442 | - $db = new DatabaseConnect(); |
|
443 | - |
|
444 | - $postId = $db->real_escape_string($postId); |
|
445 | - $voteType = $db->real_escape_string($voteType); |
|
423 | + if($result === false) |
|
424 | + { |
|
425 | + $error = db_error(); |
|
426 | + echo $error; |
|
427 | + error_log("Adding Vote failed: (" . $result->errno . ") " . $result->error); |
|
428 | + } |
|
429 | + |
|
430 | + if($result->num_rows == 0) |
|
431 | + { |
|
432 | + return FALSE; |
|
433 | + } |
|
434 | + else |
|
435 | + { |
|
436 | + return TRUE; |
|
437 | + } |
|
438 | + } |
|
439 | + |
|
440 | + function addVoteWithPostIdAndType($postId, $voteType) |
|
441 | + { |
|
442 | + $db = new DatabaseConnect(); |
|
443 | + |
|
444 | + $postId = $db->real_escape_string($postId); |
|
445 | + $voteType = $db->real_escape_string($voteType); |
|
446 | 446 | |
447 | - if($this->hasVoted($postId)) |
|
448 | - { |
|
449 | - return "Already voted"; |
|
450 | - } |
|
447 | + if($this->hasVoted($postId)) |
|
448 | + { |
|
449 | + return "Already voted"; |
|
450 | + } |
|
451 | 451 | |
452 | - $result = $db->query("INSERT INTO votes (device_uid, postId, type) |
|
452 | + $result = $db->query("INSERT INTO votes (device_uid, postId, type) |
|
453 | 453 | VALUES ('" . $this->deviceUid . "','" . $postId . "','" . $voteType . "')"); |
454 | 454 | |
455 | - if($result === false){ |
|
456 | - $error = db_error(); |
|
457 | - echo $error; |
|
458 | - echo "Adding Vote failed: (" . $result->errno . ") " . $result->error; |
|
459 | - } |
|
460 | - } |
|
461 | - |
|
462 | - function registerAccount($location) { |
|
463 | - $accountCreator = new CreateUser(); |
|
464 | - $accountCreator->setLocation($location); |
|
465 | - $data = $accountCreator->execute(); |
|
455 | + if($result === false){ |
|
456 | + $error = db_error(); |
|
457 | + echo $error; |
|
458 | + echo "Adding Vote failed: (" . $result->errno . ") " . $result->error; |
|
459 | + } |
|
460 | + } |
|
461 | + |
|
462 | + function registerAccount($location) { |
|
463 | + $accountCreator = new CreateUser(); |
|
464 | + $accountCreator->setLocation($location); |
|
465 | + $data = $accountCreator->execute(); |
|
466 | 466 | |
467 | - $access_token = (string)$data[0]['access_token']; |
|
468 | - $refresh_token = (string)$data[0]['refresh_token']; |
|
469 | - $token_type = (string)$data[0]['token_type']; |
|
470 | - $expires_in = $data[0]['expires_in']; |
|
471 | - $expiration_date = $data[0]['expiration_date']; |
|
472 | - $distinct_id = (string)$data[0]['distinct_id']; |
|
473 | - $device_uid = (string)$data[1]; |
|
474 | - |
|
475 | - $name = $location->cityName; |
|
476 | - $lat = $location->lat; |
|
477 | - $lng = $location->lng; |
|
467 | + $access_token = (string)$data[0]['access_token']; |
|
468 | + $refresh_token = (string)$data[0]['refresh_token']; |
|
469 | + $token_type = (string)$data[0]['token_type']; |
|
470 | + $expires_in = $data[0]['expires_in']; |
|
471 | + $expiration_date = $data[0]['expiration_date']; |
|
472 | + $distinct_id = (string)$data[0]['distinct_id']; |
|
473 | + $device_uid = (string)$data[1]; |
|
474 | + |
|
475 | + $name = $location->cityName; |
|
476 | + $lat = $location->lat; |
|
477 | + $lng = $location->lng; |
|
478 | 478 | |
479 | - $db = new DatabaseConnect(); |
|
480 | - $result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type, |
|
479 | + $db = new DatabaseConnect(); |
|
480 | + $result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type, |
|
481 | 481 | expires_in, expiration_date, distinct_id, device_uid, name, lat, lng) |
482 | 482 | VALUES ('" . $access_token . "','" . $refresh_token . "','" . $token_type . |
483 | - "','" . $expires_in . "','" . $expiration_date . "','" . $distinct_id . |
|
484 | - "','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') "); |
|
485 | - |
|
486 | - $success = TRUE; |
|
487 | - if($result === false){ |
|
488 | - $error = $db->error(); |
|
489 | - echo $error; |
|
490 | - echo "Adding account failed: (" . $result->errno . ") " . $result->error; |
|
491 | - $success = FALSE; |
|
492 | - } |
|
483 | + "','" . $expires_in . "','" . $expiration_date . "','" . $distinct_id . |
|
484 | + "','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') "); |
|
485 | + |
|
486 | + $success = TRUE; |
|
487 | + if($result === false){ |
|
488 | + $error = $db->error(); |
|
489 | + echo $error; |
|
490 | + echo "Adding account failed: (" . $result->errno . ") " . $result->error; |
|
491 | + $success = FALSE; |
|
492 | + } |
|
493 | 493 | |
494 | - return $device_uid; |
|
495 | - } |
|
494 | + return $device_uid; |
|
495 | + } |
|
496 | 496 | |
497 | - function createAccount() |
|
498 | - { |
|
499 | - $config = parse_ini_file('config/config.ini.php'); |
|
500 | - $location = new Location(); |
|
501 | - $location->setLat($config['default_lat']); |
|
502 | - $location->setLng($config['default_lng']); |
|
503 | - $location->setCityName($config['default_location']); |
|
497 | + function createAccount() |
|
498 | + { |
|
499 | + $config = parse_ini_file('config/config.ini.php'); |
|
500 | + $location = new Location(); |
|
501 | + $location->setLat($config['default_lat']); |
|
502 | + $location->setLng($config['default_lng']); |
|
503 | + $location->setCityName($config['default_location']); |
|
504 | 504 | |
505 | - $deviceUid = $this->registerAccount($location); |
|
505 | + $deviceUid = $this->registerAccount($location); |
|
506 | 506 | |
507 | - return $deviceUid; |
|
508 | - } |
|
507 | + return $deviceUid; |
|
508 | + } |
|
509 | 509 | } |
510 | 510 | \ No newline at end of file |
@@ -2,20 +2,20 @@ 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 = 'SDydTnTdqqaiAMfneLkqXYxamvNuUYOmkqpdiZTu'; |
|
8 | - const USERAGENT = 'Jodel/4.34.2 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
|
9 | - const CLIENT_TYPE = 'android_4.34.2'; |
|
5 | + const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
6 | + const APIURL = 'https://api.go-tellm.com/api'; |
|
7 | + const SECRET = 'SDydTnTdqqaiAMfneLkqXYxamvNuUYOmkqpdiZTu'; |
|
8 | + const USERAGENT = 'Jodel/4.34.2 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
|
9 | + const CLIENT_TYPE = 'android_4.34.2'; |
|
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 | - { |
|
17 | + public function execute() |
|
18 | + { |
|
19 | 19 | $result = new \stdClass(); |
20 | 20 | |
21 | 21 | $this->payLoad = $this->getPayload(); |
@@ -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,85 +45,85 @@ 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 | - } |
|
73 | - switch ($result->status_code) { |
|
74 | - case 200: |
|
75 | - $result = json_decode($result->body, true); |
|
76 | - break; |
|
77 | - case 204: |
|
78 | - $result = "Success"; |
|
79 | - break; |
|
80 | - case 400: |
|
81 | - error_log('Error 400 - Fehlerhafte Anfrage'); |
|
82 | - $result = json_decode($result->body, true); |
|
83 | - break; |
|
84 | - case 401: |
|
85 | - error_log('Error 401 - Unauthorized'); |
|
86 | - $result = json_decode($result->body, true); |
|
87 | - break; |
|
88 | - case 404: |
|
89 | - error_log('Error 404 - Es wurde bereits gevoted'); |
|
90 | - $result = json_decode($result->body, true); |
|
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 | + switch ($result->status_code) { |
|
74 | + case 200: |
|
75 | + $result = json_decode($result->body, true); |
|
76 | + break; |
|
77 | + case 204: |
|
78 | + $result = "Success"; |
|
79 | + break; |
|
80 | + case 400: |
|
81 | + error_log('Error 400 - Fehlerhafte Anfrage'); |
|
82 | + $result = json_decode($result->body, true); |
|
83 | + break; |
|
84 | + case 401: |
|
85 | + error_log('Error 401 - Unauthorized'); |
|
86 | + $result = json_decode($result->body, true); |
|
87 | + break; |
|
88 | + case 404: |
|
89 | + error_log('Error 404 - Es wurde bereits gevoted'); |
|
90 | + $result = json_decode($result->body, true); |
|
91 | 91 | case 477: |
92 | - error_log('Error 477 - Signing failed'); |
|
93 | - $result = json_decode($result->body, true); |
|
94 | - break; |
|
95 | - case 429: |
|
96 | - error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true)); |
|
97 | - exit("Error 429: Too Many Requests"); |
|
98 | - break; |
|
99 | - case 403: |
|
100 | - error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true)); |
|
101 | - exit("Error 403: Access denied"); |
|
102 | - break; |
|
103 | - default: |
|
104 | - error_log('Error '.$result->status_code.' - Unauthorized'); |
|
105 | - $result = json_decode($result->body, true); |
|
106 | - } |
|
92 | + error_log('Error 477 - Signing failed'); |
|
93 | + $result = json_decode($result->body, true); |
|
94 | + break; |
|
95 | + case 429: |
|
96 | + error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true)); |
|
97 | + exit("Error 429: Too Many Requests"); |
|
98 | + break; |
|
99 | + case 403: |
|
100 | + error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true)); |
|
101 | + exit("Error 403: Access denied"); |
|
102 | + break; |
|
103 | + default: |
|
104 | + error_log('Error '.$result->status_code.' - Unauthorized'); |
|
105 | + $result = json_decode($result->body, true); |
|
106 | + } |
|
107 | 107 | |
108 | - //important for account refresh |
|
109 | - if($device_uid != '') |
|
110 | - { |
|
108 | + //important for account refresh |
|
109 | + if($device_uid != '') |
|
110 | + { |
|
111 | 111 | $result[0] = $result; |
112 | 112 | $result[1] = $device_uid; |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | 115 | |
116 | - /* var_dump($result); */ |
|
116 | + /* var_dump($result); */ |
|
117 | 117 | |
118 | - return $result; |
|
119 | - } |
|
120 | - abstract function getPayload(); |
|
121 | - /** |
|
122 | - * Gets Sign headers |
|
123 | - * @return array headers |
|
124 | - */ |
|
125 | - private function getSignHeaders() |
|
126 | - { |
|
118 | + return $result; |
|
119 | + } |
|
120 | + abstract function getPayload(); |
|
121 | + /** |
|
122 | + * Gets Sign headers |
|
123 | + * @return array headers |
|
124 | + */ |
|
125 | + private function getSignHeaders() |
|
126 | + { |
|
127 | 127 | if($this->getAccessToken() == null) { |
128 | 128 | $payload_accessToken = ""; |
129 | 129 | } |
@@ -132,54 +132,54 @@ discard block |
||
132 | 132 | } |
133 | 133 | |
134 | 134 | |
135 | - $headers = array( |
|
136 | - "Connection" => "keep-alive", |
|
137 | - "Accept-Encoding" => "gzip", |
|
138 | - "Content-Type" => "application/json; charset=UTF-8", |
|
139 | - "User-Agent" => self::USERAGENT |
|
140 | - ); |
|
141 | - $timestamp = new DateTime(); |
|
142 | - $timestamp = $timestamp->format(DateTime::ATOM); |
|
143 | - $timestamp = substr($timestamp, 0, -6); |
|
144 | - $timestamp .= "Z"; |
|
145 | - $urlParts = parse_url($this->getFullUrl()); |
|
146 | - $url2 = ""; |
|
147 | - $req = [$this->getMethod(), |
|
148 | - $urlParts['host'], |
|
149 | - "443", |
|
150 | - $urlParts['path'], |
|
151 | - $payload_accessToken, |
|
152 | - $timestamp, |
|
153 | - $url2, |
|
154 | - $this->payLoad]; |
|
155 | - $reqString = implode("%", $req); |
|
156 | - $secret = self::SECRET; |
|
157 | - $signature = hash_hmac('sha1', $reqString, $secret); |
|
158 | - $signature = strtoupper($signature); |
|
159 | - $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
160 | - $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
161 | - $headers['X-Timestamp'] = $timestamp; |
|
162 | - $headers['X-Api-Version'] = '0.2'; |
|
163 | - return $headers; |
|
164 | - } |
|
165 | - private function getFullUrl() |
|
166 | - { |
|
167 | - return self::APIURL . $this->getApiEndPoint(); |
|
168 | - } |
|
169 | - abstract function getApiEndPoint(); |
|
170 | - abstract function getMethod(); |
|
171 | - /** |
|
172 | - * @return string |
|
173 | - */ |
|
174 | - private function getAccessToken() |
|
175 | - { |
|
176 | - return $this->accessToken; |
|
177 | - } |
|
178 | - /** |
|
179 | - * @param string $accessToken |
|
180 | - */ |
|
181 | - public function setAccessToken($accessToken) |
|
182 | - { |
|
183 | - $this->accessToken = $accessToken; |
|
184 | - } |
|
135 | + $headers = array( |
|
136 | + "Connection" => "keep-alive", |
|
137 | + "Accept-Encoding" => "gzip", |
|
138 | + "Content-Type" => "application/json; charset=UTF-8", |
|
139 | + "User-Agent" => self::USERAGENT |
|
140 | + ); |
|
141 | + $timestamp = new DateTime(); |
|
142 | + $timestamp = $timestamp->format(DateTime::ATOM); |
|
143 | + $timestamp = substr($timestamp, 0, -6); |
|
144 | + $timestamp .= "Z"; |
|
145 | + $urlParts = parse_url($this->getFullUrl()); |
|
146 | + $url2 = ""; |
|
147 | + $req = [$this->getMethod(), |
|
148 | + $urlParts['host'], |
|
149 | + "443", |
|
150 | + $urlParts['path'], |
|
151 | + $payload_accessToken, |
|
152 | + $timestamp, |
|
153 | + $url2, |
|
154 | + $this->payLoad]; |
|
155 | + $reqString = implode("%", $req); |
|
156 | + $secret = self::SECRET; |
|
157 | + $signature = hash_hmac('sha1', $reqString, $secret); |
|
158 | + $signature = strtoupper($signature); |
|
159 | + $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
160 | + $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
161 | + $headers['X-Timestamp'] = $timestamp; |
|
162 | + $headers['X-Api-Version'] = '0.2'; |
|
163 | + return $headers; |
|
164 | + } |
|
165 | + private function getFullUrl() |
|
166 | + { |
|
167 | + return self::APIURL . $this->getApiEndPoint(); |
|
168 | + } |
|
169 | + abstract function getApiEndPoint(); |
|
170 | + abstract function getMethod(); |
|
171 | + /** |
|
172 | + * @return string |
|
173 | + */ |
|
174 | + private function getAccessToken() |
|
175 | + { |
|
176 | + return $this->accessToken; |
|
177 | + } |
|
178 | + /** |
|
179 | + * @param string $accessToken |
|
180 | + */ |
|
181 | + public function setAccessToken($accessToken) |
|
182 | + { |
|
183 | + $this->accessToken = $accessToken; |
|
184 | + } |
|
185 | 185 | } |