PHP Classes

File: sample/ChatTokenBuilder2Sample.php

Recommend this page to a friend!
  Classes of Ujah Chigozie peter   PHP Agora Tokens   sample/ChatTokenBuilder2Sample.php   Download  
File: sample/ChatTokenBuilder2Sample.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Agora Tokens
Generate Agora user authentication tokens
Author: By
Last change:
Date: 7 days ago
Size: 699 bytes
 

Contents

Class file image Download
<?php
use \Peterujah\Agora\Agora;
use \
Peterujah\Agora\User;
use \
Peterujah\Agora\Builders\ChatToken;

$userUuid = "2882341273";
$expireTimeInSeconds = 3600;

$client = new Agora(
   
getenv("AGORA_APP_ID"), // Need to set environment variable AGORA_APP_ID
   
getenv("AGORA_APP_CERTIFICATE"), // Need to set environment variable AGORA_APP_CERTIFICATE
);
$client->setExpiration($expireTimeInSeconds);

$user = (new User($userUuid))->setPrivilegeExpire($expireTimeInSeconds);

$token = ChatToken::buildUserToken($client, $user);
echo
'Chat user token: ' . $token . PHP_EOL;

$token = ChatToken::buildAppToken($client->setExpiration($expireTimeInSeconds));
echo
'Chat app token: ' . $token . PHP_EOL;