auth.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * 用户示例
  4. */
  5. require_once __DIR__ . '/../autoload.php';
  6. $config = require_once 'config.php';
  7. use Easemob\Auth;
  8. use Easemob\User;
  9. use Easemob\Agora\ServiceRtc;
  10. // 初始化授权对象,环信 token 初始化
  11. $easemob = $config['easemob'];
  12. $auth = new Auth($easemob['app_key'], $easemob['client_id'], $easemob['client_secret']);
  13. // 设置 REST 域名,沙箱环境使用,不是沙箱环境会自动获取
  14. if (isset($easemob['api_uri']) && $easemob['api_uri']) {
  15. $auth->setApiUri($easemob['api_uri']);
  16. }
  17. /*
  18. // 初始化授权对象,声网 token 初始化
  19. $agora = $config['agora'];
  20. $auth = new Auth($agora['app_key'], $agora['app_id'], $agora['app_certificate'], true, $agora['expire_time']);
  21. $auth->setApiUri('http://a41.easemob.com');
  22. */
  23. echo '<pre>';
  24. /*
  25. // 生成 Easemob userToken
  26. var_dump($auth->getUserToken('user4', 'user4'));
  27. */
  28. /*
  29. // 生成仅含 AgoraChat 权限的 Agora userToken
  30. var_dump($auth->getUserToken('bb46ab60-5c07-11ec-8cc6-b5d98ea414b4', null));
  31. */
  32. /*
  33. // 生成包含 AgoraChat 权限和 AgoraRTC (JOIN_CHANNEL) 权限的 Agora userToken
  34. // grant rtc privileges
  35. $serviceRtc = new ServiceRtc('7d72365eb983485397e3e3f9d460bdda', '2882341273');
  36. $serviceRtc->addPrivilege($serviceRtc::PRIVILEGE_JOIN_CHANNEL, 600);
  37. $configuration = array(
  38. $serviceRtc,
  39. );
  40. var_dump($auth->getUserToken('bb46ab60-5c07-11ec-8cc6-b5d98ea414b4', null, 600, $configuration));
  41. */