push.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * 推送 API
  4. */
  5. require_once __DIR__ . '/../autoload.php';
  6. $config = require_once 'config.php';
  7. use Easemob\Auth;
  8. use Easemob\User;
  9. use Easemob\Push;
  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. $user = new User($auth);
  19. $push = new Push($auth);
  20. echo '<pre>';
  21. /*
  22. var_dump($user->get('user3'));
  23. // 设置用户推送昵称
  24. var_dump($push->updateUserNickname('user3', 'userthree'));
  25. var_dump($user->get('user3'));
  26. */
  27. /*
  28. // 设置推送消息展示方式
  29. var_dump($user->get('user3'));
  30. var_dump($push->setNotificationDisplayStyle('user3', 0));
  31. var_dump($user->get('user3'));
  32. var_dump($push->setNotificationDisplayStyle('user3'));
  33. var_dump($user->get('user3'));
  34. */
  35. /*
  36. // 设置免打扰
  37. var_dump($user->get('user3'));
  38. // 开启免打扰,设置免打扰时间
  39. var_dump($push->openNotificationNoDisturbing('user3', 10, 19));
  40. var_dump($user->get('user3'));
  41. // 取消免打扰
  42. var_dump($push->closeNotificationNoDisturbing('user3'));
  43. var_dump($user->get('user3'));
  44. */