爱狐API

根据设备类型自动返回随机图片,支持 302 重定向和 JSON 两种模式。

接口地址

GET /api/v1/randimg
GET /api/v1/headimg
GET /api/v1/yiyan

接口说明

/api/v1/randimg - 根据设备类型从数据库随机返回图片

/api/v1/headimg - 从 static/headimg 目录随机返回头像图片

/api/v1/yiyan - 从数据库随机返回一条一言数据

请求参数

接口 参数 类型 必填 说明
/api/v1/randimg type string 值为 json 时返回 JSON,否则 302 重定向
/api/v1/headimg - - - 无参数,直接返回图片文件
/api/v1/yiyan - - - 无参数,返回 JSON 格式的一言数据

返回示例

/api/v1/randimg(302 重定向):

GET /api/v1/randimg

/api/v1/randimg(JSON 模式):

GET /api/v1/randimg?type=json

{
  "success": true,
  "device_type": "pc",
  "image_url": "https://image.baidu.com/search/down?url=...",
  "content": "..."
}

/api/v1/headimg:

GET /api/v1/headimg
直接返回图片文件(jpg/png/gif等)

/api/v1/yiyan:

GET /api/v1/yiyan

{
  "success": true,
  "data": {
    "id": 1,
    "content": "人生若只如初见",
    "type": "poetry",
    "author": "纳兰性德",
    ...
  }
}

使用示例

<img src="/api/v1/randimg" alt="随机图片">
<img src="/api/v1/headimg" alt="随机头像">

<script>
fetch('/api/v1/yiyan')
  .then(res => res.json())
  .then(data => console.log(data.data.content));
</script>

图片预览

随机图片:

随机图片

随机头像:

随机头像

随机一言:

加载中...