| @@ -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; | 
| @@ -68,7 +68,7 @@ discard block | ||
| 68 | 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 | |