将SteamID64转换为SteamID

时间:2015-07-07 13:42:17

标签: php steam steam-web-api

我正在寻找一种方法,我可以使用SteamID64(76561198032122624)并将其转换为PHP中的SteamID(STEAM_0:0:35928448)。我已经搜索了这么多,我无法找到如何做到这一点。我几乎可以肯定,因为像steamid.io这样的网站能够找到它,但我不知道如何。

4 个答案:

答案 0 :(得分:4)

您需要的所有信息都在Valve's SteamID wiki page上:

  

传统格式

     

当以文本方式表示时,Steam ID遵循相当简单的格式:   “STEAM_X:Y:Z”,其中X,Y和Z是整数。

     
      
  • X表示蒸汽帐户所属的“Universe”。如果'X'为0,则这是Universe 1(公共)。
  •   
  • Y是帐户ID的最低位。因此,Y是0或1。
  •   
  • Z是帐户ID的最高31位。
  •   
     

作为64位整数

     

鉴于Steam ID的组件,可以将Steam ID转换为   它的64位整数形式如下:

     

(( Universe << 56)|(帐户类型<< 52)|(实例<< 32)|   帐户ID

我的PHP 非常生锈,但是这里有一些(未经测试的)伪代码应该大致按照要求进行:

var steamId64 = 76561198032122624;

var universe = (steamId64 >> 56) & 0xFF;
if (universe == 1) universe = 0;

var accountIdLowBit = steamId64 & 1;

var accountIdHighBits = (steamId64 >> 1) & 0x7FFFFFF;

// should hopefully produce "STEAM_0:0:35928448"
var legacySteamId = "STEAM_" + universe + ":" + accountIdLowBit + ":" + accountIdHighBits;

答案 1 :(得分:1)

function steamid64_to_steamid2($steamid64) {
    $accountID = bcsub($steamid64, '76561197960265728');
    return 'STEAM_0:'.bcmod($accountID, '2').':'.bcdiv($accountID, 2);
}

答案 2 :(得分:0)

<?php 

$steamid64="76561198237914532"; //YOUR STEAM ID 64

echo "<-- By BigBossPT to VynexGaming.com -->";
echo "<br><br>Steamid32: ".getSteamId32($steamid64);
echo "<br><br>Steamid64: ".getSteamID64(getSteamId32($steamid64)); // 76561197985756607 
echo "<br><br>Thanks for Gio! Website that i found: https://facepunch.com/showthread.php?t=1238157";
//OBTER STEAM ID 64 

function getSteamID64($id) {
    if (preg_match('/^STEAM_/', $id)) {
        $parts = explode(':', $id);
        return bcadd(bcadd(bcmul($parts[2], '2'), '76561197960265728'), $parts[1]);
    } elseif (is_numeric($id) && strlen($id) < 16) {
        return bcadd($id, '76561197960265728');
    } else {
        return $id; // We have no idea what this is, so just return it.
    }
}


function parseInt($string) {
    //    return intval($string);
        if(preg_match('/(\d+)/', $string, $array)) {
            return $array[1];
        } else {
            return 0;
        }
    }
function getSteamId32($id){
    // Convert SteamID64 into SteamID

    $subid = substr($id, 4); // because calculators are fags
    $steamY = parseInt($subid);
    $steamY = $steamY - 1197960265728; //76561197960265728

    if ($steamY%2 == 1){
    $steamX = 1;
    } else {
    $steamX = 0;
    }

    $steamY = (($steamY - $steamX) / 2);
    $steamID = "STEAM_0:" . (string)$steamX . ":" . (string)$steamY;
    return $steamID;

}
?>

答案 3 :(得分:0)

这是一个不需要BC Math PHP Extension的实际工作版本。

<?php
    $id = "{STEAMID64 HERE}";

function parseInt($string) {
//    return intval($string);
    if(preg_match('/(\d+)/', $string, $array)) {
        return $array[1];
    } else {
        return 0;
    }}

// Convert SteamID64 into SteamID
$subid = substr($id, 4); // because calculators suck
$steamY = parseInt($subid);
$steamY = $steamY - 1197960265728; //76561197960265728
$steamX = 0;
if ($steamY%2 == 1){
$steamX = 1;
} else {
$steamX = 0;
}

$steamY = (($steamY - $steamX) / 2);
$steamID = "STEAM_0:" . (string)$steamX . ":" . (string)$steamY;
echo $steamID;

?>