@@ -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 | |
@@ -309,7 +309,7 @@ |
||
| 309 | 309 | { |
| 310 | 310 | preg_match('/bot|spider|google|twitter/i', $_SERVER['HTTP_USER_AGENT'], $matches); |
| 311 | 311 | |
| 312 | - return (isset($matches[0])) ? true : false; |
|
| 312 | + return (isset($matches[0])) ? true : false; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | function botDeviceUidIsSet($config) |
@@ -1,53 +1,53 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class CreateUser extends AbstractRequest { |
| 4 | - /** |
|
| 5 | - * @var Location |
|
| 6 | - */ |
|
| 7 | - private $location; |
|
| 8 | - private $deviceUid; |
|
| 9 | - /** |
|
| 10 | - * @return Location |
|
| 11 | - */ |
|
| 12 | - private function getLocation() |
|
| 13 | - { |
|
| 14 | - return $this->location; |
|
| 15 | - } |
|
| 16 | - /** |
|
| 17 | - * @param Location $location |
|
| 18 | - */ |
|
| 19 | - public function setLocation(Location $location) |
|
| 20 | - { |
|
| 21 | - $this->location = $location; |
|
| 22 | - } |
|
| 23 | - private function getDeviceUid() |
|
| 24 | - { |
|
| 4 | + /** |
|
| 5 | + * @var Location |
|
| 6 | + */ |
|
| 7 | + private $location; |
|
| 8 | + private $deviceUid; |
|
| 9 | + /** |
|
| 10 | + * @return Location |
|
| 11 | + */ |
|
| 12 | + private function getLocation() |
|
| 13 | + { |
|
| 14 | + return $this->location; |
|
| 15 | + } |
|
| 16 | + /** |
|
| 17 | + * @param Location $location |
|
| 18 | + */ |
|
| 19 | + public function setLocation(Location $location) |
|
| 20 | + { |
|
| 21 | + $this->location = $location; |
|
| 22 | + } |
|
| 23 | + private function getDeviceUid() |
|
| 24 | + { |
|
| 25 | 25 | return $this->deviceUid; |
| 26 | 26 | } |
| 27 | 27 | public function setDeviceUid($deviceUid) |
| 28 | - { |
|
| 28 | + { |
|
| 29 | 29 | $this->deviceUid = $deviceUid; |
| 30 | 30 | } |
| 31 | - private function generateDeviceUid() |
|
| 32 | - { |
|
| 33 | - return $this->random_str(64, 'abcdef0123456789'); |
|
| 34 | - } |
|
| 31 | + private function generateDeviceUid() |
|
| 32 | + { |
|
| 33 | + return $this->random_str(64, 'abcdef0123456789'); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - private function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') |
|
| 37 | - { |
|
| 38 | - $str = ''; |
|
| 39 | - $max = mb_strlen($keyspace, '8bit') - 1; |
|
| 40 | - for ($i = 0; $i < $length; ++$i) { |
|
| 41 | - $str .= $keyspace[rand(0, $max)]; |
|
| 42 | - } |
|
| 43 | - return $str; |
|
| 44 | - } |
|
| 45 | - public function getApiEndPoint() |
|
| 46 | - { |
|
| 47 | - return '/v2/users'; |
|
| 48 | - } |
|
| 49 | - public function getPayload() |
|
| 50 | - { |
|
| 36 | + private function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') |
|
| 37 | + { |
|
| 38 | + $str = ''; |
|
| 39 | + $max = mb_strlen($keyspace, '8bit') - 1; |
|
| 40 | + for ($i = 0; $i < $length; ++$i) { |
|
| 41 | + $str .= $keyspace[rand(0, $max)]; |
|
| 42 | + } |
|
| 43 | + return $str; |
|
| 44 | + } |
|
| 45 | + public function getApiEndPoint() |
|
| 46 | + { |
|
| 47 | + return '/v2/users'; |
|
| 48 | + } |
|
| 49 | + public function getPayload() |
|
| 50 | + { |
|
| 51 | 51 | if(!isset($this->deviceUid)) |
| 52 | 52 | { |
| 53 | 53 | $this->setDeviceUid($this->generateDeviceUid()); |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | "client_id" => self::CLIENTID, |
| 59 | 59 | "device_uid" => $this->getDeviceUid(), |
| 60 | 60 | ); |
| 61 | - } |
|
| 62 | - public function getMethod() |
|
| 63 | - { |
|
| 64 | - return 'POST'; |
|
| 65 | - } |
|
| 61 | + } |
|
| 62 | + public function getMethod() |
|
| 63 | + { |
|
| 64 | + return 'POST'; |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -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 = 'plerFToqEdWlzShdZlTywaCHRuzlKIMsNmOJVDGE'; |
|
| 8 | - const USERAGENT = 'Jodel/4.31.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
|
| 9 | - const CLIENT_TYPE = 'android_4.31.1'; |
|
| 5 | + const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
| 6 | + const APIURL = 'https://api.go-tellm.com/api'; |
|
| 7 | + const SECRET = 'plerFToqEdWlzShdZlTywaCHRuzlKIMsNmOJVDGE'; |
|
| 8 | + const USERAGENT = 'Jodel/4.31.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
|
| 9 | + const CLIENT_TYPE = 'android_4.31.1'; |
|
| 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 | } |