curl -X POST "http://localhost:5001/channel" \
-H "Content-Type: application/json" \
-d '{
"channel_id": "group123",
"channel_type": 2,
"large": 0,
"ban": 0,
"subscribers": ["user1", "user2", "user3"]
}'
const response = await fetch('http://localhost:5001/channel', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
channel_id: 'group123',
channel_type: 2,
large: 0,
ban: 0,
subscribers: ['user1', 'user2', 'user3']
})
});
const data = await response.json();
console.log(data);
import requests
data = {
"channel_id": "group123",
"channel_type": 2,
"large": 0,
"ban": 0,
"subscribers": ["user1", "user2", "user3"]
}
response = requests.post('http://localhost:5001/channel', json=data)
result = response.json()
print(result)
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
data := map[string]interface{}{
"channel_id": "group123",
"channel_type": 2,
"large": 0,
"ban": 0,
"subscribers": []string{"user1", "user2", "user3"},
}
jsonData, _ := json.Marshal(data)
resp, err := http.Post(
"http://localhost:5001/channel",
"application/json",
bytes.NewBuffer(jsonData),
)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("%+v\n", result)
}
{
"status": "ok"
}
频道管理
创建频道
创建新的聊天频道
POST
/
channel
curl -X POST "http://localhost:5001/channel" \
-H "Content-Type: application/json" \
-d '{
"channel_id": "group123",
"channel_type": 2,
"large": 0,
"ban": 0,
"subscribers": ["user1", "user2", "user3"]
}'
const response = await fetch('http://localhost:5001/channel', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
channel_id: 'group123',
channel_type: 2,
large: 0,
ban: 0,
subscribers: ['user1', 'user2', 'user3']
})
});
const data = await response.json();
console.log(data);
import requests
data = {
"channel_id": "group123",
"channel_type": 2,
"large": 0,
"ban": 0,
"subscribers": ["user1", "user2", "user3"]
}
response = requests.post('http://localhost:5001/channel', json=data)
result = response.json()
print(result)
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
data := map[string]interface{}{
"channel_id": "group123",
"channel_type": 2,
"large": 0,
"ban": 0,
"subscribers": []string{"user1", "user2", "user3"},
}
jsonData, _ := json.Marshal(data)
resp, err := http.Post(
"http://localhost:5001/channel",
"application/json",
bytes.NewBuffer(jsonData),
)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("%+v\n", result)
}
{
"status": "ok"
}
概述
创建新的聊天频道,支持个人频道和群组频道的创建。请求体
必传参数
string
必填
频道 ID,必须唯一
integer
必填
频道类型
1- 个人频道2- 群组频道
可选参数
integer
默认值:0
是否禁言
0- 允许发言1- 全员禁言
integer
默认值:0
是否解散频道
1- 解散频道(不可逆)
integer
默认值:0
是否禁止发送消息 (0.不禁止 1.禁止),禁止后,频道内所有成员都不能发送消息,个人频道能收消息,但不能发消息
integer
默认值:0
是否允许陌生人发送消息(0.不允许 1.允许)(此配置目前只支持个人频道)
个人频道:如果AllowStranger为1,则陌生人可以给当前用户发消息,比如:当前账号需要接受陌生人消息,channel_id为当前用户的uid
curl -X POST "http://localhost:5001/channel" \
-H "Content-Type: application/json" \
-d '{
"channel_id": "group123",
"channel_type": 2,
"large": 0,
"ban": 0,
"subscribers": ["user1", "user2", "user3"]
}'
const response = await fetch('http://localhost:5001/channel', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
channel_id: 'group123',
channel_type: 2,
large: 0,
ban: 0,
subscribers: ['user1', 'user2', 'user3']
})
});
const data = await response.json();
console.log(data);
import requests
data = {
"channel_id": "group123",
"channel_type": 2,
"large": 0,
"ban": 0,
"subscribers": ["user1", "user2", "user3"]
}
response = requests.post('http://localhost:5001/channel', json=data)
result = response.json()
print(result)
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
data := map[string]interface{}{
"channel_id": "group123",
"channel_type": 2,
"large": 0,
"ban": 0,
"subscribers": []string{"user1", "user2", "user3"},
}
jsonData, _ := json.Marshal(data)
resp, err := http.Post(
"http://localhost:5001/channel",
"application/json",
bytes.NewBuffer(jsonData),
)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("%+v\n", result)
}
{
"status": "ok"
}
响应字段
string
必填
操作状态,成功时返回
"ok"状态码
| 状态码 | 说明 |
|---|---|
| 200 | 频道创建成功 |
| 400 | 请求参数错误 |
| 409 | 频道 ID 已存在 |
| 500 | 服务器内部错误 |
最佳实践
- 频道 ID 唯一性:确保频道 ID 在系统中唯一
- 成员管理:合理设置初始订阅者列表
- 权限控制:根据需要设置禁言状态
⌘I

