API 调用文档

接口列表和参数详见 API 页面,本页介绍如何使用

返回格式

302 重定向(默认)

GET https://api.yppp.net/pc.php
→ 302 Found
→ Location: https://list.yppp.net/d/image/xxx.jpg

JSON 格式

GET https://api.yppp.net/pc.php?return=json

{
  "code": "200",
  "acgurl": "https://list.yppp.net/d/image/xxx.png",
  "width": "2290",
  "height": "1200",
  "size": "png"
}

使用示例

HTML 直接展示

<img src="https://api.yppp.net/pc.php" alt="随机图片">

简单场景下直接用 img 标签即可,每次刷新页面都会返回不同图片

JavaScript 获取

// 获取 JSON 格式
const res = await fetch('https://api.yppp.net/pc.php?return=json');
const data = await res.json();
console.log(data.acgurl);

// 同一页面多次调用需加时间戳避免缓存
const res2 = await fetch(`https://api.yppp.net/pc.php?return=json&t=${Date.now()}`);

Python 请求

import requests

# JSON 格式
res = requests.get('https://api.yppp.net/pc.php?return=json')
print(res.json()['acgurl'])

# 直接下载图片
res = requests.get('https://api.yppp.net/pc.php')
with open('random.jpg', 'wb') as f:
    f.write(res.content)

cURL

# 获取 JSON
curl https://api.yppp.net/pc.php?return=json

# 直接下载
curl -L https://api.yppp.net/pc.php -o random.jpg

注意事项

返回 API 页面 回到图库