Skip to content
On this page

小程序API参考

WanYesea 小程序通过 REST API 与 WordPress 后端进行数据交互。以下是主要 API 接口的详细说明:

基础信息

  • API 基础地址https://your-wordpress-site.com/wp-json/wanyesea/v1
  • 请求头
    plaintext
    Content-Type: application/json
    X-WP-Nonce: {nonce}
    
  • 认证方式:通过 WordPress 非ce认证机制
  • 响应格式:JSON

首页相关接口

获取首页轮播图

请求

plaintext
GET /home/banners

响应

json
{
  "success": true,
  "data": [
    {
      "id": 1,
      "image_url": "https://example.com/banner1.jpg",
      "link": "pages/detail/detail?id=1",
      "title": "最新壁纸"
    },
    // ...更多轮播图
  ]
}

获取公告信息

请求

plaintext
GET /home/notices

响应

json
{
  "success": true,
  "data": {
    "title": "重要更新通知",
    "content": "小程序v1.1.0版本已发布,新增收藏功能...",
    "date": "2023-11-01"
  }
}

壁纸相关接口

获取壁纸列表

请求

plaintext
GET /wallpapers?category={category_id}&page={page}&per_page={per_page}

参数

  • category_id (可选): 壁纸分类ID
  • page (可选): 页码,默认1
  • per_page (可选): 每页数量,默认10

响应

json
{
  "success": true,
  "data": {
    "total": 100,
    "pages": 10,
    "current_page": 1,
    "wallpapers": [
      {
        "id": 1,
        "title": "自然风光",
        "thumbnail_url": "https://example.com/thumb1.jpg",
        "full_url": "https://example.com/full1.jpg",
        "category": "nature",
        "download_count": 120
      },
      // ...更多壁纸
    ]
  }
}

获取壁纸详情

请求

plaintext
GET /wallpapers/{id}

响应

json
{
  "success": true,
  "data": {
    "id": 1,
    "title": "自然风光",
    "description": "高清自然风景壁纸",
    "full_url": "https://example.com/full1.jpg",
    "category": {
      "id": 2,
      "name": "自然"
    },
    "tags": ["山水", "风景", "4K"],
    "download_count": 120,
    "is_favorite": false
  }
}

收藏壁纸

请求

plaintext
POST /wallpapers/{id}/favorite

响应

json
{
  "success": true,
  "data": {
    "is_favorite": true,
    "message": "收藏成功"
  }
}

取消收藏壁纸

请求

plaintext
DELETE /wallpapers/{id}/favorite

响应

json
{
  "success": true,
  "data": {
    "is_favorite": false,
    "message": "取消收藏成功"
  }
}

用户相关接口

用户登录

请求

plaintext
POST /user/login
Content-Type: application/json

{
  "code": "{wx_login_code}"
}

响应

json
{
  "success": true,
  "data": {
    "user_id": 123,
    "nickname": "用户昵称",
    "avatar": "https://example.com/avatar.jpg",
    "vip_level": 0,
    "vip_expire": null,
    "nonce": "{new_nonce}"
  }
}

获取用户收藏

请求

plaintext
GET /user/favorites?page={page}&per_page={per_page}

响应

json
{
  "success": true,
  "data": {
    "total": 20,
    "pages": 2,
    "current_page": 1,
    "favorites": [
      {
        "id": 1,
        "wallpaper_id": 5,
        "title": "壁纸标题",
        "thumbnail_url": "https://example.com/thumb5.jpg",
        "added_time": "2023-10-20"
      },
      // ...更多收藏
    ]
  }
}

功能相关接口

获取功能模块列表

请求

plaintext
GET /functions?category={category_id}

响应

json
{
  "success": true,
  "data": [
    {
      "id": 1,
      "title": "图片压缩",
      "description": "压缩图片大小,节省存储空间",
      "icon_url": "https://example.com/icon1.png",
      "category_id": 1,
      "category_name": "工具"
    },
    // ...更多功能
  ]
}

获取功能详情

请求

plaintext
GET /functions/{id}

响应

json
{
  "success": true,
  "data": {
    "id": 1,
    "title": "图片压缩",
    "description": "压缩图片大小,节省存储空间",
    "icon_url": "https://example.com/icon1.png",
    "cover_image": "https://example.com/cover1.jpg",
    "content": "详细功能介绍...",
    "steps": [
      "步骤1:选择图片",
      "步骤2:设置压缩参数",
      "步骤3:点击压缩"
    ],
    "related_functions": [2, 5, 8]
  }
}

错误处理

API 响应中包含错误信息,格式如下:

json
{
  "success": false,
  "error": {
    "code": "invalid_request",
    "message": "无效的请求参数",
    "details": "壁纸ID不能为空"
  }
}

常见错误代码:

  • unauthorized: 用户未登录
  • invalid_request: 请求参数错误
  • not_found: 资源不存在
  • server_error: 服务器内部错误
  • rate_limit_exceeded: 请求频率超限