0

我一直在使用我的 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 开发面板的屏幕截图,以及错误获取消息:

截屏

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

4

1 回答 1

1

Riot Games 移除了部分v3API 端点,现在移至,您可以在此处v4找到新版本的端点,至于数据龙版本,您可以在此处找到

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

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

你可以在这里加入他们的不和谐

于 2019-03-26T02:23:46.587 回答