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/supergroup/join-policy/set" \
-H "Content-Type: application/json" \
-H "App-Key: $APP_KEY" \
-H "Nonce: $NONCE" \
-H "Timestamp: $TIMESTAMP" \
-H "Signature: $SIGNATURE" \
-d '{"groupId":"group1","joinPolicy":"open"}'
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/supergroup/join-policy/set';
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({"groupId":"group1","joinPolicy":"open"}),
});
const result = await res.json();
if (result.code !== 0) throw new Error(result.code + ': ' + result.msg);
console.log(result.data);
{
"code": 0,
"data": {
"groupId": "group1",
"name": "产品群",
"groupType": "normal",
"owner": "user1",
"ownerName": "Alice",
"members": [
"user2"
],
"memberCount": 1,
"admins": [
"user1"
],
"muted": {
"user2": 0
},
"notice": "本周五 20:00 全员复盘",
"avatarUrl": "https://cdn.example.com/avatar/user1.png",
"createdAt": 1750000000000,
"maxMembers": 3000
},
"requestId": "req_7f3a9c"
}