ChatTokenBuilder2.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Easemob\Agora;
  3. /**
  4. * @ignore
  5. */
  6. class ChatTokenBuilder2
  7. {
  8. /**
  9. * Build the CHAT token.
  10. *
  11. * @param $appId : The App ID issued to you by Agora. Apply for a new App ID from
  12. * Agora Dashboard if it is missing from your kit. See Get an App ID.
  13. * @param $appCertificate : Certificate of the application that you registered in
  14. * the Agora Dashboard. See Get an App Certificate.
  15. * @param $userId : The user's unique id.
  16. * @param $expire : represented by the number of seconds elapsed since now. If, for example, you want to access the
  17. * Agora Service within 10 minutes after the token is generated, set expireTimestamp as 600(seconds).
  18. * @return The CHAT token.
  19. */
  20. public static function buildUserToken($appId, $appCertificate, $userId, $expire)
  21. {
  22. $accessToken = new AccessToken2($appId, $appCertificate, $expire);
  23. $serviceChat = new ServiceChat($userId);
  24. $serviceChat->addPrivilege($serviceChat::PRIVILEGE_USER, $expire);
  25. $accessToken->addService($serviceChat);
  26. return $accessToken->build();
  27. }
  28. /**
  29. * Build the CHAT token.
  30. *
  31. * @param $appId : The App ID issued to you by Agora. Apply for a new App ID from
  32. * Agora Dashboard if it is missing from your kit. See Get an App ID.
  33. * @param $appCertificate : Certificate of the application that you registered in
  34. * the Agora Dashboard. See Get an App Certificate.
  35. * @param $expire : represented by the number of seconds elapsed since now. If, for example, you want to access the
  36. * Agora Service within 10 minutes after the token is generated, set expireTimestamp as 600(seconds).
  37. * @return The CHAT token.
  38. */
  39. public static function buildAppToken($appId, $appCertificate, $expire)
  40. {
  41. $accessToken = new AccessToken2($appId, $appCertificate, $expire);
  42. $serviceChat = new ServiceChat();
  43. $serviceChat->addPrivilege($serviceChat::PRIVILEGE_APP, $expire);
  44. $accessToken->addService($serviceChat);
  45. return $accessToken->build();
  46. }
  47. }