duanlongling5308 2016-10-09 22:45 采纳率: 0%
浏览 99

在PHP中使用Steam Web API获取多个贴纸(CSGO)

So i have been having troubles with seeing if a user has more than one of the same sticker in their inventory using the Steam Web API.

http://steamcommunity.com/profiles/76561198188713228/inventory/json/730/2

My current code works perfectly fine when displaying any other item that has an amount greater than one, but when it comes to displaying a sticker it will only display one on the site.

Here is my code:

            $Steam_inv= file_get_contents($urls[2]);
            $Steam_Json = json_decode($Steam_inv, true);

            echo "User is logged in (steamID: $matches[1])
";


            //var_dump($Steam_Json['rgDescriptions']['1989271297_0']['market_name']);
            $TotalItems = 0;

            foreach ($Steam_Json['rgDescriptions'] as $item){
                $TotalItems++;
                $itemBD = json_encode($item);
                $itemAD = json_decode($itemBD, true);

                $result = json_encode($itemAD['market_name']);
                $result = str_replace('"', " ", json_encode($itemAD['market_name']));
                $result = str_replace('Factory New', "FN", $result);
                $result = str_replace('Minimal Wear', "MW", $result);
                $result = str_replace('Field-Tested', "FT", $result);
                $result = str_replace('Well-Worn', "WW", $result);
                $result = str_replace('Battle-Scarred', "BS", $result);
                $result = str_replace('\u2122', " ", $result);
                $result = str_replace('\u2605', " ", $result);                  

                $WepType = json_encode($itemAD['tags'][0]['internal_name']);
                $WepType = str_replace('"', "", $WepType);


                    if($WepType != "CSGO_Type_WeaponCase" && $WepType != "CSGO_Type_Knife")
                    {
                    $colors = json_encode($itemAD['tags'][4]['color']);
                    $colors = str_replace('"', "", $colors);
                    }
                    elseif ($WepType == "CSGO_Type_Knife"){
                        $colors = "FFD700";
                        $result = "★" . $result;
                    }


                $pics = json_encode($itemAD['classid']);
                $pics = str_replace('"', "", $pics);
                echo "<p style='color:#$colors;position:relative;left:50%;'>" . $result . "</p>" . "<img class='Guns' src='https://steamcommunity-a.akamaihd.net/economy/image/class/730/$pics'></img>";
            }
            echo $TotalItems;

Sorry if its sloppy, im really new to PHP.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stm32流水灯+呼吸灯+外部中断按键
    • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
    • ¥15 NX MCD仿真与博途通讯不了啥情况
    • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
    • ¥15 gradio的web端页面格式不对的问题
    • ¥15 求大家看看Nonce如何配置
    • ¥15 Matlab怎么求解含参的二重积分?
    • ¥15 苹果手机突然连不上wifi了?
    • ¥15 cgictest.cgi文件无法访问
    • ¥20 删除和修改功能无法调用