开放API文档
欢迎使用代码资源网开放API
我们提供了丰富的API接口,方便开发者集成和扩展网站功能。通过API,您可以实现收藏管理、用户认证、内容获取等功能。
基础URL:
http://www.mokuo.cn
认证方式: Session认证(需要先登录)
数据格式: JSON
API密钥管理
GET
/api/apply
API密钥申请页面
响应示例
HTML页面
POST
/api/handleApply
提交API密钥申请
参数
| 参数名 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
purpose |
string | 是 | API使用目的 |
description |
string | 否 | 项目描述 |
contact |
string | 否 | 联系方式 |
响应示例
{"code": 200, "message": "API密钥申请成功", "data": {"api_key": "xxxxxxxxxxxxxxxxxx", "message": "提示信息"}}
GET
/api/auth/profile
获取当前认证用户信息
请求头
Authorization: Bearer YOUR_API_KEY
响应示例
{"success": true, "data": {"user_id": 123, "username": "testuser", "email": "test@example.com"}}
收藏相关API
POST
/api/favorite/add
添加收藏
参数
| 参数名 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
content_type |
string | 是 | 内容类型 (software/tutorial/technical) |
content_id |
integer | 是 | 内容ID |
请求头
Authorization: Bearer YOUR_API_KEY
响应示例
{"success": true, "message": "收藏成功", "data": {"count": 10}}
POST
/api/favorite/remove
取消收藏
参数
| 参数名 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
content_type |
string | 是 | 内容类型 (software/tutorial/technical) |
content_id |
integer | 是 | 内容ID |
请求头
Authorization: Bearer YOUR_API_KEY
响应示例
{"success": true, "message": "取消收藏成功", "data": {"count": 9}}
GET
/api/favorite/check
检查收藏状态
参数
| 参数名 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
content_type |
string | 是 | 内容类型 (software/tutorial/technical) |
content_id |
integer | 是 | 内容ID |
请求头
Authorization: Bearer YOUR_API_KEY
响应示例
{"success": true, "data": {"is_favorite": true, "count": 10}}
GET
/api/favorite/list
获取收藏列表
参数
| 参数名 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
content_type |
string | 否 | 内容类型过滤 |
page |
integer | 否 | 页码,默认1 |
pageSize |
integer | 否 | 每页数量,默认20 |
请求头
Authorization: Bearer YOUR_API_KEY
响应示例
{"success": true, "data": {"items": [...], "total": 50, "page": 1, "pageSize": 20}}
用户认证API
POST
/api/auth/login
API用户登录
参数
| 参数名 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
username |
string | 是 | 用户名 |
password |
string | 是 | 密码 |
响应示例
{"success": true, "message": "登录成功", "data": {"token": "YOUR_API_KEY"}}
POST
/api/auth/register
API用户注册
参数
| 参数名 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
username |
string | 是 | 用户名 |
password |
string | 是 | 密码 |
email |
string | 是 | 邮箱 |
响应示例
{"success": true, "message": "注册成功", "data": {"user_id": 123}}
POST
/api/auth/logout
API用户登出
请求头
Authorization: Bearer YOUR_API_KEY
响应示例
{"success": true, "message": "登出成功"}