block.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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\Block;
  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. $block = new Block($auth);
  19. $user = new User($auth);
  20. echo '<pre>';
  21. /*
  22. // 获取用户黑名单
  23. var_dump($block->getUsersBlockedFromSendMsgToUser('user3'));
  24. */
  25. /*
  26. // 添加用户黑名单
  27. var_dump($block->getUsersBlockedFromSendMsgToUser('user1'));
  28. var_dump($block->blockUserSendMsgToUser('user1', array('user2', 'user3')));
  29. var_dump($block->getUsersBlockedFromSendMsgToUser('user1'));
  30. */
  31. /*
  32. var_dump($block->getUsersBlockedFromSendMsgToUser('user1'));
  33. // 移除用户黑名单
  34. var_dump($block->unblockUserSendMsgToUser('user1', 'user3'));
  35. var_dump($block->getUsersBlockedFromSendMsgToUser('user1'));
  36. */
  37. /*
  38. var_dump($user->get('user1'));
  39. // 用户账号禁用
  40. var_dump($block->blockUserLogin('user1'));
  41. var_dump($user->get('user1'));
  42. // 用户账号解禁
  43. var_dump($block->unblockUserLogin('user1'));
  44. var_dump($user->get('user1'));
  45. */
  46. /*
  47. // 设置用户全局禁言
  48. var_dump($block->blockUserSendMsg('user3'));
  49. */
  50. /*
  51. // 取消用户全局禁言
  52. var_dump($block->unblockUserSendMsg('user3'));
  53. */
  54. /*
  55. // 查询单个帐号全局禁言
  56. var_dump($block->getUserBlocked('user3'));
  57. */
  58. /*
  59. // 查询APPKEY的用户禁言
  60. var_dump($block->getAppBlocked());
  61. */
  62. // Group
  63. /*
  64. // 查询群组黑名单
  65. var_dump($block->getUsersBlockedJoinGroup('177627064238081'));
  66. */
  67. /*
  68. var_dump($block->getUsersBlockedJoinGroup('177627064238081'));
  69. // 添加单个用户至群组黑名单
  70. var_dump($block->blockUserJoinGroup('177627064238081', 'user4'));
  71. var_dump($block->getUsersBlockedJoinGroup('177627064238081'));
  72. */
  73. /*
  74. var_dump($block->getUsersBlockedJoinGroup('177627064238081'));
  75. // 批量添加用户至群组黑名单
  76. var_dump($block->blockUsersJoinGroup('177627064238081', array('user1', 'user3')));
  77. var_dump($block->getUsersBlockedJoinGroup('177627064238081'));
  78. */
  79. /*
  80. var_dump($block->getUsersBlockedJoinGroup('177627064238081'));
  81. // 从群组黑名单移除单个用户
  82. var_dump($block->unblockUserJoinGroup('177627064238081', 'user4'));
  83. var_dump($block->getUsersBlockedJoinGroup('177627064238081'));
  84. */
  85. /*
  86. // 批量从群组黑名单移除用户
  87. var_dump($block->getUsersBlockedJoinGroup('177627064238081'));
  88. var_dump($block->unblockUsersJoinGroup('177627064238081', array('user1', 'user3')));
  89. var_dump($block->getUsersBlockedJoinGroup('177627064238081'));
  90. */
  91. /*
  92. var_dump($block->getUsersBlockedSendMsgToGroup('177627064238081'));
  93. // 添加群禁言
  94. var_dump($block->blockUserSendMsgToGroup('177627064238081', array('user4')));
  95. var_dump($block->getUsersBlockedSendMsgToGroup('177627064238081'));
  96. var_dump($block->blockUserSendMsgToGroup('177627064238081', array('user5', 'user6')));
  97. var_dump($block->getUsersBlockedSendMsgToGroup('177627064238081'));
  98. */
  99. /*
  100. var_dump($block->getUsersBlockedSendMsgToGroup('177627064238081'));
  101. // 移除群禁言
  102. var_dump($block->unblockUserSendMsgToGroup('177627064238081', array('user4')));
  103. var_dump($block->getUsersBlockedSendMsgToGroup('177627064238081'));
  104. var_dump($block->unblockUserSendMsgToGroup('177627064238081', array('user5', 'user6')));
  105. var_dump($block->getUsersBlockedSendMsgToGroup('177627064238081'));
  106. */
  107. /*
  108. // 获取群禁言列表
  109. var_dump($block->getUsersBlockedSendMsgToGroup('177627064238081'));
  110. */
  111. /*
  112. // 禁言群组全体成员
  113. var_dump($block->blockAllUserSendMsgToGroup('177627064238081'));
  114. */
  115. /*
  116. // 解除群组全员禁言
  117. var_dump($block->unblockAllUserSendMsgToGroup('177627064238081'));
  118. */
  119. // Room
  120. /*
  121. // 查询聊天室黑名单
  122. var_dump($block->getUsersBlockedJoinRoom('177630845403137'));
  123. */
  124. /*
  125. var_dump($block->getUsersBlockedJoinRoom('177630845403137'));
  126. // 添加单个用户至聊天室黑名单
  127. var_dump($block->blockUserJoinRoom('177630845403137', 'user11'));
  128. var_dump($block->getUsersBlockedJoinRoom('177630845403137'));
  129. */
  130. /*
  131. var_dump($block->getUsersBlockedJoinRoom('177630845403137'));
  132. // 批量添加用户至聊天室黑名单
  133. var_dump($block->blockUsersJoinRoom('177630845403137', array('user12', 'user13')));
  134. var_dump($block->getUsersBlockedJoinRoom('177630845403137'));
  135. */
  136. /*
  137. var_dump($block->getUsersBlockedJoinRoom('177630845403137'));
  138. // 从聊天室黑名单移除单个用户
  139. var_dump($block->unblockUserJoinRoom('177630845403137', 'user11'));
  140. var_dump($block->getUsersBlockedJoinRoom('177630845403137'));
  141. */
  142. /*
  143. // 批量从聊天室黑名单移除用户
  144. var_dump($block->getUsersBlockedJoinRoom('177630845403137'));
  145. var_dump($block->unblockUsersJoinRoom('177630845403137', array('user12', 'user13')));
  146. var_dump($block->getUsersBlockedJoinRoom('177630845403137'));
  147. */
  148. /*
  149. var_dump($block->getUsersBlockedSendMsgToRoom('177630783537155'));
  150. // 添加聊天室禁言
  151. var_dump($block->blockUserSendMsgToRoom('177630783537155', array('user4')));
  152. var_dump($block->getUsersBlockedSendMsgToRoom('177630783537155'));
  153. var_dump($block->blockUserSendMsgToRoom('177630783537155', array('user2', 'user3')));
  154. var_dump($block->getUsersBlockedSendMsgToRoom('177630783537155'));
  155. */
  156. /*
  157. var_dump($block->getUsersBlockedSendMsgToRoom('177630783537155'));
  158. // 移除聊天室禁言
  159. var_dump($block->unblockUserSendMsgToRoom('177630783537155', array('user4')));
  160. var_dump($block->getUsersBlockedSendMsgToRoom('177630783537155'));
  161. var_dump($block->unblockUserSendMsgToRoom('177630783537155', array('user2', 'user3')));
  162. var_dump($block->getUsersBlockedSendMsgToRoom('177630783537155'));
  163. */
  164. /*
  165. // 获取聊天室禁言列表
  166. var_dump($block->getUsersBlockedSendMsgToRoom('177630783537155'));
  167. */
  168. /*
  169. // 禁言聊天室全体成员
  170. var_dump($block->blockAllUserSendMsgToRoom('177630783537155'));
  171. */
  172. /*
  173. // 解除聊天室全员禁言
  174. var_dump($block->unblockAllUserSendMsgToRoom('177630783537155'));
  175. */