logo
In-app Chat
Powered Byspreading
On this page

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

ParameterTypeDescription
appidStringThe unique ID of an app.
eventStringThe callback event. The return value is user_action.
timestampIntegerThe Unix timestamp of the callback server. Unit: seconds.
nonceStringA random number.
signatureStringThe verification string. For more information, see Authenticating server-to-server callbacks.
user_idStringThe user ID.
user_nameSTRINGThe username.
osStringThe description of the operating system, which is synchronized upon user login. Valid values:
  • PC
  • IOS_PHONE
  • ANDROID
  • MAC
  • LINUX
  • WEB
  • MINIPROGRAM (mini program)
  • ANDROID_TV
actionInteger

Status. Valid values:

  • 0: online, which indicates that the user app successfully connects to the ZIM server by calling the login operation.
  • 1: logout, which indicates that the user app successfully disconnects from the ZIM server by calling the logout operation.
  • 2: offline.
session_idStringThe unique ID of a session. If a user is online on multiple terminals, multiple sessions exist and are identified by ID.
login_timeIntegerThe Unix timestamp of login. Unit: seconds.
reloginStringThe identifier of re-login. Valid values:
  • 0: first login.
  • 1: re-login.
logout_timeIntegerThe Unix timestamp of logout. Unit: seconds.
logout_reasonStringThe reason for logout.
offline_timeIntegerThe Unix timestamp of going offline. Unit: seconds.
Note

We recommend that you convert some parameters into integers for logic processing, including appid and nonce.

Sample code

  • POST/JSON
Untitled
{
    "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"
}
1
Copied!

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.

Previous

Callback configuration instructions

Next

Call invitation sent