0d483c43db4094ed655149957e9a66d399118557.svn-base 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. package io.agora.rtm;
  2. import io.agora.media.AccessToken2;
  3. public class RtmTokenBuilder2 {
  4. /**
  5. * Build the RTM token.
  6. *
  7. * @param appId: The App ID issued to you by Agora. Apply for a new App ID from
  8. * Agora Dashboard if it is missing from your kit. See Get an App ID.
  9. * @param appCertificate: Certificate of the application that you registered in
  10. * the Agora Dashboard. See Get an App Certificate.
  11. * @param userId: The user's account, max length is 64 Bytes.
  12. * @param expire: represented by the number of seconds elapsed since now. If, for example, you want to access the
  13. * Agora Service within 10 minutes after the token is generated, set expireTimestamp as 600(seconds).
  14. * @return The RTM token.
  15. */
  16. public String buildToken(String appId, String appCertificate, String userId, int expire) {
  17. AccessToken2 accessToken = new AccessToken2(appId, appCertificate, expire);
  18. AccessToken2.Service serviceRtm = new AccessToken2.ServiceRtm(userId);
  19. serviceRtm.addPrivilegeRtm(AccessToken2.PrivilegeRtm.PRIVILEGE_JOIN_LOGIN, expire);
  20. accessToken.addService(serviceRtm);
  21. try {
  22. return accessToken.build();
  23. } catch (Exception e) {
  24. e.printStackTrace();
  25. return "";
  26. }
  27. }
  28. }