Php 代码有但我没有';我不知道在哪里
所以我有代码应该从bitskins或steamcommunity获取物品价格。它什么都做,除了价格是0Php 代码有但我没有';我不知道在哪里,php,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->getCod
<?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("$" , "", $price2);
$price2 = str_replace("$" , "", $price2);
$price2 = round(str_replace(",",".",$price2), 2);
}
else
{
$price2 = $item_price->price;
$price2 = str_replace("$" , "", $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
]);
?>
如果项位于数据库中,则以下是bitskins API结果:
如果项目不在数据库中,请执行以下操作:
基本上,若项目不在数据库中,它应该使用steam市场。我找不到任何“错误”代码,但它在数据库中插入了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("$" , "", $price2);
$price2 = str_replace("$" , "", $price2);
$price2 = round(str_replace(",",".",$price2), 2);
}
您无法从steamcommunity.com$link
获取内容,并试图从失败的数据集中提取中间价
试着这样做:
$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("$" , "", $price2);
$price2 = str_replace("$" , "", $price2);
$price2 = round(str_replace(",",".",$price2), 2);
}
当bitskins上的price为null时尝试这样做,否则它会从bitskins获取price,或者我在那里做了一些错误的事情:D?您使用文件获取内容从bitskins.com获取数据,但如果失败,您就不能使用文件获取内容从backup steamcommunity.com获取数据。嗯,您能为我“修复”代码吗?非常感谢,先生添加了示例解决方案。尝试了您的部分代码,但仍在数据库中输入了0以获取价格。