[“timeout” => 15]]);
$json = @file_get_contents($url, false, $context);
if ($json === false) {
return [“error” => true, “message” => “无法连接API”];
}
$response = json_decode($json, true);
$d = $response[‘data’] ?? [];
// 解析完整 CoinGecko 数据(关键!)
$raw_json = $d[‘raw_coin_data’] ?? $d[‘raw_data’] ?? ‘{}’;
$raw = json_decode($raw_json, true) ?: [];
$market = $raw[‘market_data’] ?? [];
// 调试信息(上线后可删除)
error_log(“Raw length: ” . strlen($raw_json) . ” | Rank: ” . ($raw[‘market_cap_rank’] ?? ‘N/A’));
return [
“price_usd” => (float)($d[‘price_usd’] ?? 0),
“price_change_percentage_24h” => (float)($d[‘price_change_percentage_24h’] ?? 0),
“market_cap_usd” => (float)($d[‘market_cap_usd’] ?? 0),
“total_volume_24h” => (float)($d[‘total_volume_24h’] ?? 0),
“circulating_supply” => (float)($d[‘circulating_supply’] ?? 0),
“market_cap_rank” => (int)($raw[‘market_cap_rank’] ?? 0),
“high_24h” => (float)($market[‘high_24h’][‘usd’] ?? 0),
“low_24h” => (float)($market[‘low_24h’][‘usd’] ?? 0),
“price_change_percentage_7d” => (float)($market[‘price_change_percentage_7d_in_currency’][‘usd’] ?? 0),
“ath” => (float)($market[‘ath’][‘usd’] ?? 0),
“ath_change_percentage” => (float)($market[‘ath_change_percentage’][‘usd’] ?? 0),
// 新增:历史最低 (ATL)
“atl” => (float)($market[‘atl’][‘usd’] ?? 0),
“atl_change_percentage” => (float)($market[‘atl_change_percentage’][‘usd’] ?? 0),
“error” => false
];
}
$doge = get_doge_data();
$change_color = $doge[‘price_change_percentage_24h’] >= 0 ? ‘text-green-400’ : ‘text-red-400’;
$change_sign = $doge[‘price_change_percentage_24h’] >= 0 ? ‘+’ : ”;
?>
– 欢迎来到狗狗币大家庭!
DOGECOIN 实时数据
$
市值
$ B
24h 成交量
$ B
7天涨跌
历史最高 (ATH)
$
(↓ %)
全球市值排行
#
流通总量
B DOGE
历史最低 (ATL)
$
(↑ %)
这里是 DOGECOIN 的家!
分享 meme、讨论价格、一起 To the Moon!
Very community. Much love.