-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimized MCPremium Added MCPremiumResponse
- Loading branch information
Showing
5 changed files
with
171 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.idea | ||
vendor | ||
/composer.lock |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "lukasss93/minecraft-premium-account-checker", | ||
"description": "PHP library to check if a Minecraft account is Premium", | ||
"license": "MIT", | ||
"type": "project", | ||
"authors": [ | ||
{ | ||
"name": "Luca Patera", | ||
"email": "[email protected]", | ||
"homepage": "https://www.lucapatera.it/" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.6", | ||
"guzzlehttp/guzzle": "^6.3" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"MCPremium\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
namespace MCPremium; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Exception\ClientException; | ||
use GuzzleHttp\Psr7\Response; | ||
|
||
/** | ||
* PHP class to check if a Minecraft account is Premium | ||
* Class MCPremium | ||
* @package MCPremium | ||
*/ | ||
class MCPremium { | ||
const game = "Minecraft"; | ||
const version = 12; | ||
const api = "https://authserver.mojang.com/authenticate"; | ||
|
||
private function __construct() {} | ||
|
||
/** | ||
* Check if an account is premium | ||
* @param $username | ||
* @param $password | ||
* @return \MCPremium\MCPremiumResponse | ||
*/ | ||
public static function check($username, $password) { | ||
|
||
//build parameters | ||
$parameters = [ | ||
'agent' => [ | ||
'name' => self::game, | ||
'version' => self::version | ||
], | ||
'username' => (string)$username, | ||
'password' => (string)$password | ||
]; | ||
|
||
//initialize client | ||
$client = new Client(); | ||
$response = new Response(); | ||
|
||
//initialize output | ||
$data = null; | ||
|
||
try { | ||
//send request | ||
$response = $client->post(self::api, [ | ||
'json' => $parameters | ||
]); | ||
} | ||
catch(ClientException $e) { | ||
if($e->hasResponse()) { | ||
$response = $e->getResponse(); | ||
} | ||
} | ||
|
||
//get content | ||
$content = $response->getBody()->getContents(); | ||
|
||
//decode json content | ||
$json = \GuzzleHttp\json_decode($content, true); | ||
|
||
//initialize mcpremium response class | ||
$output = new MCPremiumResponse(); | ||
|
||
//set original content to raw property | ||
$output->raw = $json; | ||
|
||
//get values | ||
if(array_key_exists('errorMessage', $json)) { | ||
$output->error = $json['errorMessage']; | ||
} | ||
else if(!array_key_exists('selectedProfile', $json)) { | ||
$output->error = "Your account is not premium."; | ||
} | ||
else { | ||
$selectedProfile = $json['selectedProfile']; | ||
|
||
//username | ||
$output->username=$username; | ||
|
||
//correct_username | ||
$output->correct_username = array_key_exists('name', $selectedProfile) ? $selectedProfile['name'] : null; | ||
|
||
//uuid | ||
$output->uuid = array_key_exists('id', $selectedProfile) ? $selectedProfile['id'] : null; | ||
|
||
//created_at | ||
$output->created_at= array_key_exists('createdAt', $selectedProfile) ? $selectedProfile['createdAt'] : null; | ||
|
||
//check premium | ||
if($output->uuid == null && $output->correct_username == null) { | ||
$output->error = "Your account is not premium."; | ||
$output->premium = false; | ||
} | ||
else { | ||
$output->premium = true; | ||
} | ||
} | ||
|
||
return $output; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace MCPremium; | ||
|
||
/** | ||
* Response class used by MCPremium class | ||
* Class MCPremiumResponse | ||
* @package MCPremium | ||
*/ | ||
class MCPremiumResponse { | ||
|
||
/** @var bool $premium Returns true if the account is premium, otherwise false. */ | ||
public $premium = false; | ||
|
||
/** @var string Error message. */ | ||
public $error = null; | ||
|
||
/** @var string $username Entered username. */ | ||
public $username = null; | ||
|
||
/** @var string Correct username if the account is migrated. */ | ||
public $correct_username = null; | ||
|
||
/** @var string Universally unique identifier of the account. */ | ||
public $uuid = null; | ||
|
||
/** @var int $created_at Creation timestamp account */ | ||
public $created_at=null; | ||
|
||
/** @var array $raw Json response from API */ | ||
public $raw = null; | ||
|
||
/** | ||
* Returns all class properties as an array. | ||
* @return array | ||
*/ | ||
public function toArray() { | ||
$properties = get_object_vars($this); | ||
unset($properties['raw']); | ||
return $properties; | ||
} | ||
|
||
} |