上次更新后如何更新Riot Api

时间:2019-03-20 14:50:53

标签: php riot-games-api

我一直在使用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开发人员面板的屏幕截图,并显示了错误获取消息:

screenshot

该代码应该从Riot服务器获取召唤者的名字,并检查当前的联赛,分区和最近的比赛历史。

1 个答案:

答案 0 :(得分:1)

Riot Games删除了一些v3 API端点,现在移至v4,您可以找到新版本的端点here,对于数据龙版本,您可以找到它here

示例:/lol/summoner/v4/summoners/by-name/{summonerName}

他们现在也正在使用加密的ID,并为召唤者添加了另一个名为puuid的标识符

您可以加入他们不和谐的here