all(); $CallbackCommand = $params["CallbackCommand"] ?? ''; switch ($CallbackCommand) { case 'Group.CallbackAfterGroupDestroyed':// 群组解散之后回调 LogUtil::info('群组解散之后回调',self::LOG_MODULE,__FUNCTION__); $room_no = $params["GroupId"]; $model = new LiveRoomModel(); $room = $model->getDetail(params: ['room_no'=>$room_no]); if (!$room){ return AppResult::im_success('直播间不存在或已下播'); } $model = new LiveRoomModel(); if (!$model->closeRoom($room['id'])){ return AppResult::im_error($model->getMessage() ?? '操作失败'); } break; case 'Group.CallbackAfterMemberExit': // 成员离开 LogUtil::info('群成员离开之后回调',self::LOG_MODULE,__FUNCTION__); $room_no = $params["GroupId"]; $members = $params["ExitMemberList"]; $model = new LiveRoomModel(); $model->setIsStatusSearchValue(0); $room = $model->getDetail(params: ['room_no'=>$room_no]); if (!$room){ LogUtil::info('直播间不存在或已下播',self::LOG_MODULE,__FUNCTION__); } if($members) { foreach($members as $k => $v) { $gz_user_id = im_un_prefix($v["Member_Account"]); // 从原房间内移除此用户 RedisUtil::getInstance(RedisKeyEnum::ROOM_USER_LIST,$room_no)->zRem($gz_user_id); // 扣除在线用户在房间情况 RedisUtil::getInstance(RedisKeyEnum::ROOM_USER_IN)->hDel((string)$gz_user_id); if ($room){ $this->service->liveRoomDataPush(['session' => $room['session'], 'ccu' => -1]); if ($room['user_id'] == $gz_user_id){ // 如果是主播,则关闭直播间 $model = new LiveRoomModel(); $model->closeRoom($room['id']); // 腾讯直播解散群组 $im = new TencentIm(); $im->destroy_group($room_no); } } } } break; case 'Group.CallbackOnMemberStateChange': LogUtil::info('直播群成员在线状态回调',self::LOG_MODULE,__FUNCTION__); $type = $params['EventType']; $room_no = $params["GroupId"]; $members = $params["MemberList"]; $model = new LiveRoomModel(); $room = $model->where('room_no',$room_no)->whereIn('status',[1,2])->find(); if (!$room){ LogUtil::info('直播间不存在或已下播',self::LOG_MODULE,__FUNCTION__); } if ($type == 'Offline'){ LogUtil::info('直播群成员离线',self::LOG_MODULE,__FUNCTION__); if($members) { foreach($members as $k => $v) { $gz_user_id = im_un_prefix($v["Member_Account"]); // 从原房间内移除此用户 RedisUtil::getInstance(RedisKeyEnum::ROOM_USER_LIST,$room_no)->zrem($gz_user_id); // 扣除在线用户在房间情况 RedisUtil::getInstance(RedisKeyEnum::ROOM_USER_IN)->hDel($gz_user_id); if ($room){ $this->service->liveRoomDataPush(['session' => $room['session'], 'ccu' => -1]); if ($room['user_id'] == $gz_user_id){ // 如果是主播,则关闭直播间 $model = new LiveRoomModel(); $model->closeRoom($room['id']); // 腾讯直播解散群组 $im = new TencentIm(); $im->destroy_group($room_no); } } } } } break; } // 处理结果通知 return AppResult::im_success('处理成功'); } }