以下是 Iridencense 支持的 WebSocket 命令和对应的 JSON 数据格式:
请求:
{
"command": "login",
"userId": 1,
"password": "password123"
}响应:
{
"state": true,
"message": "登录成功"
}请求:
{
"command": "signUp",
"userid": 1,
"password": "password123"
}请求:
{
"command": "sendMessage",
"targetId": 2,
"requestId": 1,
"messageBody": "Hello, world!",
"time": 1631846000
}响应:
{
"requestId": 1,
"messageId": 1,
"time": 1631846000,
"state": 1
}请求:
{
"command": "addFriend",
"friendId": 2
}请求:
{
"command": "deleteFriend",
"friendId": 2
}请求:
{
"command": "getUserData",
"userId": 1
}响应:
{
"userId": 1,
"userName": "张三",
"userAvatar": "http://example.com/avatar.jpg",
"userNote": "这是一个备注",
"userPermission": 1,
"userFriendList": "[2,3,4]"
}请求:
{
"command": "changeAvatar",
"newAvatar": "http://example.com/new_avatar.jpg"
}响应:
{
"userId": 1,
"newAvatar": "http://example.com/new_avatar.jpg",
"success": true
}请求:
{
"command": "getMessagesWithUser",
"otherUserId": 2,
"startTime": 1631846000,
"endTime": 1631932400
}响应:
{
"userId": 1,
"messages": [
{
"messageId": 1,
"senderId": 1,
"receiverId": 2,
"time": 1631846000,
"messageBody": "Hello, world!",
"messageType": 1
}
]
}请求:
{
"command": "createGroup",
"groupName": "新群聊",
"groupExplaination": "这是一个新的群聊"
}响应:
{
"groupId": 1,
"success": true
}请求:
{
"command": "breakGroup",
"groupId": 1
}响应:
{
"groupId": 1,
"success": true
}请求:
{
"command": "sendGroupMessage",
"groupId": 1,
"messageBody": "Hello, group!",
"requestId": 1
}响应:
{
"requestId": 1,
"messageId": 1,
"time": 1631846000,
"state": 1
}以下是 Iridencense HTTP API 支持的请求和响应:
- URL:
/register - Method:
POST - Content-Type:
application/json或application/x-www-form-urlencoded - Request Body (JSON):
userName: 用户名,不超过10个字符password: 密码,长度在8到100个字符之间,必须包含大小写字母和数字
- Response: 用户唯一的自增ID
- URL:
/login - Method:
POST - Content-Type:
application/x-www-form-urlencoded - Request Body (JSON):
userId: 用户IDpassword: 用户密码
- Response: 用户的 token
- URL:
/request - Method:
POST - Content-Type:
application/json或application/x-www-form-urlencoded - Request Body (JSON):
token: 用户的 tokencommand: 指令,可以是getUserData或getUserDataByIDtarget(可选): 目标用户的ID,仅在command为getUserDataByID时使用
- Response: 用户的信息,包括用户名、头像、备注、权限和好友列表
- URL:
/request - Method:
POST - Content-Type:
application/json或application/x-www-form-urlencoded - Request Body (JSON):
token: 服务器的 tokencommand: 指令,必须为verifyTokentargetToken: 要验证的用户 token
- Response: 用户的信息,包括用户名、头像、备注、权限和好友列表
- URL:
/request - Method:
POST - Content-Type:
application/json - Request Body (JSON):
token: 用户的 tokencommand: 指令,必须为publishPostuserID: 用户IDcontent: 帖子内容
- Response: 发布成功的确认
- URL:
/request - Method:
POST - Content-Type:
application/json - Request Body (JSON):
token: 用户的 tokencommand: 指令,必须为getPostpostID: 帖子ID
- Response: 指定的帖子
- URL:
/request - Method:
POST - Content-Type:
application/json - Request Body (JSON):
token: 用户的 tokencommand: 指令,必须为getUserPostsuserID: 用户IDstartTime: 开始时间 (Unix timestamp)endTime: 结束时间 (Unix timestamp)
- Response: 用户在指定时间段内的所有帖子的列表
- URL:
/request - Method:
POST - Content-Type:
application/json - Request Body (JSON):
token: 用户的 tokencommand: 指令,必须为getPostsstartTime: 开始时间 (Unix timestamp)endTime: 结束时间 (Unix timestamp)
- Response: 指定时间段内的所有帖子的列表
- 400 Bad Request: 请求的参数无效或缺失
- 401 Unauthorized: 提供的 token 无效
- 500 Internal Server Error: 服务器内部错误
- 所有的请求都必须是 POST 请求
- 所有的参数都应该在请求体中以 JSON 或表单的形式提供
- 所有的响应都是纯文本,除了获取用户信息的响应是 JSON 格式
- 用户的 token 在登录成功后由服务器生成并返回,之后的所有请求都应该在请求头中提供这个 token
- 服务器的 token 应该在配置文件中提供,并且只能用于验证用户 token 的请求
请注意,API暂不完善,仍在开发中