RtmTokenBuilder.php 1.2 KB

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace app\common\library\agora\token;
  3. class RtmTokenBuilder
  4. {
  5. const RoleRtmUser = 1;
  6. # appID: The App ID issued to you by Agora. Apply for a new App ID from
  7. # Agora Dashboard if it is missing from your kit. See Get an App ID.
  8. # appCertificate: Certificate of the application that you registered in
  9. # the Agora Dashboard. See Get an App Certificate.
  10. # channelName:Unique channel name for the AgoraRTC session in the string format
  11. # userAccount: The user account.
  12. # role: Role_Rtm_User = 1
  13. # privilegeExpireTs: represented by the number of seconds elapsed since
  14. # 1/1/1970. If, for example, you want to access the
  15. # Agora Service within 10 minutes after the token is
  16. # generated, set expireTimestamp as the current
  17. # timestamp + 600 (seconds)./
  18. public static function buildToken($appID, $appCertificate, $userAccount, $role, $privilegeExpireTs){
  19. $token = AccessToken::init($appID, $appCertificate, $userAccount, "");
  20. $Privileges = AccessToken::Privileges;
  21. $token->addPrivilege($Privileges["kRtmLogin"], $privilegeExpireTs);
  22. return $token->build();
  23. }
  24. }
  25. ?>