123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- <?php
- namespace app\common\library;
- use Easemob\Auth;
- use Easemob\Group;
- use Easemob\User;
- use Easemob\Room;
- class Easemob {
- protected $auth;
- protected $room;
- protected $user;
- protected $group;
- public function __construct() {
-
- $easemob_config = config('easemob');
- $appKey = $easemob_config['appkey'];
- $clientIdOrAppID = $easemob_config['client_id'];
- $clientSecretOrAppCertificate = $easemob_config['client_secret'];
- $this->auth = new Auth($appKey,$clientIdOrAppID,$clientSecretOrAppCertificate);
- $this->room = new Room($this->auth);
- $this->user = new User($this->auth);
- $this->group = new Group($this->auth);
- }
-
-
-
- public function user_create($user_id){
- $user_id = '' . $user_id . '';
- $register_data = ['username'=>$user_id,'password'=>123456];
- $rs = $this->user->create($register_data);
-
- if(isset($rs['code'])){
- return false;
- }
- if(isset($rs['uuid'])){
- return true;
- }
-
- return false;
- }
-
-
- public function group_createPublicGroup($user_id,$guild_name,$guild_desc,$maxusers){
- $user_id = ''.$user_id.'';
- $rs = $this->group->createPublicGroup($user_id,$guild_name,$guild_desc,[],$maxusers);
- return $rs;
- }
-
-
- public function group_addGroupMember($groupId,$user_id){
- $rs = $this->group->addGroupMember($groupId,$user_id);
- return $rs;
- }
-
- public function group_removeGroupMember($groupId,$user_id)
- {
- $rs = $this->group->removeGroupMember($groupId,$user_id);
- return $rs;
- }
-
- public function group_addGroupAdmin($groupId,$user_id){
- $rs = $this->group->addGroupAdmin($groupId,$user_id);
- return $rs;
- }
-
- public function group_removeGroupAdmin($groupId,$user_id){
- $rs = $this->group->removeGroupAdmin($groupId,$user_id);
- return $rs;
- }
-
-
-
-
- public function room_listAllRoomsUserJoined($user_id){
- $user_id = '' . $user_id . '';
- $rs = $this->room->listAllRoomsUserJoined($user_id);
- return $rs;
- }
-
-
- public function room_getRoom($roomId){
- $rs = $this->room->getRoom($roomId);
- return $rs;
- }
-
-
- public function room_createRoom($name,$info,$user_id){
- $user_id = '' . $user_id . '';
- $room_id = $this->room->createRoom($name,$info,$user_id,[$user_id],10000);
- return $room_id;
- }
-
-
- public function room_updateRoom($room_id,$name,$description,$maxusers = false){
- $data = [
- 'room_id' => $room_id,
- 'name' => $name,
- 'description'=>$description,
- ];
- if($maxusers !== false){
- $data['maxusers'] = $maxusers;
- }
- $rs = $this->room->updateRoom($data);
- return $rs;
- }
-
-
-
-
-
-
- public function room_getRoomCustomAttribute($room_id,$keys){
- $rs = $this->room->getRoomCustomAttribute($room_id,$keys);
- return $rs;
- }
-
-
-
-
- public function room_setRoomCustomAttributeForced($room_id,$owner_id,$matedata){
- $owner_id = ''.$owner_id.'';
-
- $rs = $this->room->addRoomMember($room_id,$owner_id);
-
-
- $rs = $this->room->setRoomCustomAttributeForced($room_id,$owner_id,$matedata);
- return $rs;
- }
-
-
- public function room_deleteRoomCustomAttributeForced($room_id,$owner_id,$keys){
- $owner_id = ''.$owner_id.'';
- $rs = $this->room->deleteRoomCustomAttributeForced($room_id,$owner_id,$keys);
- return $rs;
- }
-
-
- public function room_listRoomMembers($roomId, $pageSize = 10, $pageNum = 1){
- $rs = $this->room->listRoomMembers($roomId, $pageSize, $pageNum);
- return $rs;
- }
-
-
-
-
- public function room_removeRoomMembers($roomId, $usernames){
- $rs = $this->room->removeRoomMembers($roomId, $usernames);
- return $rs;
- }
-
-
- public function room_promoteRoomAdmin($roomId, $newadmin){
- $newadmin = ''.$newadmin.'';
- $rs = $this->room->promoteRoomAdmin($roomId, $newadmin);
-
- return $rs;
- }
-
- public function room_demoteRoomAdmin($roomId, $oldadmin){
- $oldadmin = ''.$oldadmin.'';
- $rs = $this->room->demoteRoomAdmin($roomId, $oldadmin);
-
- return $rs;
- }
-
-
-
- }
|