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/message/stream/end" \
-H "Content-Type: application/json" \
-H "App-Key: $APP_KEY" \
-H "Nonce: $NONCE" \
-H "Timestamp: $TIMESTAMP" \
-H "Signature: $SIGNATURE" \
-d '{"streamId":"stream_1"}'
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/message/stream/end';
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({"streamId":"stream_1"}),
});
const result = await res.json();
if (result.code !== 0) throw new Error(result.code + ': ' + result.msg);
console.log(result.data);
{
"code": 0,
"data": {
"messageId": "msg_10001",
"clientMsgId": "client_9f2a7c",
"conversationType": 1,
"targetId": "user2",
"channelId": "channel1",
"senderId": "user1",
"seq": 1024,
"timestamp": 1750000000000,
"content": {
"type": "text",
"text": "你好,IM PaaS"
},
"direction": 1
},
"requestId": "req_7f3a9c"
}