文章详情接口

接口说明

获取单篇文章的详细信息。支持加密文章的访问,登录用户可以查看更多信息。

  • 接口URL: /api/articles/show
  • 请求方法: POST
  • 权限要求: 支持匿名访问,登录用户可查看更多信息

请求参数

参数名 类型 必填 说明 示例值
article_id number 文章ID 1
article_password string 文章密码,访问加密文章时需提供 "123456"

响应结构

typescript 复制代码
interface Response {
  code: number;      // 状态码
  message: string;   // 响应消息
  data: Article;     // 文章详情
}

interface Article {
  article_id: number;           // 文章ID
  article_title: string;        // 文章标题
  article_date: string;         // 发布日期
  article_text: string;         // 文章完整内容
  article_title_image: string;  // 标题图片
  article_views: number;        // 浏览量
  article_likes: number;        // 点赞数
  article_comments: number;     // 评论数
  article_private: number;      // 是否私密
  article_password: string;     // 文章密码
  has_password: boolean;        // 是否需要密码访问
}

响应示例

json 复制代码
{
  "code": 0,
  "message": "success",
  "data": {
    "article_id": 1,
    "article_title": "示例文章",
    "article_date": "2024-01-01",
    "article_text": "这是文章的完整内容...",
    "article_title_image": "https://example.com/image.jpg",
    "article_views": 100,
    "article_likes": 50,
    "article_comments": 10,
    "article_private": 0,
    "article_password": "",
    "has_password": false
  }
}

特殊说明

文章访问权限

  • 普通文章:所有用户可以访问
  • 加密文章:需要提供正确的 article_password
  • 私密文章(article_private=1):仅登录用户可访问

密码验证

  • 访问加密文章时,必须提供正确的密码才能查看文章内容
  • 密码错误时,文章内容将被过滤
  • 登录用户可以不受密码限制访问所有文章

错误码说明

错误码 说明 处理建议
0 成功 -
404 文章不存在 检查文章ID是否正确
403 密码错误或无权访问 检查密码是否正确或登录后访问
500 服务器错误 请联系管理员

调用示例

基础调用

typescript 复制代码
const response = await fetch('/api/articles/show', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    article_id: 1
  })
});

访问加密文章

typescript 复制代码
const response = await fetch('/api/articles/show', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    article_id: 1,
    article_password: "123456"
  })
});