curl -X POST "http://localhost:5001/route/batch?intranet=0" \
-H "Content-Type: application/json" \
-d '["user1", "user2", "user3"]'
const userIds = ["user1", "user2", "user3"];
const response = await fetch('http://localhost:5001/route/batch?intranet=0', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(userIds)
});
const data = await response.json();
console.log(data);
import requests
user_ids = ["user1", "user2", "user3"]
response = requests.post(
'http://localhost:5001/route/batch',
params={'intranet': 0},
json=user_ids
)
data = response.json()
print(data)
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
userIds := []string{"user1", "user2", "user3"}
jsonData, _ := json.Marshal(userIds)
resp, err := http.Post(
"http://localhost:5001/route/batch?intranet=0",
"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)
}
[
{
"uids": ["user1", "user2"],
"tcp_addr": "127.0.0.1:5100",
"ws_addr": "ws://127.0.0.1:5200",
"wss_addr": "wss://127.0.0.1:5300"
},
{
"uids": ["user3"],
"tcp_addr": "127.0.0.1:5101",
"ws_addr": "ws://127.0.0.1:5201",
"wss_addr": "wss://127.0.0.1:5301"
}
]
路由管理
批量获取用户 IM 地址
批量获取多个用户的 IM 连接地址
POST
/
route
/
batch
curl -X POST "http://localhost:5001/route/batch?intranet=0" \
-H "Content-Type: application/json" \
-d '["user1", "user2", "user3"]'
const userIds = ["user1", "user2", "user3"];
const response = await fetch('http://localhost:5001/route/batch?intranet=0', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(userIds)
});
const data = await response.json();
console.log(data);
import requests
user_ids = ["user1", "user2", "user3"]
response = requests.post(
'http://localhost:5001/route/batch',
params={'intranet': 0},
json=user_ids
)
data = response.json()
print(data)
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
userIds := []string{"user1", "user2", "user3"}
jsonData, _ := json.Marshal(userIds)
resp, err := http.Post(
"http://localhost:5001/route/batch?intranet=0",
"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)
}
[
{
"uids": ["user1", "user2"],
"tcp_addr": "127.0.0.1:5100",
"ws_addr": "ws://127.0.0.1:5200",
"wss_addr": "wss://127.0.0.1:5300"
},
{
"uids": ["user3"],
"tcp_addr": "127.0.0.1:5101",
"ws_addr": "ws://127.0.0.1:5201",
"wss_addr": "wss://127.0.0.1:5301"
}
]
概述
批量获取多个用户的 IM 连接地址,用于为不同用户分配不同的连接节点。查询参数
是否返回内网地址
0- 返回外网地址1- 返回内网地址
请求体
curl -X POST "http://localhost:5001/route/batch?intranet=0" \
-H "Content-Type: application/json" \
-d '["user1", "user2", "user3"]'
const userIds = ["user1", "user2", "user3"];
const response = await fetch('http://localhost:5001/route/batch?intranet=0', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(userIds)
});
const data = await response.json();
console.log(data);
import requests
user_ids = ["user1", "user2", "user3"]
response = requests.post(
'http://localhost:5001/route/batch',
params={'intranet': 0},
json=user_ids
)
data = response.json()
print(data)
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
userIds := []string{"user1", "user2", "user3"}
jsonData, _ := json.Marshal(userIds)
resp, err := http.Post(
"http://localhost:5001/route/batch?intranet=0",
"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)
}
[
{
"uids": ["user1", "user2"],
"tcp_addr": "127.0.0.1:5100",
"ws_addr": "ws://127.0.0.1:5200",
"wss_addr": "wss://127.0.0.1:5300"
},
{
"uids": ["user3"],
"tcp_addr": "127.0.0.1:5101",
"ws_addr": "ws://127.0.0.1:5201",
"wss_addr": "wss://127.0.0.1:5301"
}
]
响应字段
响应是一个数组,每个元素包含以下字段:分配到此地址的用户 ID 列表
TCP 连接地址,格式为
host:portWebSocket 连接地址,格式为
ws://host:portWebSocket Secure 连接地址,格式为
wss://host:port状态码
| 状态码 | 说明 |
|---|---|
| 200 | 成功获取批量 IM 连接地址 |
| 400 | 请求参数错误 |
| 500 | 服务器内部错误 |
⌘I

