|
|
@@ -31,12 +31,10 @@ class MessageController extends AbstractController
|
|
|
// 获取 Swoole WebSocket Server 实例
|
|
|
$server = \Hyperf\Context\ApplicationContext::getContainer()->get(\Swoole\Server::class);
|
|
|
$redisClient = new RedisService();
|
|
|
- var_dump($adminList, '-------------&&&&&&&&&&&&&&&&&&&&&&----');
|
|
|
if ($adminList && isset($adminList['data'])) {
|
|
|
foreach ($adminList['data'] as $admin) {
|
|
|
$fd = $redisClient->findFd((int)$admin['id']);
|
|
|
if ($fd && $server->isEstablished((int)$fd)) {
|
|
|
- var_dump($fd, '-------------&&&&&&&&&&&&&&&&&&&&&&----');
|
|
|
$server->push((int)$fd, json_encode($data));
|
|
|
}
|
|
|
}
|
|
|
@@ -67,8 +65,6 @@ class MessageController extends AbstractController
|
|
|
$server = \Hyperf\Context\ApplicationContext::getContainer()->get(\Swoole\Server::class);
|
|
|
$redisClient = new RedisService();
|
|
|
$data['user_id'] = json_decode($data['user_id'],true);
|
|
|
- // var_dump($data['user_id'],"====================%%%%%%%%%%%====");
|
|
|
-
|
|
|
if(is_array($data['user_id'])){
|
|
|
foreach($data['user_id'] as $user_id){
|
|
|
$fd = $redisClient->findFd((int)$user_id);
|
|
|
@@ -83,5 +79,58 @@ class MessageController extends AbstractController
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 单聊
|
|
|
+ */
|
|
|
+ public function sendSingleChat($data){
|
|
|
+ $userInfo = $this->userServiceClient->getImContact([
|
|
|
+ 'user_id' => $data['receiver_id'],
|
|
|
+ 'friend_id' => $data['user_id'],
|
|
|
+ ]);
|
|
|
+// var_dump("用户信息:",$userInfo);
|
|
|
+ $server = \Hyperf\Context\ApplicationContext::getContainer()->get(\Swoole\Server::class);
|
|
|
+ $redisClient = new RedisService();
|
|
|
+ $message = [
|
|
|
+ 'talk_type' => 1,
|
|
|
+ 'title' => $userInfo['data']['remark'],
|
|
|
+ 'content' => $data['content'],
|
|
|
+ 'messageType' => 1,
|
|
|
+ 'receiver_id'=> $data['user_id'],
|
|
|
+// 'user_id' => $user['user_id'] ?? '',
|
|
|
+ 'time' => microtime(),
|
|
|
+ ];
|
|
|
+ $fd = $redisClient->findFd((int)$data['receiver_id']);
|
|
|
+ if ($fd && $server->isEstablished((int)$fd)) {
|
|
|
+ $server->push((int)$fd, json_encode($message));
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 群聊
|
|
|
+ */
|
|
|
+ public function sendGroupChat($data){
|
|
|
+ $userList = $this->userServiceClient->getImGroupMember(['user_id' => $data['user_id'],'group_id' => $data['receiver_id']]);
|
|
|
+ // 获取 Swoole WebSocket Server 实例
|
|
|
+ $server = \Hyperf\Context\ApplicationContext::getContainer()->get(\Swoole\Server::class);
|
|
|
+ $redisClient = new RedisService();
|
|
|
+ if($userList && isset($userList['data'])){
|
|
|
+ foreach($userList['data'] as $user){
|
|
|
+ $message = [
|
|
|
+ 'talk_type' => 2,
|
|
|
+ 'title' => $user['group_name'],
|
|
|
+ 'content' => $data['content'],
|
|
|
+ 'messageType' => 1,
|
|
|
+ 'receiver_id'=> $data['receiver_id'],
|
|
|
+// 'user_id' => $user['user_id'] ?? '',
|
|
|
+ 'time' => microtime(),
|
|
|
+ ];
|
|
|
+ $fd = $redisClient->findFd((int)$user['user_id']);
|
|
|
+ if ($fd && $server->isEstablished((int)$fd)) {
|
|
|
+ $server->push((int)$fd, json_encode($message));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|