分页查询用户加入的群(page/size;role 0=全部/1=成员/2=管理员/3=群主;order 0=正序/1=倒序,默认倒序;size 上限 100)。覆盖融云 /entrust/joined/group/query.json。
APP_KEY="demo"
APP_SECRET="YOUR_APP_SECRET"
BASE_URL="https://im.example.com"
NONCE="$(openssl rand -hex 16)"
TIMESTAMP="$(date +%s%3N)"
SIGNATURE="$(printf '%s' "$APP_SECRET$NONCE$TIMESTAMP" | openssl sha1 | awk '{print $2}')"
curl -sS -X POST "$BASE_URL/im/v2/entrust/joined/group/query" \
-H "Content-Type: application/json" \
-H "App-Key: $APP_KEY" \
-H "Nonce: $NONCE" \
-H "Timestamp: $TIMESTAMP" \
-H "Signature: $SIGNATURE" \
-d '{"userId":"user1","page":0,"size":20480,"role":0,"order":0}'
import { createHash, randomBytes } from 'node:crypto';
const APP_KEY = 'demo';
const APP_SECRET = 'YOUR_APP_SECRET';
const BASE_URL = 'https://im.example.com';
const PATH = '/im/v2/entrust/joined/group/query';
const nonce = randomBytes(16).toString('hex');
const timestamp = String(Date.now());
const signature = createHash('sha1')
.update(APP_SECRET + nonce + timestamp)
.digest('hex');
const res = await fetch(BASE_URL + PATH, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'App-Key': APP_KEY,
Nonce: nonce,
Timestamp: timestamp,
Signature: signature,
},
body: JSON.stringify({"userId":"user1","page":0,"size":20480,"role":0,"order":0}),
});
const result = await res.json();
if (result.code !== 0) throw new Error(result.code + ': ' + result.msg);
console.log(result.data);
{
"code": 0,
"data": {
"groups": [
{
"groupId": "group1",
"name": "Alice",
"owner": "user1",
"count": 1,
"role": 0,
"createTime": 0,
"joinTime": 0,
"portraitUrl": "string",
"remarkName": "string",
"groupProfile": "string"
}
],
"total": 1,
"page": 0,
"size": 20480,
"hasMore": false,
"pageToken": "string"
},
"requestId": "req_7f3a9c"
}