mirror of
https://github.com/elyby/accounts.git
synced 2024-11-26 16:52:02 +05:30
#276: если система скинов недоступна, то генерируем ответ самостоятельно
This commit is contained in:
parent
c029db82a1
commit
3bde676217
@ -8,21 +8,26 @@ class Api {
|
|||||||
|
|
||||||
const BASE_DOMAIN = 'http://skinsystem.ely.by';
|
const BASE_DOMAIN = 'http://skinsystem.ely.by';
|
||||||
|
|
||||||
public function textures($username) : array {
|
/**
|
||||||
|
* @param string $username
|
||||||
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function textures(string $username): array {
|
||||||
$response = $this->getClient()->get($this->getBuildUrl('/textures/' . $username));
|
$response = $this->getClient()->get($this->getBuildUrl('/textures/' . $username));
|
||||||
$textures = json_decode($response->getBody(), true);
|
|
||||||
|
|
||||||
return $textures;
|
return json_decode($response->getBody(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getBuildUrl(string $url) : string {
|
protected function getBuildUrl(string $url): string {
|
||||||
return self::BASE_DOMAIN . $url;
|
return self::BASE_DOMAIN . $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return GuzzleClient
|
* @return GuzzleClient
|
||||||
*/
|
*/
|
||||||
protected function getClient() : GuzzleClient {
|
protected function getClient(): GuzzleClient {
|
||||||
return Yii::$app->guzzle;
|
return Yii::$app->guzzle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ namespace common\models;
|
|||||||
use common\components\SkinSystem\Api as SkinSystemApi;
|
use common\components\SkinSystem\Api as SkinSystemApi;
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use GuzzleHttp\Exception\RequestException;
|
||||||
|
use Yii;
|
||||||
|
|
||||||
class Textures {
|
class Textures {
|
||||||
|
|
||||||
@ -57,9 +59,20 @@ class Textures {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTextures() {
|
public function getTextures(): array {
|
||||||
$api = new SkinSystemApi();
|
try {
|
||||||
return $api->textures($this->account->username);
|
$textures = $this->getSkinsystemApi()->textures($this->account->username);
|
||||||
|
} catch (RequestException $e) {
|
||||||
|
Yii::warning('Cannot get textures from skinsystem.ely.by. Exception message is ' . $e->getMessage());
|
||||||
|
$textures = [
|
||||||
|
'SKIN' => [
|
||||||
|
'url' => 'http://skins.minecraft.net/MinecraftSkins/' . $this->account->username . '.png',
|
||||||
|
'hash' => md5(uniqid('random, please', true)),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $textures;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function encrypt(array $data) {
|
public static function encrypt(array $data) {
|
||||||
@ -70,4 +83,8 @@ class Textures {
|
|||||||
return json_decode(base64_decode($string), $assoc);
|
return json_decode(base64_decode($string), $assoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getSkinsystemApi(): SkinSystemApi {
|
||||||
|
return new SkinSystemApi();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user