#站内信API服务
[toc]
##一、运行方法
composer install.env.example到.env并修改其中的数据库配置。php artisan migrate执行数据库迁移。php -S 0.0.0.0:8080 -t public 开启服务(测试用)。启动mysql数据库:
docker run --name message_server_mysql \
-e MYSQL_ROOT_PASSWORD=pass \
-d mysql --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
创建message_server数据库:
docker exec message_server_mysql bash -c 'echo "CREATE DATABASE message_server" | mysql -u root -ppass'
启动message_server:
./build_image.sh
./start-container.sh
##二、单元测试
phpunit
##三、接口文档
请求:GET /groups
响应:
{
"data": [
{
"id": 1,
"name": "major group",
"created_at": "2016-03-30 06:28:17",
"updated_at": "2016-03-30 06:28:17"
},
{
"id": 2,
"name": "second group",
"created_at": "2016-03-30 06:29:39",
"updated_at": "2016-03-30 06:29:39"
}
]
}
请求:POST /groups
参数:
请求示例
curl -H "Content-Type: application/json" --data '{"name": "major group"}' $host/groups
响应
{
"data": {
"name": "major group",
"updated_at": "2016-03-30 06:28:17",
"created_at": "2016-03-30 06:28:17",
"id": 1
}
}
请求: POST /groups/add_users
参数:
{
group_id: 1,
users: [1, 2, 3]
}
请求示例
curl -H "Content-Type: application/json" --data '{"group_id": 1, "users": [1, 2, 3]}' $host/groups/add_users
请求:DELETE /groups/delete_users
参数:
{
group_id: 1,
users: [1, 2, 3]
}
请求示例
curl -H "Content-Type: application/json" -X DELETE --data '{"group_id": 1, "users": [1, 2, 3]}' $host/groups/delete_users
请求:DELETE /groups/{group_id}
参数:
请求示例
curl -X DELETE $host/groups/2
请求:POST /messages/
参数:
user、group、global,分别为发送给用户的消息,发送给群组的消息和发送给全体的消息。user和group时可用,标示要接收的群体。example:
{
'content': 'this is a message',
'target_type': 'user',
'targets': [1, 2, 3],
'sender_id': 1
}
请求示例
curl -H "Content-Type: application/json" --data '{"content":"this is a message","target_type":"user","targets":[1,2,3],"sender_id":1}' $host/messages
响应:
{"data":[]}
请求:GET /users/{user_id}/unread_messages_count
参数:
请求示例
curl $host/users/1/unread_messages_count
响应
{"data":1}
请求:GET /users/{user_id}/unread_messages
参数:
请求示例
curl $host/users/1/unread_messages
响应:
{
"data": [
{
"id": 1,
"content": "this is a message",
"created_at": "2016-03-30 06:42:59",
"sender_id": 1
}
]
}
请求:POST /messages/read
参数:
请求示例:
curl -H "Content-Type: application/json" --data '{"user_id": 1,"message_id":1}' $host/messages/read
请求:GET /users/{user_id}/read_messages
参数:
请求示例
curl $host/users/1/unread_messages
响应:
{
"data": [
{
"id": 1,
"content": "this is a message",
"created_at": "2016-03-30 06:42:59",
"sender_id": 1
}
]
}
Content type
Image
Digest
Size
201.4 MB
Last updated
over 8 years ago
docker pull chareice/message-server