排序Steam Web Api GetPlayerSummaries响应

时间:2015-07-21 16:02:06

标签: php steam steam-web-api

我正在上课,将获得有关团队的数据 - 基于每个团队存储在数据库中的32位SteamID的5位Steam用户。它被翻译成64位SteamID。 我需要以正确的顺序回应,因为有指定的队长。 这就是问题 - GetPlayerSummaries总是以随机顺序返回配置文件。我希望这些按照网址排序。 我已经尝试过sort()方法,但似乎没有用,就像我想要的那样。 我已经尝试将'steamid'与这个翻译的64位SteamID匹配,如下所示:

$profile_get = json_decode(file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=mywebapikey&steamids='.$stmid64['capt'].','.$stmid64['p2'].','.$stmid64['p3'].','.$stmid64['p4'].','.$stmid64['p5']),true);

$profile_get = $profile_get['response'];

    foreach($profile_get['players'] as $profile){
        if($profile['steamid'] === $stmid64['capt']){
            $profile_got = array(
               0 => $profile
            );
        }
        elseif($profile['steamid'] === $stmid64['p2']){
            $profile_got[1] = $profile;
        }
        elseif($profile['steamid'] === $stmid64['p3']){
            $profile_got[2] = $profile;
        }
        elseif($profile['steamid'] === $stmid64['p4']){
            $profile_got[3] = $profile;
        }
        elseif($profile['steamid'] === $stmid64['p5']){
            $profile_got[4] = $profile;
        }
    }

其中$stmid64是64位SteamID,但显然不起作用:(

var_dump($profile_got[0]);
var_dump($profile_got[1]);
var_dump($profile_got[2]);
var_dump($profile_got[3]);
var_dump($profile_got[4]);

var_dump($profile_got);返回NULL。 我尝试了很多不同的代码,但它们也没有用。

我希望你能帮助我不要单独做所有的请求。

1 个答案:

答案 0 :(得分:0)

$profile_get = json_decode(file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='.$mywebapikey.'&steamids='.$stmid64['capt'].','.$stmid64['p2'].','.$stmid64['p3'].','.$stmid64['p4'].','.$stmid64['p5']),true);

for ($i = 0; $i < 5; $i++) {
  if ($i == 0)
    $player = 'capt';
  else 
    $player = 'p'.($i+1);

  for ($j = 0; $j < 5; $j++) {
    if ($stmid64[$player] == $profile_get['response']['players'][$j]['steamid']) {
      $profile_got[$i] = $profile_get['response']['players'][$j];
      break;
    }
  } 
} 

var_dump($profile_got[0]);
var_dump($profile_got[1]);
var_dump($profile_got[2]);
var_dump($profile_got[3]);
var_dump($profile_got[4]);

欢呼声

这个按预期工作,它将通过'capt'命令你的数组(为什么不用p1代替?,你可以保存3行),'p2','p3','p4' ,'p5'。你仍然可以通过多种方式扩展它,但基本上这就是如何将它们按正确的顺序排列。还记得我把你的(我的)api密钥存储在$ var