新时空 API

如需获取更多信息或技术支持,请联系:

contact@newtimespace.com

新时空 API 获取单条或多条新闻详情

方法: GET

路径: /api/v1/news/:id

描述: 查询指定新闻的详情,支持多个 ID(逗号分隔)。

新闻项:

  • article_id: 字符串,文章 ID。
  • language: 字符串,语言代码。
  • title: 字符串,标题。
  • description: 字符串,描述。
  • content: 字符串,正文。
  • tags: 字符串,标签(逗号分隔)。
  • keywords: 数组,关键词。
  • authors: 数组,作者。
  • category: 字符串,分类。
  • dataType: 字符串,常量 "news"。
  • url: 字符串,文章 URL。
  • pubDate: 字符串,发布日期时间(Y-m-d H:i:s)。
  • pubDateTZ: 字符串,时区(UTC)。
  • date: 字符串,日期(Y-m-d)。
  • time: 字符串,时间(H:i:s)。
  • updated_at: 字符串,更新时间。
  • word_count: 整数,字数。
  • reading_time: 整数,阅读时间(分钟)。
  • is_breaking_news: 布尔,是否突发新闻。
  • sentiment: 字符串,情感(neutral 等)。
  • related_articles: 数组,相关文章。
  • geo_location: 字符串,地理位置。
  • source: 对象,来源信息(id, name, url, country, icon)。
  • image: 对象,图片信息(url, alt, caption, source, credit)。
  • video: 对象,视频信息(url, thumbnail, duration, source, credit)。

单条JSON响应示例
多条JSON相响应示例
错误响应(JSON 示例)
                         {
 "status": "success",
 "data": {
   "article_id": "123",
   "language": "zh-cn",
   "title": "新闻标题",
   "description": "新闻描述",
   "content": "新闻内容",
   "tags": "标签1,标签2",
   "keywords": ["关键词1", "关键词2"],
   "authors": ["作者1", "作者2"],
   "category": "分类名称",
   "dataType": "news",
   "url": "https://www.newtimespace.com/zh-cn/article/123",
   "pubDate": "2026-01-13 12:00:00",
   "pubDateTZ": "UTC",
   "date": "2026-01-13",
   "time": "12:00:00",
   "updated_at": "2026-01-13 13:00:00",
   "word_count": 500,
   "reading_time": 3,
   "is_breaking_news": false,
   "sentiment": "neutral",
   "related_articles": [],
   "geo_location": "",
   "source": {
     "id": "",
     "name": "NewTimeSpace",
     "url": "",
     "country": "",
   "icon": ""
   },
   "image": {
     "url": "",
     "alt": "",
     "caption": "",
     "source": "",
     "credit": ""
   },
   "video": {
     "url": null,
     "thumbnail": "",
     "duration": "",
     "source": "",
     "credit": ""
   }
  }
 },
 "pagination": {
   "page": 1,
   "limit": 10,
   "total": 100,
   "pages": 10
  }
 }
                        
                      

参数 arrow

参数 类型 必填 描述 默认值
articleIds string 文章 ID(逗号分隔,如 "123,456")。 ''
language string 语言(zh-cn, zh-hk, en) zh-cn
format string 返回格式(json 或 xml) json

状态码 arrow

  • 200: 成功。
  • 400: 参数无效。
  • 404: 新闻未找到。
  • 500: 内部错误。

错误处理 arrow

  • API 使用标准 HTTP 状态码。
  • 错误响应包含 "status": "error" 和 "message" 字段(JSON)。
  • XML 错误:错误消息

附加信息 arrow

  • 日志:错误记录到系统日志(Log::write)。
  • 缓存:分类信息使用静态缓存。
  • 语言转换:对于 zh-hk,使用简繁转换(需 Chinese 库)。
  • 安全:参数过滤(intval, trim, addslashes)。
  • 依赖:ThinkPHP 框架,数据库表(ts_information_news 等)。