Как обновить Riot Api после последнего обновления - PullRequest
0 голосов
/ 20 марта 2019

Я использовал мой Riot Api для проверки текущего деления данного призывателя, но, вероятно, после того, как обновление перестало работать, вот мой код:

<?php

namespace AppBundle\Utils;

class LolApi
{

    private $apiKey = 'my api key';

    private $server = 'eun1';

    public static function makeRequest($url)
    {
        $result = file_get_contents($url);
        sleep(1.5);

        return $result;
    }

    private function executeCommand($command)
    {
        try {
            $url =
            $c = file_get_contents('https://' . $this->server . '.api.riotgames.com' . $command . '?api_key=' . $this->apiKey);

            return json_decode($c);
        } catch (Exception $e) {
            return null;
        }
    }

    public function setServer($server)
    {
        if ($server == 'EUNE') {
            $this->$server = 'eun1';
        }
        if ($server == 'EUW') {
            $this->$server = 'euw1';
        }
        if ($server == 'NA') {
            $this->$server = 'na1';
        }
        if ($server == 'OCE') {
            $this->$server = 'oc1';
        }
    }

    public function getSummonerIdByName($summonerName)
    {
        $data = $this->executeCommand('/lol/summoner/v3/summoners/by-name/' . rawurlencode($summonerName));

        return $data->id;
    }

    public function getAccountIdByName($summonerName)
    {
        $data = $this->executeCommand('/lol/summoner/v3/summoners/by-name/' . rawurlencode($summonerName));

        return $data->accountId;
    }

    public function getDivision($summonerName)
    {
        $id = $this->getSummonerIdByName($summonerName);

        $data = $this->executeCommand('/lol/league/v3/positions/by-summoner/' . $id);

        foreach ($data as $entry) {
            if ($entry->queueType == 'RANKED_SOLO_5x5') {
                return [$entry->tier, $entry->rank];
            }
        }

//        dump($id); exit;

        return [null, null];
    }


    public function getSpectateMatch($summonerName)
    {
        $id = $this->getSummonerIdByName($summonerName);
        $data = null;
        try {
            $data = $this->executeCommand('/lol/spectator/v3/active-games/by-summoner/' . $id);
        } catch (\Exception $e) {

        }

        return $data;
    }

    public function getMatches($summonerName)
    {
        $id = $this->getAccountIdByName($summonerName);
        $data = $this->executeCommand('/lol/match/v3/matchlists/by-account/' . $id . '/recent');

        $matchIds = [];

        foreach ($data->matches as $match) {
            array_push($matchIds, $match->gameId);
        }

        $retString = '';
        $matchList = [];

        foreach ($matchIds as $matchId) {
            $data = $this->executeCommand('/lol/match/v3/matches/' . $matchId);
            $continueMatchProcessing = true;

            foreach ($data->participantIdentities as $participantIdentity) {
                if (!isset($participantIdentity->player)) {
                    $continueMatchProcessing = false;
                    break;
                }

                if ($participantIdentity->player->summonerName == $summonerName) {
                    $playerParticipantId = $participantIdentity->participantId;
                }
            }

            if (!$continueMatchProcessing) {
                continue;
            }


            foreach ($data->participants as $participant) {
                if ($participant->participantId == $playerParticipantId) {
                    $matchArray = [
                        $participant->stats->win,
                        $participant->stats->kills,
                        $participant->stats->deaths,
                        $participant->stats->assists,
                        $participant->stats->goldEarned,
                        $participant->stats->totalMinionsKilled,
                        $participant->stats->item0,
                        $participant->stats->item1,
                        $participant->stats->item2,
                        $participant->stats->item3,
                        $participant->stats->item4,
                        $participant->stats->item5,
                        $participant->stats->item6,
                        $participant->spell1Id,
                        $participant->spell2Id,
                        $participant->championId,
                        $data->gameDuration
                    ];

                    array_push($matchList, $matchArray);
                }
            }
        }

        return $matchList;
    }
}

?>

Я поменял v3 на v4, но это не такПомогите.Я новичок в php, просто редактирую свой текущий код.

Также добавляю скриншот моей панели разработки API и сообщение об ошибке: Get:

screenshot

Код должен получить имя призывателя с серверов Riot и проверить текущую лигу, дивизион, историю последних матчей.

1 Ответ

1 голос
/ 26 марта 2019

Riot Games удалили некоторые из конечных точек API v3 и теперь перемещены в v4, вы можете найти конечные точки новой версии здесь , а что касается версии с данными-драконами, вы можете найти ее здесь

Пример: /lol/summoner/v4/summoners/by-name/{summonerName}

Теперь они также используют зашифрованные идентификаторы и добавили еще один идентификатор для призывателя puuid

Вы можете присоединиться к ихдискорд здесь

...