@@ -13,6 +13,9 @@ discard block |
||
| 13 | 13 | return $this->cityName; |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | + /** |
|
| 17 | + * @param string $cityName |
|
| 18 | + */ |
|
| 16 | 19 | public function setCityName($cityName) |
| 17 | 20 | { |
| 18 | 21 | $this->cityName = $cityName; |
@@ -23,6 +26,9 @@ discard block |
||
| 23 | 26 | return $this->lat; |
| 24 | 27 | } |
| 25 | 28 | |
| 29 | + /** |
|
| 30 | + * @param double $lat |
|
| 31 | + */ |
|
| 26 | 32 | public function setLat($lat) |
| 27 | 33 | { |
| 28 | 34 | $this->lat = $lat; |
@@ -33,6 +39,9 @@ discard block |
||
| 33 | 39 | return $this->lng; |
| 34 | 40 | } |
| 35 | 41 | |
| 42 | + /** |
|
| 43 | + * @param double $lng |
|
| 44 | + */ |
|
| 36 | 45 | public function setLng($lng) |
| 37 | 46 | { |
| 38 | 47 | $this->lng = $lng; |
@@ -2,51 +2,51 @@ |
||
| 2 | 2 | |
| 3 | 3 | class Location{ |
| 4 | 4 | |
| 5 | - public $cityName; |
|
| 6 | - |
|
| 7 | - public $lat; |
|
| 8 | - |
|
| 9 | - public $lng; |
|
| 10 | - |
|
| 11 | - public function getCityName() |
|
| 12 | - { |
|
| 13 | - return $this->cityName; |
|
| 14 | - } |
|
| 15 | - |
|
| 16 | - public function setCityName($cityName) |
|
| 17 | - { |
|
| 18 | - $this->cityName = $cityName; |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function getLat() |
|
| 22 | - { |
|
| 23 | - return $this->lat; |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - public function setLat($lat) |
|
| 27 | - { |
|
| 28 | - $this->lat = $lat; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - public function getLng() |
|
| 32 | - { |
|
| 33 | - return $this->lng; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - public function setLng($lng) |
|
| 37 | - { |
|
| 38 | - $this->lng = $lng; |
|
| 39 | - } |
|
| 40 | - public function toArray(){ |
|
| 41 | - return array( |
|
| 42 | - "city" => $this->getCityName(), |
|
| 43 | - "country" => 'DE', |
|
| 44 | - "loc_accuracy" => '0.0', |
|
| 45 | - "loc_coordinates" => array( |
|
| 46 | - "lat" => $this->getLat(), |
|
| 47 | - "lng" => $this->getLng(), |
|
| 48 | - ), |
|
| 49 | - "name" => $this->getCityName() |
|
| 50 | - ); |
|
| 51 | - } |
|
| 5 | + public $cityName; |
|
| 6 | + |
|
| 7 | + public $lat; |
|
| 8 | + |
|
| 9 | + public $lng; |
|
| 10 | + |
|
| 11 | + public function getCityName() |
|
| 12 | + { |
|
| 13 | + return $this->cityName; |
|
| 14 | + } |
|
| 15 | + |
|
| 16 | + public function setCityName($cityName) |
|
| 17 | + { |
|
| 18 | + $this->cityName = $cityName; |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function getLat() |
|
| 22 | + { |
|
| 23 | + return $this->lat; |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + public function setLat($lat) |
|
| 27 | + { |
|
| 28 | + $this->lat = $lat; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + public function getLng() |
|
| 32 | + { |
|
| 33 | + return $this->lng; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + public function setLng($lng) |
|
| 37 | + { |
|
| 38 | + $this->lng = $lng; |
|
| 39 | + } |
|
| 40 | + public function toArray(){ |
|
| 41 | + return array( |
|
| 42 | + "city" => $this->getCityName(), |
|
| 43 | + "country" => 'DE', |
|
| 44 | + "loc_accuracy" => '0.0', |
|
| 45 | + "loc_coordinates" => array( |
|
| 46 | + "lat" => $this->getLat(), |
|
| 47 | + "lng" => $this->getLng(), |
|
| 48 | + ), |
|
| 49 | + "name" => $this->getCityName() |
|
| 50 | + ); |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -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 = "VwJHzYUbPjGiXWauoVNaHoCWsaacTmnkGwNtHhjy"; |
|
| 8 | - const USERAGENT = "Jodel/4.27.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )"; |
|
| 9 | - const CLIENT_TYPE = 'android_4.27.1'; |
|
| 5 | + CONST CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
| 6 | + CONST APIURL = 'https://api.go-tellm.com/api'; |
|
| 7 | + const SECRET = "VwJHzYUbPjGiXWauoVNaHoCWsaacTmnkGwNtHhjy"; |
|
| 8 | + const USERAGENT = "Jodel/4.27.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )"; |
|
| 9 | + const CLIENT_TYPE = 'android_4.27.1'; |
|
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @var string |
|
| 13 | - */ |
|
| 14 | - private $accessToken = null; |
|
| 15 | - private $payLoad; |
|
| 16 | - public function execute() |
|
| 17 | - { |
|
| 11 | + /** |
|
| 12 | + * @var string |
|
| 13 | + */ |
|
| 14 | + private $accessToken = null; |
|
| 15 | + private $payLoad; |
|
| 16 | + public function execute() |
|
| 17 | + { |
|
| 18 | 18 | $result = new \stdClass(); |
| 19 | 19 | |
| 20 | 20 | $this->payLoad = $this->getPayload(); |
@@ -24,71 +24,71 @@ 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 | *var_dump($url); |
| 37 | 37 | *var_dump($header); |
| 38 | 38 | *var_dump($this->payLoad); |
| 39 | 39 | */ |
| 40 | 40 | |
| 41 | 41 | |
| 42 | - switch ($this->getMethod()) { |
|
| 43 | - case 'POST': |
|
| 44 | - $result = Requests::post($url, $header, $this->payLoad); |
|
| 45 | - break; |
|
| 46 | - case 'GET': |
|
| 47 | - $result = Requests::get($url, $header); |
|
| 48 | - break; |
|
| 49 | - case 'PUT': |
|
| 50 | - $result = Requests::put($url, $header, $this->payLoad); |
|
| 51 | - break; |
|
| 52 | - } |
|
| 53 | - switch ($result->status_code) { |
|
| 54 | - case 200: |
|
| 55 | - $result = json_decode($result->body, true); |
|
| 56 | - break; |
|
| 57 | - case 204: |
|
| 58 | - $result = "Success"; |
|
| 59 | - break; |
|
| 60 | - case 401: |
|
| 42 | + switch ($this->getMethod()) { |
|
| 43 | + case 'POST': |
|
| 44 | + $result = Requests::post($url, $header, $this->payLoad); |
|
| 45 | + break; |
|
| 46 | + case 'GET': |
|
| 47 | + $result = Requests::get($url, $header); |
|
| 48 | + break; |
|
| 49 | + case 'PUT': |
|
| 50 | + $result = Requests::put($url, $header, $this->payLoad); |
|
| 51 | + break; |
|
| 52 | + } |
|
| 53 | + switch ($result->status_code) { |
|
| 54 | + case 200: |
|
| 55 | + $result = json_decode($result->body, true); |
|
| 56 | + break; |
|
| 57 | + case 204: |
|
| 58 | + $result = "Success"; |
|
| 59 | + break; |
|
| 60 | + case 401: |
|
| 61 | 61 | throw new \Exception('Unauthorized'); |
| 62 | - break; |
|
| 63 | - case 404: |
|
| 64 | - echo "Es wurde bereits gevoted"; |
|
| 62 | + break; |
|
| 63 | + case 404: |
|
| 64 | + echo "Es wurde bereits gevoted"; |
|
| 65 | 65 | case 477: |
| 66 | - echo "Es wurde bereits gevoted"; |
|
| 67 | - throw new \Exception('Signing failed!'); |
|
| 68 | - break; |
|
| 69 | - default: |
|
| 70 | - throw new \Exception('Unknown Error: '.$result->status_code); |
|
| 71 | - } |
|
| 66 | + echo "Es wurde bereits gevoted"; |
|
| 67 | + throw new \Exception('Signing failed!'); |
|
| 68 | + break; |
|
| 69 | + default: |
|
| 70 | + throw new \Exception('Unknown Error: '.$result->status_code); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - if($device_uid != "") |
|
| 74 | - { |
|
| 73 | + if($device_uid != "") |
|
| 74 | + { |
|
| 75 | 75 | $result[0] = $result; |
| 76 | 76 | $result[1] = $device_uid; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /* |
|
| 79 | + /* |
|
| 80 | 80 | var_dump($result); |
| 81 | 81 | */ |
| 82 | 82 | |
| 83 | - return $result; |
|
| 84 | - } |
|
| 85 | - abstract function getPayload(); |
|
| 86 | - /** |
|
| 87 | - * Gets Sign headers |
|
| 88 | - * @return array headers |
|
| 89 | - */ |
|
| 90 | - private function getSignHeaders() |
|
| 91 | - { |
|
| 83 | + return $result; |
|
| 84 | + } |
|
| 85 | + abstract function getPayload(); |
|
| 86 | + /** |
|
| 87 | + * Gets Sign headers |
|
| 88 | + * @return array headers |
|
| 89 | + */ |
|
| 90 | + private function getSignHeaders() |
|
| 91 | + { |
|
| 92 | 92 | if($this->getAccessToken() == null) { |
| 93 | 93 | $payload_accessToken = ""; |
| 94 | 94 | } |
@@ -97,54 +97,54 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
| 100 | - $headers = array( |
|
| 101 | - "Connection" => "keep-alive", |
|
| 102 | - "Accept-Encoding" => "gzip", |
|
| 103 | - "Content-Type" => "application/json; charset=UTF-8", |
|
| 104 | - "User-Agent" => self::USERAGENT |
|
| 105 | - ); |
|
| 106 | - $timestamp = new DateTime(); |
|
| 107 | - $timestamp = $timestamp->format(DateTime::ATOM); |
|
| 108 | - $timestamp = substr($timestamp, 0, -6); |
|
| 109 | - $timestamp .= "Z"; |
|
| 110 | - $urlParts = parse_url($this->getFullUrl()); |
|
| 111 | - $url2 = ""; |
|
| 112 | - $req = [$this->getMethod(), |
|
| 113 | - $urlParts['host'], |
|
| 114 | - "443", |
|
| 115 | - $urlParts['path'], |
|
| 116 | - $payload_accessToken, |
|
| 117 | - $timestamp, |
|
| 118 | - $url2, |
|
| 119 | - $this->payLoad]; |
|
| 120 | - $reqString = implode("%", $req); |
|
| 121 | - $secret = self::SECRET; |
|
| 122 | - $signature = hash_hmac('sha1', $reqString, $secret); |
|
| 123 | - $signature = strtoupper($signature); |
|
| 124 | - $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
| 125 | - $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
| 126 | - $headers['X-Timestamp'] = $timestamp; |
|
| 127 | - $headers['X-Api-Version'] = '0.2'; |
|
| 128 | - return $headers; |
|
| 129 | - } |
|
| 130 | - private function getFullUrl() |
|
| 131 | - { |
|
| 132 | - return self::APIURL . $this->getApiEndPoint(); |
|
| 133 | - } |
|
| 134 | - abstract function getApiEndPoint(); |
|
| 135 | - abstract function getMethod(); |
|
| 136 | - /** |
|
| 137 | - * @return string |
|
| 138 | - */ |
|
| 139 | - private function getAccessToken() |
|
| 140 | - { |
|
| 141 | - return $this->accessToken; |
|
| 142 | - } |
|
| 143 | - /** |
|
| 144 | - * @param string $accessToken |
|
| 145 | - */ |
|
| 146 | - public function setAccessToken($accessToken) |
|
| 147 | - { |
|
| 148 | - $this->accessToken = $accessToken; |
|
| 149 | - } |
|
| 100 | + $headers = array( |
|
| 101 | + "Connection" => "keep-alive", |
|
| 102 | + "Accept-Encoding" => "gzip", |
|
| 103 | + "Content-Type" => "application/json; charset=UTF-8", |
|
| 104 | + "User-Agent" => self::USERAGENT |
|
| 105 | + ); |
|
| 106 | + $timestamp = new DateTime(); |
|
| 107 | + $timestamp = $timestamp->format(DateTime::ATOM); |
|
| 108 | + $timestamp = substr($timestamp, 0, -6); |
|
| 109 | + $timestamp .= "Z"; |
|
| 110 | + $urlParts = parse_url($this->getFullUrl()); |
|
| 111 | + $url2 = ""; |
|
| 112 | + $req = [$this->getMethod(), |
|
| 113 | + $urlParts['host'], |
|
| 114 | + "443", |
|
| 115 | + $urlParts['path'], |
|
| 116 | + $payload_accessToken, |
|
| 117 | + $timestamp, |
|
| 118 | + $url2, |
|
| 119 | + $this->payLoad]; |
|
| 120 | + $reqString = implode("%", $req); |
|
| 121 | + $secret = self::SECRET; |
|
| 122 | + $signature = hash_hmac('sha1', $reqString, $secret); |
|
| 123 | + $signature = strtoupper($signature); |
|
| 124 | + $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
| 125 | + $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
| 126 | + $headers['X-Timestamp'] = $timestamp; |
|
| 127 | + $headers['X-Api-Version'] = '0.2'; |
|
| 128 | + return $headers; |
|
| 129 | + } |
|
| 130 | + private function getFullUrl() |
|
| 131 | + { |
|
| 132 | + return self::APIURL . $this->getApiEndPoint(); |
|
| 133 | + } |
|
| 134 | + abstract function getApiEndPoint(); |
|
| 135 | + abstract function getMethod(); |
|
| 136 | + /** |
|
| 137 | + * @return string |
|
| 138 | + */ |
|
| 139 | + private function getAccessToken() |
|
| 140 | + { |
|
| 141 | + return $this->accessToken; |
|
| 142 | + } |
|
| 143 | + /** |
|
| 144 | + * @param string $accessToken |
|
| 145 | + */ |
|
| 146 | + public function setAccessToken($accessToken) |
|
| 147 | + { |
|
| 148 | + $this->accessToken = $accessToken; |
|
| 149 | + } |
|
| 150 | 150 | } |
@@ -1,59 +1,59 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class SendJodel extends AbstractRequest { |
| 4 | - /** |
|
| 5 | - * @var Location |
|
| 6 | - */ |
|
| 7 | - public $location; |
|
| 8 | - /** |
|
| 9 | - * @return Location |
|
| 10 | - */ |
|
| 11 | - public function getLocation() |
|
| 12 | - { |
|
| 13 | - return $this->location; |
|
| 14 | - } |
|
| 15 | - /** |
|
| 16 | - * @param Location $location |
|
| 17 | - */ |
|
| 18 | - public function setLocation($location) |
|
| 19 | - { |
|
| 20 | - $this->location = $location; |
|
| 21 | - } |
|
| 4 | + /** |
|
| 5 | + * @var Location |
|
| 6 | + */ |
|
| 7 | + public $location; |
|
| 8 | + /** |
|
| 9 | + * @return Location |
|
| 10 | + */ |
|
| 11 | + public function getLocation() |
|
| 12 | + { |
|
| 13 | + return $this->location; |
|
| 14 | + } |
|
| 15 | + /** |
|
| 16 | + * @param Location $location |
|
| 17 | + */ |
|
| 18 | + public function setLocation($location) |
|
| 19 | + { |
|
| 20 | + $this->location = $location; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public $ancestor; |
|
| 24 | - /** |
|
| 25 | - * @return Location |
|
| 26 | - */ |
|
| 27 | - public function getAncestor() |
|
| 28 | - { |
|
| 29 | - return $this->ancestor; |
|
| 30 | - } |
|
| 31 | - /** |
|
| 32 | - * @param Location $location |
|
| 33 | - */ |
|
| 34 | - public function setAncestor($ancestor) |
|
| 35 | - { |
|
| 36 | - if(isset($ancestor) && $ancestor != "") |
|
| 37 | - { |
|
| 23 | + public $ancestor; |
|
| 24 | + /** |
|
| 25 | + * @return Location |
|
| 26 | + */ |
|
| 27 | + public function getAncestor() |
|
| 28 | + { |
|
| 29 | + return $this->ancestor; |
|
| 30 | + } |
|
| 31 | + /** |
|
| 32 | + * @param Location $location |
|
| 33 | + */ |
|
| 34 | + public function setAncestor($ancestor) |
|
| 35 | + { |
|
| 36 | + if(isset($ancestor) && $ancestor != "") |
|
| 37 | + { |
|
| 38 | 38 | $this->ancestor = $ancestor; |
| 39 | 39 | } |
| 40 | - } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - function getApiEndPoint() |
|
| 43 | - { |
|
| 44 | - return '/v3/posts/'; |
|
| 45 | - } |
|
| 46 | - function getPayload() |
|
| 47 | - { |
|
| 48 | - return array( |
|
| 42 | + function getApiEndPoint() |
|
| 43 | + { |
|
| 44 | + return '/v3/posts/'; |
|
| 45 | + } |
|
| 46 | + function getPayload() |
|
| 47 | + { |
|
| 48 | + return array( |
|
| 49 | 49 | "ancestor" => $this->getAncestor(), |
| 50 | 50 | "color" => "9EC41C", |
| 51 | - "location" => $this->getLocation()->toArray(), |
|
| 52 | - "message" => $_POST['message'], |
|
| 53 | - ); |
|
| 54 | - } |
|
| 55 | - function getMethod() |
|
| 56 | - { |
|
| 57 | - return 'POST'; |
|
| 58 | - } |
|
| 51 | + "location" => $this->getLocation()->toArray(), |
|
| 52 | + "message" => $_POST['message'], |
|
| 53 | + ); |
|
| 54 | + } |
|
| 55 | + function getMethod() |
|
| 56 | + { |
|
| 57 | + return 'POST'; |
|
| 58 | + } |
|
| 59 | 59 | } |