代码有,但我不明白在哪里


Code has but I don't understand where

所以我有代码应该从bitskins或steamcommunity获取项目价格。它做所有事情,除了它输入的价格是 0。

<?php
require_once "../config.php";
require_once "../db.php";
$secret ="";
$api = "";
require_once 'GoogleAuthenticator.php';
$ga = new PHPGangsta_GoogleAuthenticator();
$oneCode = $ga->getCode($secret);
if(!isset($_GET['secret']) || $_GET['secret'] != $config['bot_key_add']){
    die("Access denied");
    return;
}
$json = json_decode(file_get_contents("php://input"));
$weapon = urlencode($json->weapon);
$link = "https://bitskins.com/api/v1/get_item_price/?api_key=" . $api . "&code=" . $oneCode . "&names=" . $weapon . "&delimiter=!END!";
$steam_price = file_get_contents($link);
$item_price = json_decode($steam_price);
if(empty($item_price) || $item_price->success == false || empty($item_price->price))
{
    $link = "http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=.$weapon";
    $price2 = $item_price->median_price;
    $price2 = str_replace("&#36;" , "", $price2);
    $price2 = str_replace("$" , "", $price2);
    $price2 = round(str_replace(",",".",$price2), 2);
}
else 
{
    $price2 = $item_price->price;
    $price2 = str_replace("&#36;" , "", $price2);
    $price2 = str_replace("$" , "", $price2);
    $price2 = round(str_replace(",",".",$price2), 2);
}
$saveWeapon = $pdo->prepare("");
$saveWeapon->execute([  ":steamId"      => $json->userID,
                        ":classid"      => $json->classid,
                        ":assetid"      => $json->assetid,
                        ":weaponName"   => $json->weapon,
                        ":price"        => $price2,
                        ":float"        => $json->color
]);
?>

如果项目在数据库中,以下是位皮肤 API 结果:https://i.stack.imgur.com/Dm0P0.png以下是如果项目不在数据库中:https://i.stack.imgur.com/QZg1r.png

基本上,如果项目不在数据库中,它应该使用蒸汽市场。我找不到任何"错误"代码,但在数据库中插入 0

好吧,让我们看看这里发生了什么。

$link = "https://bitskins.com/api/v1/get_item_price/?api_key=" . $api . "&code=" . $oneCode . "&names=" . $weapon . "&delimiter=!END!";
$steam_price = file_get_contents($link);
$item_price = json_decode($steam_price);
if(empty($item_price) || $item_price->success == false || empty($item_price->price))
{
    $link = "http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=.$weapon";
    $price2 = $item_price->median_price;
    $price2 = str_replace("&#36;" , "", $price2);
    $price2 = str_replace("$" , "", $price2);
    $price2 = round(str_replace(",",".",$price2), 2);
}

您没有从 steamcommunity.com $link获取内容,并试图从失败的数据集中提取median_price

尝试这样的事情:

$link = "https://bitskins.com/api/v1/get_item_price/?api_key=" . $api . "&code=" . $oneCode . "&names=" . $weapon . "&delimiter=!END!";
$steam_price = file_get_contents($link);
$item_price = json_decode($steam_price);
if(empty($item_price) || $item_price->success == false || empty($item_price->price))
{
    $link = "http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=.$weapon";
    // Added
    $steam_price = file_get_contents($link);
    $item_price = json_decode($steam_price);
    // 
    $price2 = $item_price->median_price;
    $price2 = str_replace("&#36;" , "", $price2);
    $price2 = str_replace("$" , "", $price2);
    $price2 = round(str_replace(",",".",$price2), 2);
}