@@ -278,6 +278,9 @@ |
||
| 278 | 278 | return $data["karma"]; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | +/** |
|
| 282 | + * @param string $postId |
|
| 283 | + */ |
|
| 281 | 284 | function deviceUidHasVotedThisPostId($deviceUid, $postId) |
| 282 | 285 | { |
| 283 | 286 | $db = new DatabaseConnect(); |
@@ -43,7 +43,8 @@ discard block |
||
| 43 | 43 | if ($result->num_rows > 0) |
| 44 | 44 | { |
| 45 | 45 | // output data of each row |
| 46 | - while($row = $result->fetch_assoc()) { |
|
| 46 | + while($row = $result->fetch_assoc()) |
|
| 47 | + { |
|
| 47 | 48 | //$access_token = $row["access_token"]; |
| 48 | 49 | $expiration_date = $row["expiration_date"]; |
| 49 | 50 | $deviceUid = $row["device_uid"]; |
@@ -55,7 +56,8 @@ discard block |
||
| 55 | 56 | echo '0 results'; |
| 56 | 57 | } |
| 57 | 58 | |
| 58 | - if($expiration_date <= time()) { |
|
| 59 | + if($expiration_date <= time()) |
|
| 60 | + { |
|
| 59 | 61 | $accountCreator = new CreateUser(); |
| 60 | 62 | $accountCreator->setAccessToken($access_token);//$accountData->getAccessToken()); |
| 61 | 63 | $accountCreator->setDeviceUid($deviceUid); |
@@ -72,7 +74,8 @@ discard block |
||
| 72 | 74 | expiration_date='" . $expiration_date . "' |
| 73 | 75 | WHERE device_uid='" . $device_uid . "'"); |
| 74 | 76 | |
| 75 | - if($result === false){ |
|
| 77 | + if($result === false) |
|
| 78 | + { |
|
| 76 | 79 | echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
| 77 | 80 | } |
| 78 | 81 | } |
@@ -88,7 +91,8 @@ discard block |
||
| 88 | 91 | if ($result->num_rows > 0) |
| 89 | 92 | { |
| 90 | 93 | // output data of each row |
| 91 | - while($row = $result->fetch_assoc()) { |
|
| 94 | + while($row = $result->fetch_assoc()) |
|
| 95 | + { |
|
| 92 | 96 | //$access_token = $row["access_token"]; |
| 93 | 97 | $expiration_date = $row["expiration_date"]; |
| 94 | 98 | $deviceUid = $row["device_uid"]; |
@@ -100,7 +104,8 @@ discard block |
||
| 100 | 104 | echo '0 results'; |
| 101 | 105 | } |
| 102 | 106 | |
| 103 | - if($expiration_date <= time()) { |
|
| 107 | + if($expiration_date <= time()) |
|
| 108 | + { |
|
| 104 | 109 | $accountCreator = new CreateUser(); |
| 105 | 110 | $accountCreator->setAccessToken($access_token);//$accountData->getAccessToken()); |
| 106 | 111 | $accountCreator->setDeviceUid($deviceUid); |
@@ -117,7 +122,8 @@ discard block |
||
| 117 | 122 | expiration_date='" . $expiration_date . "' |
| 118 | 123 | WHERE device_uid='" . $device_uid . "'"); |
| 119 | 124 | |
| 120 | - if($result === false){ |
|
| 125 | + if($result === false) |
|
| 126 | + { |
|
| 121 | 127 | echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
| 122 | 128 | } |
| 123 | 129 | } |
@@ -135,7 +141,8 @@ discard block |
||
| 135 | 141 | if ($result->num_rows > 0) |
| 136 | 142 | { |
| 137 | 143 | // output data of each row |
| 138 | - while($row = $result->fetch_assoc()) { |
|
| 144 | + while($row = $result->fetch_assoc()) |
|
| 145 | + { |
|
| 139 | 146 | //$access_token = $row["access_token"]; |
| 140 | 147 | $expiration_date = $row["expiration_date"]; |
| 141 | 148 | $deviceUid = $row["device_uid"]; |
@@ -147,7 +154,8 @@ discard block |
||
| 147 | 154 | echo '0 results'; |
| 148 | 155 | } |
| 149 | 156 | |
| 150 | - if($expiration_date <= time()) { |
|
| 157 | + if($expiration_date <= time()) |
|
| 158 | + { |
|
| 151 | 159 | $accountCreator = new CreateUser(); |
| 152 | 160 | $accountCreator->setAccessToken($access_token); |
| 153 | 161 | $accountCreator->setDeviceUid($deviceUid); |
@@ -164,7 +172,8 @@ discard block |
||
| 164 | 172 | expiration_date='" . $expiration_date . "' |
| 165 | 173 | WHERE device_uid='" . $device_uid . "'"); |
| 166 | 174 | |
| 167 | - if($result === false){ |
|
| 175 | + if($result === false) |
|
| 176 | + { |
|
| 168 | 177 | echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
| 169 | 178 | } |
| 170 | 179 | } |
@@ -320,14 +329,16 @@ discard block |
||
| 320 | 329 | $result = $db->query("INSERT INTO votes (device_uid, postId, type) |
| 321 | 330 | VALUES ('" . $device_uid . "','" . $postId . "','" . $voteType . "')"); |
| 322 | 331 | |
| 323 | - if($result === false){ |
|
| 332 | + if($result === false) |
|
| 333 | + { |
|
| 324 | 334 | $error = db_error(); |
| 325 | 335 | echo $error; |
| 326 | 336 | echo "Adding Vote failed: (" . $result->errno . ") " . $result->error; |
| 327 | 337 | } |
| 328 | 338 | } |
| 329 | 339 | |
| 330 | -function registerAccount(Location $location) { |
|
| 340 | +function registerAccount(Location $location) |
|
| 341 | +{ |
|
| 331 | 342 | $accountCreator = new CreateUser(); |
| 332 | 343 | $accountCreator->setLocation($location); |
| 333 | 344 | $data = $accountCreator->execute(); |
@@ -352,7 +363,8 @@ discard block |
||
| 352 | 363 | "','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') "); |
| 353 | 364 | |
| 354 | 365 | $success = TRUE; |
| 355 | - if($result === false){ |
|
| 366 | + if($result === false) |
|
| 367 | + { |
|
| 356 | 368 | $error = db_error(); |
| 357 | 369 | echo $error; |
| 358 | 370 | echo "Adding account failed: (" . $result->errno . ") " . $result->error; |
@@ -363,7 +375,7 @@ discard block |
||
| 363 | 375 | } |
| 364 | 376 | |
| 365 | 377 | function getPosts($lastPostId, $accessToken, $url, $version = 'v2') |
| 366 | -{ |
|
| 378 | +{ |
|
| 367 | 379 | $accountCreator = new GetPosts(); |
| 368 | 380 | $accountCreator->setLastPostId($lastPostId); |
| 369 | 381 | $accountCreator->setAccessToken($accessToken); |
@@ -414,7 +426,8 @@ discard block |
||
| 414 | 426 | } |
| 415 | 427 | |
| 416 | 428 | function jodelToHtml($post, $view = 'time', $isDetailedView = FALSE) |
| 417 | -{ //ToDO |
|
| 429 | +{ |
|
| 430 | +//ToDO |
|
| 418 | 431 | //Replace # with link |
| 419 | 432 | //preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text); |
| 420 | 433 | |
@@ -464,10 +477,12 @@ discard block |
||
| 464 | 477 | <article id ="postId-<?php echo $post["post_id"]; ?>" class="jodel" style="background-color: #<?php echo $post["color"];?>;"> |
| 465 | 478 | <content> |
| 466 | 479 | <?php |
| 467 | - if(isset($post["image_url"])) { |
|
| 480 | + if(isset($post["image_url"])) |
|
| 481 | + { |
|
| 468 | 482 | echo '<img src="' . $post["image_url"] . '">'; |
| 469 | 483 | } |
| 470 | - else { |
|
| 484 | + else |
|
| 485 | + { |
|
| 471 | 486 | echo str_replace(' ', ' ', nl2br(htmlspecialchars($post["message"]))); |
| 472 | 487 | } |
| 473 | 488 | ?> |
@@ -475,11 +490,13 @@ discard block |
||
| 475 | 490 | <aside> |
| 476 | 491 | <?php |
| 477 | 492 | if($isDetailedView) |
| 478 | - {?> |
|
| 493 | + { |
|
| 494 | +?> |
|
| 479 | 495 | <a href="index.php?vote=up&getPostDetails=true&postID=<?php echo $post['post_id'];?>&postID_parent=<?php echo htmlspecialchars($_GET['postID']);?>"> |
| 480 | 496 | <?php } |
| 481 | - else |
|
| 482 | - {?> |
|
| 497 | +else |
|
| 498 | + { |
|
| 499 | +?> |
|
| 483 | 500 | <a href="index.php?vote=up&postID=<?php echo $post['post_id'];?>"> |
| 484 | 501 | <?php } ?> |
| 485 | 502 | <i class="fa fa-angle-up fa-3x"></i> |
@@ -488,11 +505,13 @@ discard block |
||
| 488 | 505 | <?php echo $post["vote_count"];?><br /> |
| 489 | 506 | <?php |
| 490 | 507 | if($isDetailedView) |
| 491 | - {?> |
|
| 508 | + { |
|
| 509 | +?> |
|
| 492 | 510 | <a href="index.php?vote=down&getPostDetails=true&postID=<?php echo $post['post_id'];?>&postID_parent=<?php echo htmlspecialchars($_GET['postID']);?>"> |
| 493 | 511 | <?php } |
| 494 | - else |
|
| 495 | - {?> |
|
| 512 | +else |
|
| 513 | + { |
|
| 514 | +?> |
|
| 496 | 515 | <a href="index.php?vote=down&postID=<?php echo $post['post_id'];?>"> |
| 497 | 516 | <?php } ?> |
| 498 | 517 | <i class="fa fa-angle-down fa-3x"></i> |
@@ -510,13 +529,19 @@ discard block |
||
| 510 | 529 | </span> |
| 511 | 530 | </td> |
| 512 | 531 | <td class="comments"> |
| 513 | - <?php if(!$isDetailedView) {?> |
|
| 532 | + <?php if(!$isDetailedView) |
|
| 533 | +{ |
|
| 534 | +?> |
|
| 514 | 535 | <span data-tooltip="Comments"> |
| 515 | 536 | <a href="index.php?getPostDetails=true&view=<?php echo $view;?>&postID=<?php echo $post["post_id"];?>"> |
| 516 | 537 | <i class="fa fa-commenting-o"></i> |
| 517 | - <?php if(array_key_exists("child_count", $post)) { |
|
| 538 | + <?php if(array_key_exists("child_count", $post)) |
|
| 539 | +{ |
|
| 518 | 540 | echo $post["child_count"]; |
| 519 | - } else echo "0"; |
|
| 541 | + } |
|
| 542 | + else { |
|
| 543 | + echo "0"; |
|
| 544 | + } |
|
| 520 | 545 | ?> |
| 521 | 546 | </a> |
| 522 | 547 | </span> |
@@ -1,21 +1,21 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class Upvote extends AbstractRequest { |
| 3 | 3 | |
| 4 | - public $postId; |
|
| 4 | + public $postId; |
|
| 5 | 5 | |
| 6 | - function getApiEndPoint() |
|
| 7 | - { |
|
| 8 | - return '/v2/posts/' . $this->postId . '/upvote'; |
|
| 9 | - } |
|
| 10 | - function getPayload() |
|
| 11 | - { |
|
| 12 | - return array( |
|
| 6 | + function getApiEndPoint() |
|
| 7 | + { |
|
| 8 | + return '/v2/posts/' . $this->postId . '/upvote'; |
|
| 9 | + } |
|
| 10 | + function getPayload() |
|
| 11 | + { |
|
| 12 | + return array( |
|
| 13 | 13 | // "reason_code" => -1, |
| 14 | - ); |
|
| 15 | - } |
|
| 16 | - function getMethod() |
|
| 17 | - { |
|
| 18 | - return 'PUT'; |
|
| 19 | - } |
|
| 14 | + ); |
|
| 15 | + } |
|
| 16 | + function getMethod() |
|
| 17 | + { |
|
| 18 | + return 'PUT'; |
|
| 19 | + } |
|
| 20 | 20 | } |
| 21 | 21 | |
@@ -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,15 +24,15 @@ 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: |
|
| 35 | - /* |
|
| 31 | + if ($this->getAccessToken()) { |
|
| 32 | + $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
| 33 | + } |
|
| 34 | + //Comment out to debug the Request: |
|
| 35 | + /* |
|
| 36 | 36 | printf("URL: "); |
| 37 | 37 | var_dump($url); |
| 38 | 38 | echo "<br />"; |
@@ -43,82 +43,82 @@ discard block |
||
| 43 | 43 | var_dump($this->payLoad); |
| 44 | 44 | echo "<br />"; |
| 45 | 45 | */ |
| 46 | - /* |
|
| 46 | + /* |
|
| 47 | 47 | $options = array( |
| 48 | 48 | 'timeout' => 100, |
| 49 | 49 | 'connect_timeout' => 100, |
| 50 | 50 | 'proxy' => '186.103.169.165:8080', |
| 51 | 51 | );*/ |
| 52 | 52 | |
| 53 | - switch ($this->getMethod()) { |
|
| 54 | - case 'POST': |
|
| 55 | - $result = Requests::post($url, $header, $this->payLoad); |
|
| 56 | - break; |
|
| 57 | - case 'GET': |
|
| 58 | - if($this->version == 'v3') |
|
| 59 | - { |
|
| 60 | - $result = Requests::get($url, $header); |
|
| 61 | - } |
|
| 62 | - else |
|
| 63 | - { |
|
| 64 | - $result = Requests::get($url, $header); |
|
| 65 | - } |
|
| 66 | - break; |
|
| 67 | - case 'PUT': |
|
| 68 | - $result = Requests::put($url, $header);//, $this->payLoad); |
|
| 69 | - break; |
|
| 70 | - } |
|
| 71 | - switch ($result->status_code) { |
|
| 72 | - case 200: |
|
| 73 | - $result = json_decode($result->body, true); |
|
| 74 | - break; |
|
| 75 | - case 204: |
|
| 76 | - $result = "Success"; |
|
| 77 | - break; |
|
| 78 | - case 401: |
|
| 53 | + switch ($this->getMethod()) { |
|
| 54 | + case 'POST': |
|
| 55 | + $result = Requests::post($url, $header, $this->payLoad); |
|
| 56 | + break; |
|
| 57 | + case 'GET': |
|
| 58 | + if($this->version == 'v3') |
|
| 59 | + { |
|
| 60 | + $result = Requests::get($url, $header); |
|
| 61 | + } |
|
| 62 | + else |
|
| 63 | + { |
|
| 64 | + $result = Requests::get($url, $header); |
|
| 65 | + } |
|
| 66 | + break; |
|
| 67 | + case 'PUT': |
|
| 68 | + $result = Requests::put($url, $header);//, $this->payLoad); |
|
| 69 | + break; |
|
| 70 | + } |
|
| 71 | + switch ($result->status_code) { |
|
| 72 | + case 200: |
|
| 73 | + $result = json_decode($result->body, true); |
|
| 74 | + break; |
|
| 75 | + case 204: |
|
| 76 | + $result = "Success"; |
|
| 77 | + break; |
|
| 78 | + case 401: |
|
| 79 | 79 | //throw new \Exception('Unauthorized'); |
| 80 | - error_log('Error 401 - Unauthorized'); // - JodelDeviceId:' . $deviceUid); |
|
| 81 | - break; |
|
| 82 | - case 404: |
|
| 83 | - //echo "Es wurde bereits gevoted"; |
|
| 84 | - error_log('Error 404 - Es wurde bereits gevoted'); // - JodelDeviceId:' . $deviceUid); |
|
| 80 | + error_log('Error 401 - Unauthorized'); // - JodelDeviceId:' . $deviceUid); |
|
| 81 | + break; |
|
| 82 | + case 404: |
|
| 83 | + //echo "Es wurde bereits gevoted"; |
|
| 84 | + error_log('Error 404 - Es wurde bereits gevoted'); // - JodelDeviceId:' . $deviceUid); |
|
| 85 | 85 | case 477: |
| 86 | - //echo "Es wurde bereits gevoted"; |
|
| 87 | - //throw new \Exception('Signing failed!'); |
|
| 88 | - error_log('Error 477 - Signing failed'); // - JodelDeviceId:' . $deviceUid); |
|
| 89 | - break; |
|
| 90 | - case 429: |
|
| 91 | - error_log('Error 429 - Too Many Requests'); // - JodelDeviceId:' . $deviceUid); |
|
| 92 | - exit("Error 429: Too Many Requests"); |
|
| 93 | - break; |
|
| 94 | - case 403: |
|
| 95 | - error_log('Error 403 - Access denied'); // - JodelDeviceId:' . $deviceUid); |
|
| 96 | - exit("Error 403: Access denied"); |
|
| 97 | - break; |
|
| 98 | - default: |
|
| 99 | - error_log('Error '.$result->status_code.' - Unauthorized'); // - JodelDeviceId:' . $deviceUid); |
|
| 100 | - //throw new \Exception('Unknown Error: '.$result->status_code); |
|
| 101 | - } |
|
| 86 | + //echo "Es wurde bereits gevoted"; |
|
| 87 | + //throw new \Exception('Signing failed!'); |
|
| 88 | + error_log('Error 477 - Signing failed'); // - JodelDeviceId:' . $deviceUid); |
|
| 89 | + break; |
|
| 90 | + case 429: |
|
| 91 | + error_log('Error 429 - Too Many Requests'); // - JodelDeviceId:' . $deviceUid); |
|
| 92 | + exit("Error 429: Too Many Requests"); |
|
| 93 | + break; |
|
| 94 | + case 403: |
|
| 95 | + error_log('Error 403 - Access denied'); // - JodelDeviceId:' . $deviceUid); |
|
| 96 | + exit("Error 403: Access denied"); |
|
| 97 | + break; |
|
| 98 | + default: |
|
| 99 | + error_log('Error '.$result->status_code.' - Unauthorized'); // - JodelDeviceId:' . $deviceUid); |
|
| 100 | + //throw new \Exception('Unknown Error: '.$result->status_code); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - if($device_uid != '') |
|
| 104 | - { |
|
| 103 | + if($device_uid != '') |
|
| 104 | + { |
|
| 105 | 105 | $result[0] = $result; |
| 106 | 106 | $result[1] = $device_uid; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - /* |
|
| 109 | + /* |
|
| 110 | 110 | var_dump($result); |
| 111 | 111 | */ |
| 112 | 112 | |
| 113 | - return $result; |
|
| 114 | - } |
|
| 115 | - abstract function getPayload(); |
|
| 116 | - /** |
|
| 117 | - * Gets Sign headers |
|
| 118 | - * @return array headers |
|
| 119 | - */ |
|
| 120 | - private function getSignHeaders() |
|
| 121 | - { |
|
| 113 | + return $result; |
|
| 114 | + } |
|
| 115 | + abstract function getPayload(); |
|
| 116 | + /** |
|
| 117 | + * Gets Sign headers |
|
| 118 | + * @return array headers |
|
| 119 | + */ |
|
| 120 | + private function getSignHeaders() |
|
| 121 | + { |
|
| 122 | 122 | if($this->getAccessToken() == null) { |
| 123 | 123 | $payload_accessToken = ""; |
| 124 | 124 | } |
@@ -127,54 +127,54 @@ discard block |
||
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | |
| 130 | - $headers = array( |
|
| 131 | - "Connection" => "keep-alive", |
|
| 132 | - "Accept-Encoding" => "gzip", |
|
| 133 | - "Content-Type" => "application/json; charset=UTF-8", |
|
| 134 | - "User-Agent" => self::USERAGENT |
|
| 135 | - ); |
|
| 136 | - $timestamp = new DateTime(); |
|
| 137 | - $timestamp = $timestamp->format(DateTime::ATOM); |
|
| 138 | - $timestamp = substr($timestamp, 0, -6); |
|
| 139 | - $timestamp .= "Z"; |
|
| 140 | - $urlParts = parse_url($this->getFullUrl()); |
|
| 141 | - $url2 = ""; |
|
| 142 | - $req = [$this->getMethod(), |
|
| 143 | - $urlParts['host'], |
|
| 144 | - "443", |
|
| 145 | - $urlParts['path'], |
|
| 146 | - $payload_accessToken, |
|
| 147 | - $timestamp, |
|
| 148 | - $url2, |
|
| 149 | - $this->payLoad]; |
|
| 150 | - $reqString = implode("%", $req); |
|
| 151 | - $secret = self::SECRET; |
|
| 152 | - $signature = hash_hmac('sha1', $reqString, $secret); |
|
| 153 | - $signature = strtoupper($signature); |
|
| 154 | - $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
| 155 | - $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
| 156 | - $headers['X-Timestamp'] = $timestamp; |
|
| 157 | - $headers['X-Api-Version'] = '0.2'; |
|
| 158 | - return $headers; |
|
| 159 | - } |
|
| 160 | - private function getFullUrl() |
|
| 161 | - { |
|
| 162 | - return self::APIURL . $this->getApiEndPoint(); |
|
| 163 | - } |
|
| 164 | - abstract function getApiEndPoint(); |
|
| 165 | - abstract function getMethod(); |
|
| 166 | - /** |
|
| 167 | - * @return string |
|
| 168 | - */ |
|
| 169 | - private function getAccessToken() |
|
| 170 | - { |
|
| 171 | - return $this->accessToken; |
|
| 172 | - } |
|
| 173 | - /** |
|
| 174 | - * @param string $accessToken |
|
| 175 | - */ |
|
| 176 | - public function setAccessToken($accessToken) |
|
| 177 | - { |
|
| 178 | - $this->accessToken = $accessToken; |
|
| 179 | - } |
|
| 130 | + $headers = array( |
|
| 131 | + "Connection" => "keep-alive", |
|
| 132 | + "Accept-Encoding" => "gzip", |
|
| 133 | + "Content-Type" => "application/json; charset=UTF-8", |
|
| 134 | + "User-Agent" => self::USERAGENT |
|
| 135 | + ); |
|
| 136 | + $timestamp = new DateTime(); |
|
| 137 | + $timestamp = $timestamp->format(DateTime::ATOM); |
|
| 138 | + $timestamp = substr($timestamp, 0, -6); |
|
| 139 | + $timestamp .= "Z"; |
|
| 140 | + $urlParts = parse_url($this->getFullUrl()); |
|
| 141 | + $url2 = ""; |
|
| 142 | + $req = [$this->getMethod(), |
|
| 143 | + $urlParts['host'], |
|
| 144 | + "443", |
|
| 145 | + $urlParts['path'], |
|
| 146 | + $payload_accessToken, |
|
| 147 | + $timestamp, |
|
| 148 | + $url2, |
|
| 149 | + $this->payLoad]; |
|
| 150 | + $reqString = implode("%", $req); |
|
| 151 | + $secret = self::SECRET; |
|
| 152 | + $signature = hash_hmac('sha1', $reqString, $secret); |
|
| 153 | + $signature = strtoupper($signature); |
|
| 154 | + $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
| 155 | + $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
| 156 | + $headers['X-Timestamp'] = $timestamp; |
|
| 157 | + $headers['X-Api-Version'] = '0.2'; |
|
| 158 | + return $headers; |
|
| 159 | + } |
|
| 160 | + private function getFullUrl() |
|
| 161 | + { |
|
| 162 | + return self::APIURL . $this->getApiEndPoint(); |
|
| 163 | + } |
|
| 164 | + abstract function getApiEndPoint(); |
|
| 165 | + abstract function getMethod(); |
|
| 166 | + /** |
|
| 167 | + * @return string |
|
| 168 | + */ |
|
| 169 | + private function getAccessToken() |
|
| 170 | + { |
|
| 171 | + return $this->accessToken; |
|
| 172 | + } |
|
| 173 | + /** |
|
| 174 | + * @param string $accessToken |
|
| 175 | + */ |
|
| 176 | + public function setAccessToken($accessToken) |
|
| 177 | + { |
|
| 178 | + $this->accessToken = $accessToken; |
|
| 179 | + } |
|
| 180 | 180 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | $header = $this->getSignHeaders(); |
| 29 | 29 | $url = $this->getFullUrl(); |
| 30 | 30 | |
| 31 | - if ($this->getAccessToken()) { |
|
| 31 | + if($this->getAccessToken()) { |
|
| 32 | 32 | $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
| 33 | 33 | } |
| 34 | 34 | //Comment out to debug the Request: |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | 'proxy' => '186.103.169.165:8080', |
| 51 | 51 | );*/ |
| 52 | 52 | |
| 53 | - switch ($this->getMethod()) { |
|
| 53 | + switch($this->getMethod()) { |
|
| 54 | 54 | case 'POST': |
| 55 | 55 | $result = Requests::post($url, $header, $this->payLoad); |
| 56 | 56 | break; |
@@ -65,10 +65,10 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | break; |
| 67 | 67 | case 'PUT': |
| 68 | - $result = Requests::put($url, $header);//, $this->payLoad); |
|
| 68 | + $result = Requests::put($url, $header); //, $this->payLoad); |
|
| 69 | 69 | break; |
| 70 | 70 | } |
| 71 | - switch ($result->status_code) { |
|
| 71 | + switch($result->status_code) { |
|
| 72 | 72 | case 200: |
| 73 | 73 | $result = json_decode($result->body, true); |
| 74 | 74 | break; |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | exit("Error 403: Access denied"); |
| 97 | 97 | break; |
| 98 | 98 | default: |
| 99 | - error_log('Error '.$result->status_code.' - Unauthorized'); // - JodelDeviceId:' . $deviceUid); |
|
| 99 | + error_log('Error ' . $result->status_code . ' - Unauthorized'); // - JodelDeviceId:' . $deviceUid); |
|
| 100 | 100 | //throw new \Exception('Unknown Error: '.$result->status_code); |
| 101 | 101 | } |
| 102 | 102 | |
@@ -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: |
@@ -50,7 +52,8 @@ discard block |
||
| 50 | 52 | 'proxy' => '186.103.169.165:8080', |
| 51 | 53 | );*/ |
| 52 | 54 | |
| 53 | - switch ($this->getMethod()) { |
|
| 55 | + switch ($this->getMethod()) |
|
| 56 | + { |
|
| 54 | 57 | case 'POST': |
| 55 | 58 | $result = Requests::post($url, $header, $this->payLoad); |
| 56 | 59 | break; |
@@ -68,7 +71,8 @@ discard block |
||
| 68 | 71 | $result = Requests::put($url, $header);//, $this->payLoad); |
| 69 | 72 | break; |
| 70 | 73 | } |
| 71 | - switch ($result->status_code) { |
|
| 74 | + switch ($result->status_code) |
|
| 75 | + { |
|
| 72 | 76 | case 200: |
| 73 | 77 | $result = json_decode($result->body, true); |
| 74 | 78 | break; |
@@ -119,10 +123,12 @@ discard block |
||
| 119 | 123 | */ |
| 120 | 124 | private function getSignHeaders() |
| 121 | 125 | { |
| 122 | - if($this->getAccessToken() == null) { |
|
| 126 | + if($this->getAccessToken() == null) |
|
| 127 | + { |
|
| 123 | 128 | $payload_accessToken = ""; |
| 124 | 129 | } |
| 125 | - else { |
|
| 130 | + else |
|
| 131 | + { |
|
| 126 | 132 | $payload_accessToken = $this->getAccessToken(); |
| 127 | 133 | } |
| 128 | 134 | |