Login and logout callback
Overview
You can use this callback to listen for user login and logout and implement the business logic, for example, counting online users.
- User login: A TCP connection is established.
- User logout or network disconnection: A TCP connection is disconnected.
- App heartbeat timeout: An app is killed or crashes.
Callback description
- Request method: POST.
Note
The callback data format is JSON, and you need to perform UrlDecode decoding on it.
- Request URL: Contact ZEGOCLOUD technical support to configure the callback URL.
- Protocol: HTTPS/HTTP. HTTPS is recommended.
Callback parameters
Parameter | Type | Description |
---|---|---|
appid | String | The unique ID of an app. |
event | String | The callback event. The return value is user_action . |
timestamp | Integer | The Unix timestamp of the callback server. Unit: seconds. |
nonce | String | A random number. |
signature | String | The verification string. For more information, see Authenticating server-to-server callbacks. |
user_id | String | The user ID. |
user_name | STRING | The username. |
os | String | The description of the operating system, which is synchronized upon user login. Valid values:
|
action | Integer | Status. Valid values:
|
session_id | String | The unique ID of a session. If a user is online on multiple terminals, multiple sessions exist and are identified by ID. |
login_time | Integer | The Unix timestamp of login. Unit: seconds. |
relogin | String | The identifier of re-login. Valid values:
|
logout_time | Integer | The Unix timestamp of logout. Unit: seconds. |
logout_reason | String | The reason for logout. |
offline_time | Integer | The Unix timestamp of going offline. Unit: seconds. |
We recommend that you convert some parameters into integers for logic processing, including appid
and nonce
.
Sample code
- POST/JSON
{
"appid": "1",
"event": "user_action",
"timestamp": 1679553625,
"nonce": "350176",
"signature": "signature",
"user_id": "123456",
"user_name": "user_name",
"os": "PC ",
"action": 1,
"session_id": "930821637828251648",
"login_time": 1679553625,
"relogin": "1",
"logout_time": 1679553625,
"logout_reason": "logout_reason"
}
Return codes
If an HTTP status code 2XX (for example, 200) is returned, the callback succeeded. Otherwise, the callback failed.
Callback retry policy
If the ZEGOCLOUD server does not receive a response, or the HTTP status code received by the ZEGOCLOUD server is not 2xx (such as 200), it will retry with intervals of 2s, 4s, 8s, 16s, and 32s respectively. If the retry still fails after an interval of 32s, it will no longer retry.