Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
42959273
Commit
42959273
authored
Feb 05, 2020
by
ryoii
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update http md
parent
ec49701b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
274 additions
and
19 deletions
+274
-19
mirai-api-http/README_CH.md
mirai-api-http/README_CH.md
+274
-19
No files found.
mirai-api-http/README_CH.md
View file @
42959273
# mirai-api-http
# mirai-api-http
<b>
<b>
Mirai-API-http 提供HTTP API供所有语言使用mirai
</b>
Mirai-API-http 提供HTTP API供所有语言使用mirai
<br>
</b>
### 快速开始
```
kotlin
fun
main
()
{
val
bot
=
Bot
(
123456789
,
"password"
)
bot
.
login
()
MiraiHttpAPIServer
.
start
()
bot
.
network
.
awaitDisconnection
()
}
```
### 开始会话-认证(Authorize)
### 开始会话-认证(Authorize)
```
```
[POST] /auth
[POST] /auth
```
```
使用此方法验证你的会话连接, 并将这个会话绑定一个BOT
<br>
使用此方法验证你的身份,并返回一个会话
注意: 每个会话只能绑定一个BOT.
#### 请求:<br>
#### 请求:
```
json5
{
"authKey": "U9HSaDXl39ksd918273hU"
}
```
| 名字 | 类型 | 可选 | 举例 | 说明 |
| 名字 | 类型 | 可选 | 举例 | 说明 |
| --- | --- | --- | --- | --- |
| --- | --- | --- | --- | --- |
| key | String |false|U9HSaDXl39ksd918273hU|MIRAI API HTTP key, HTTP API的核心key|
| authKey | String |false|"U9HSaDXl39ksd918273hU"|创建Mirai-Http-Server时生成的key,可在启动时指定或随机生成|
| qq | String |false|1040400290|需要绑定的BOT QQ号|
#### 响应: 返回(成功):
#### 返回(成功):<br>
```
json5
{
"code": 0,
"session": "UnVerifiedSession"
}
```
| 名字 | 类型 | 举例 | 说明|
| 名字 | 类型 | 举例 | 说明|
| --- | --- | --- | --- |
| --- | --- | --- | --- |
| code |Int |0|返回状态|
| code |Int |0|返回状态
码
|
| session |String |
UANSHDKSLAOISN
|你的session key|
| session |String |
"UnVerifiedSession"
|你的session key|
#### 状态码:
<br>
#### 状态码:
| 代码 | 原因|
| 代码 | 原因|
| --- | --- |
| --- | --- |
| 0 | 正常 |
| 0 | 正常 |
| 1 | 错误的MIRAI API HTTP key|
| 1 | 错误的MIRAI API HTTP auth key|
| 2 | 试图绑定不存在的bot|
session key 是使用以下方法必须携带的
</br>
session key 是使用以下方法必须携带的
</br>
session key 需要被以cookie的形式上报
<b>
cookies
</b>
:
session key 使用前必须进行校验和绑定指定的Bot,
**每个Session只能绑定一个Bot,但一个Bot可有多个Session**
### 校验Session
```
[post] /verify
```
使用此方法校验并激活你的Session,同时将Session与一个
**已登录**
的Bot绑定
#### 请求:
```
json5
{
"sessionKey": "UnVerifiedSession",
"qq": 123456789
}
```
| 名字 | 类型 | 可选 | 举例 | 说明 |
| ---------- | ------ | ----- | ------------------- | -------------------------- |
| sessionKey | String | false | "UnVerifiedSession" | 你的session key |
| qq | Long | false | 123456789 | Session将要绑定的Bot的qq号 |
#### 响应: 返回统一状态码(后续不再赘述)
```
json5
{
"code": 0,
"msg": "success"
}
```
| 状态码 | 原因 |
| ------ | ---------------------------------- |
| 0 | 正常 |
| 1 | 错误的auth key |
| 2 | 绑定的Bot不存在 |
| 3 | Session失效或不存在 |
| 4 | Session未认证(未激活) |
| 5 | 发送消息目标不存在(指定对象不存在) |
| 400 | 错误的访问,如参数错误等 |
| 名字 | 值 |
| --- | --- |
| session |your session key here |
如果出现HTTP 403错误码,代表session key已过期, 需要重新获取
### 发送好友消息
### 发送好友消息
...
@@ -50,3 +110,198 @@ Mirai-API-http 提供HTTP API供所有语言使用mirai<br>
...
@@ -50,3 +110,198 @@ Mirai-API-http 提供HTTP API供所有语言使用mirai<br>
[POST] /sendFriendMessage
[POST] /sendFriendMessage
```
```
使用此方法向指定好友发送消息
#### 请求
```
json5
{
"sessionKey": "YourSession",
"target": 987654321,
"messageChain": [
{ "type": "Plain", "text":"hello\n" },
{ "type": "Plain", "text":"world" }
]
}
```
| 名字 | 类型 | 可选 | 举例 | 说明 |
| ------------ | ------ | ----- | ----------- | -------------------------------- |
| sessionKey | String | false | YourSession | 已经激活的Session |
| target | Long | false | 987654321 | 发送消息目标好友的QQ号 |
| messageChain | Array | false | [] | 消息链,是一个消息对象构成的数组 |
#### 响应: 返回统一状态码
```
json5
{
"code": 0,
"msg": "success"
}
```
### 发送群消息
```
[POST] /sendGroupMessage
```
使用此方法向指定群发送消息
#### 请求
```
json5
{
"sessionKey": "YourSession",
"target": 987654321,
"messageChain": [
{ "type": "Plain", "text":"hello\n" },
{ "type": "Plain", "text":"world" }
]
}
```
| 名字 | 类型 | 可选 | 举例 | 说明 |
| ------------ | ------ | ----- | ----------- | -------------------------------- |
| sessionKey | String | false | YourSession | 已经激活的Session |
| target | Long | false | 987654321 | 发送消息目标群的群号 |
| messageChain | Array | false | [] | 消息链,是一个消息对象构成的数组 |
#### 响应: 返回统一状态码
```
json5
{
"code": 0,
"msg": "success"
}
```
### 获取Bot收到的消息
```
[GET] /fetchMessage?sessionKey=YourSessionKey&count=10
```
#### 请求:
| 名字 | 可选 | 举例 | 说明 |
| ---------- | ----- | -------------- | --------------- |
| sessionKey | false | YourSessionKey | 你的session key |
| count | false | 10 | 获取消息的数量 |
#### 响应: 返回JSON对象
```
json5
[{
"type": "GroupMessage", // 消息类型:GroupMessage或FriendMessage
"messageChain": [{ // 消息链,是一个消息对象构成的数组
"type": "Plain",
"text": "Miral牛逼"
}],
"sender": { // 发送者信息
"id": 123456789, // 发送者的QQ号码
"memberName": "化腾", // 发送者的群名片
"permission": "MEMBER", // 发送者的群限权:OWNER、ADMINISTRATOR或MEMBER
"group": { // 消息发送群的信息
"id": 1234567890, // 发送群的群号
"name": "Miral Technology" // 发送群的群名称
}
}
},
{
"type": "FriendMessage", // 消息类型:GroupMessage或FriendMessage
"messageChain": [{ // 消息链,是一个消息对象构成的数组
"type": "Plain",
"text": "Miral牛逼"
}],
"sender": { // 发送者信息
"id": 1234567890, // 发送者的QQ号码
"nickName": "", // 发送者的昵称
"remark": "" // 发送者的备注
}
}]
```
### 消息类型一览
#### 消息是构成消息链的基本对象,目前支持的消息类型有
+
[x] At,@消息
+
[x] Face,表情消息
+
[x] Plain,文字消息
+
[ ] Image,图片消息
+
[ ] Xml,Xml卡片消息
+
[ ] 敬请期待
#### At
```
json5
{
"type": "At",
"target": 123456,
"display": "@Mirai"
}
```
| 名字 | 类型 | 说明 |
| ------- | ------ | ------------------------- |
| target | Long | 群员QQ号 |
| display | String | @时显示的文本如:"@Mirai" |
#### Face
```
json5
{
"type": "Face",
"faceID": 123
}
```
| 名字 | 类型 | 说明 |
| ------ | ---- | ---------- |
| faceID | Int | QQ表情编号 |
#### Plain
```
json5
{
"type": "Plain",
"text": "Mirai牛逼"
}
```
| 名字 | 类型 | 说明 |
| ---- | ------ | -------- |
| text | String | 文字消息 |
#### Image
```
json5
{
"type": "Image"
// 暂时不支持Image
}
```
| 名字 | 类型 | 说明 |
| ---- | ---- | ---- |
| | | |
#### Xml
```
json5
{
"type": "Xml",
"xml": "XML"
}
```
| 名字 | 类型 | 说明 |
| ---- | ------ | ------- |
| xml | String | XML文本 |
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment