Subscribing to private channels requires prior login authentication.
Login (private channel authentication)
Authentication process : establish connection → send login request → wait for response → subscribe to private channel
Login request :
{
"op": "login",
"args": [
{
"apiKey": "YOUR_API_KEY",
"timestamp": "1766124407915",
"sign": "BASE64_ENCODED_SIGNATURE"
}
]
}Request parameters :
| Parameter | Type | Explanation |
|---|---|---|
| apiKey | String | API Key |
| timestamp | String | Current timestamp (milliseconds) |
| sign | String | Signature (Base64 encoding) |
Signature generation :
Signature string: timestamp + "GET" + "/user/verify" + ""
-
Use secretKey to encrypt the signature string with HMAC SHA256
-
Base64 encoding the results
JavaScript example :
const crypto = require('crypto');
function generateSign(timestamp, secretKey) {
const message = timestamp + 'GET' + '/user/verify' + '';
return crypto.createHmac('sha256', secretKey).update(message).digest('base64');
}Python example :
import hmac, base64
def generate_sign(timestamp, secret_key):
message = timestamp + 'GET' + '/user/verify' + ''
signature = hmac.new(bytes(secret_key, 'utf8'), bytes(message, 'utf-8'), digestmod='sha256').digest()
return base64.b64encode(signature).decode()Login response :
{"event": "login","code": "0"}