https://tool.54nav.com/project/api.php
(GET 请求){"image": "图片地址"}
https://tool.54nav.com/project/demo.php
输入您的远程 TXT 文件 URL(每行一个图片 URL),绑定后生成 KEY。使用 API 时添加 ?key=您的KEY,即可从您的库随机获取图片。
欢迎投稿您的图片 URL!支持多行输入(每行一个 URL),待审核通过后加入API库中。
以下是使用不同语言调用 API 的示例代码。
<?php
$apiUrl = 'https://tool.54nav.com/project/api.php';
$response = file_get_contents($apiUrl);
if ($response === false) {
die('请求失败');
}
$data = json_decode($response, true);
if (isset($data['image'])) {
echo '<img src="' . htmlspecialchars($data['image']) . '" alt="随机图片" style="max-width: 100%;">';
} else {
echo '错误: ' . htmlspecialchars($data['error'] ?? '未知错误');
}
?>
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
class Program {
static async Task Main(string[] args) {
string apiUrl = "https://tool.54nav.com/project/api.php";
using var client = new HttpClient();
try {
string response = await client.GetStringAsync(apiUrl);
dynamic data = JsonConvert.DeserializeObject(response);
if (data.image != null) {
Console.WriteLine("图片 URL: " + data.image);
} else {
Console.WriteLine("错误: " + data.error);
}
} catch (Exception ex) {
Console.WriteLine("请求失败: " + ex.Message);
}
}
}
import requests
import json
api_url = 'https://tool.54nav.com/project/api.php'
try:
response = requests.get(api_url)
response.raise_for_status()
data = json.loads(response.text)
if 'image' in data:
print('图片 URL:', data['image'])
else:
print('错误:', data.get('error', '未知错误'))
except requests.RequestException as e:
print('请求失败:', e)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript API 示例</title>
</head>
<body>
<img id="image" src="" alt="随机图片" style="max-width: 100%; display: none;">
<button onclick="fetchImage()">获取图片</button>
<script>
function fetchImage() {
const apiUrl = 'https://tool.54nav.com/project/api.php';
fetch(apiUrl)
.then(response => {
if (!response.ok) {
throw new Error('网络响应错误');
}
return response.json();
})
.then(data => {
if (data.image) {
const img = document.getElementById('image');
img.src = data.image;
img.style.display = 'block';
} else {
console.error('错误:', data.error);
alert('错误: ' + data.error);
}
})
.catch(error => {
console.error('请求失败:', error);
alert('请求失败: ' + error.message);
});
}
</script>
</body>
</html>