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

时间:2016-03-05 19:25:23

标签: php

所以我有代码应该从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
]);
?>

如果item在数据库中,则以下是bitskins API结果:substr 这是项目不在数据库中: http://i.imgur.com/HDMAaoC.png

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

1 个答案:

答案 0 :(得分: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);
}