Selaa lähdekoodia

Merge branch 'master' of http://git.bjzxtw.org.cn:3000/zxt/chat_producer

LiuJ 4 kuukautta sitten
vanhempi
sitoutus
13183c08d1

+ 20 - 0
app/Amqp/Producer/MqProducer.php

@@ -0,0 +1,20 @@
+<?php
+
+declare (strict_types = 1);
+
+namespace App\Amqp\Producer;
+
+use Hyperf\Amqp\Annotation\Producer;
+use Hyperf\Amqp\Message\ProducerMessage;
+
+#[Producer(exchange: 'chatprod', routingKey: 'chatprod')]
+class MqProducer extends ProducerMessage
+{
+    public function __construct($data)
+    {
+//        $this->poolName = 'default';
+        var_dump($data, '生产者数据');
+
+        $this->payload = $data;
+    }
+}

+ 269 - 96
app/JsonRpc/ChatService.php

@@ -10,11 +10,19 @@ use App\Model\ChatTopic;
 use App\Model\ChatTopicsReply;
 
 use App\Model\ChatTopicClass;
+use App\Model\ImGroup;
+use App\Model\ImGroupMember;
 use App\Model\User;
 use App\Tools\PublicData;
 use App\Tools\Result;
+use Hyperf\Context\Context;
 use Hyperf\DbConnection\Db;
 use Hyperf\RpcServer\Annotation\RpcService;
+use Hyperf\Context\ApplicationContext as ContextApplicationContext;
+use Hyperf\Amqp\Producer;
+
+use App\Amqp\Producer\MqProducer;
+use function Hyperf\Support\env;
 
 #[RpcService(name: "ChatService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class ChatService implements ChatServiceInterface
@@ -326,7 +334,7 @@ class ChatService implements ChatServiceInterface
     public function addChatRecords(array $data): array
     {
         Db::beginTransaction();
-        try {;
+        try {
             //添加会话内容
             $ChatRecordsData = [[
                 'msg_type' => $data['msg_type'] ?? 0,
@@ -756,7 +764,8 @@ class ChatService implements ChatServiceInterface
     {
         $groupMember = ChatGroupsMember::where(['group_id' => $data['group_id']])
             ->leftJoin('user as u1', 'chat_groups_members.user_id', '=', 'u1.id')
-            ->select('chat_groups_members.*', 'u1.user_name', 'u1.avatar')
+            ->leftJoin('chat_groups as c1', 'c1.id', '=', 'chat_groups_members.group_id')
+            ->select('chat_groups_members.*', 'u1.user_name', 'u1.avatar', 'c1.group_name as group_name')
             ->orderBy('id', 'desc')
             ->get();
         return Result::success($groupMember);
@@ -769,26 +778,43 @@ class ChatService implements ChatServiceInterface
      */
     public function joinGroup(array $data): array
     {
-        $group = ChatGroups::where(['id' => $data['group_id']])->first();
-        if (empty($group)) {
-            return Result::error("群不存在", 0);
-        }
-        $groupMember = ChatGroupsMember::where(['user_id' => $data['user_id'], 'group_id' => $data['group_id']])->first();
-        if ($groupMember) {
-            return Result::error("已加入群", 0);
+        try {
+            var_dump("========",$data);
+            $group = ImGroup::where(['id' => $data['group_id']])->first();
+            if (empty($group)) {
+                return Result::error("群不存在", 0);
+            }
+            $groupMember = ImGroupMember::where(['user_id' => $data['user_id'], 'group_id' => $data['group_id']])->first();
+            if ($groupMember) {
+                return Result::error("已加入群", 0);
+            }
+//        $info = [
+//            'id' => PublicData::uuid(),
+//            'user_id' => $data['user_id'],
+//            'group_id' => $data['group_id'],
+//        ];
+//        $result = ChatGroupsMember::insert($info);
+            $url = env('IM_URL').'/api/v1/group/invite';
+            $dataIM = [
+                'group_id' => intval($data['group_id']),
+                'ids' => (string)$data['user_id'],
+            ];
+            $options = [
+                'authorization'=>$data['token']
+            ];
+            var_dump("参数:",$url,$dataIM,$options);
+            $result = PublicData::im_post($url,$dataIM,$options);
+            var_dump("结果:",$result);
+            if ($result) {
+                return Result::success($data);
+            } else {
+                return Result::error($data);
+            }
+        }catch (\Exception $ex){
+            var_dump($ex->getMessage());
+            return Result::error([]);
         }
-        $info = [
-            'id' => PublicData::uuid(),
-            'user_id' => $data['user_id'],
-            'group_id' => $data['group_id'],
-        ];
-        $result = ChatGroupsMember::insert($info);
-        var_dump($result, '--------------------');
-        if ($result) {
-            return Result::success($data);
-        } else {
-            return Result::error($data);
-        };
+
     }
     /**
      * 话题 - 列表
@@ -846,36 +872,55 @@ class ChatService implements ChatServiceInterface
         try {
             $data['created_at'] = date('Y-m-d H:i:s');
             $data['updated_at'] = date('Y-m-d H:i:s');
-            $result = ChatTopic::insertGetId($data);
-            var_dump($result, 'tedst111111111111111111111111111111');
-
-            if ($result && $data['is_group'] == 1) {
-                //chat_group
-                $group_id = PublicData::uuid();
-                $groupData = [
-                    'id' => $group_id,
-                    'creator_id' => $data['user_id'],
-                    'group_name' => $data['group_name'] ?? '',
-                    'profile' => $data['profile'] ?? 0,
-                ];
-                $groupResult = ChatGroups::insertGetId($groupData);
-                $groupMemberData = [
-                    'id' => PublicData::uuid(),
-                    'user_id' => $data['user_id'],
-                    'group_id' => $group_id,
-                    'leader' => 2,
-                ];
-                $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
-                //更新result的 group_id
-                $data['group_id'] = $group_id;
-                ChatTopic::where(['id' => $result])->update($data);
-
-                // 查询 Chattopic 数据
-                $chattopic = Chattopic::find($result);
-            } else {
-                $chattopic = Chattopic::find($result);
+            if($data['type_id'] != 10000){
+                $this->sendMessage([
+                    'talk_type'=>300,
+                    'title'=>$data['title'],
+                    'content'=>'提交了审核',
+                    'messageType'=>4,
+                ]);
+                $data['status'] = 1;
+            }else{
+                $data['status'] = 2;
+               
+//                if($data['is_group'] == 1){
+//                    $group_id = PublicData::uuid();
+//                    $groupData = [
+//                        'id' => $group_id,
+//                        'creator_id' => $data['user_id'],
+//                        'group_name' => $data['group_name'] ?? '',
+//                        'profile' => '',
+//                    ];
+//                    $groupResult = ChatGroups::insertGetId($groupData);
+//                    $groupMemberData = [
+//                        'id' => PublicData::uuid(),
+//                        'user_id' => $data['user_id'],
+//                        'group_id' => $group_id,
+//                        'leader' => 2,
+//                    ];
+//                    $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
+                    //更新result的 group_id
+//                    $datas['group_id'] = $group_id;
+//                    ChatTopic::where(['id' => $data['id']])->update($datas);
+    
+                    //插入一条消息
+//                    $chatRecordsData = [
+//                        'user_id' => $data['user_id'],
+//                        'receiver_id' => $group_id,
+//                        'content' => '我创建了一个群' . Date('Y-m-d H:i:s'),
+//                        'msg_type' => 1,
+//                        'is_read' => 0,
+//                        'talk_type' => 2,
+//                        'action' => 'said',
+//                        'group_receiver_id' => $data['user_id'],
+//                    ];
+//                    ChatRecords::insert($chatRecordsData);
+//                }
+                
             }
-
+            unset($data['type_id']);
+            $result = ChatTopic::insertGetId($data);
+            $chattopic = Chattopic::find($result);
             Db::commit();
         } catch (\Exception $e) {
             Db::rollBack();
@@ -891,28 +936,115 @@ class ChatService implements ChatServiceInterface
             $query = ChatTopic::where(['id' => $data['id']]);
             $topdata = $query->first();
 
-            $result = ChatTopic::where(['id' => $data['id']])->update(['status' => $data['status']]);
-            var_dump($result, 'tedst111111111111111');
-            var_dump(date('Y-m-d H:i:s'), 'tedst111111111111111');
-            $creatter = $topdata['user_id'];
-            if ($data['status'] == 2) {
-                //插入一条消息
-                $chatRecordsData = [
-                    'user_id' => $topdata['user_id'],
-                    'receiver_id' => $topdata['group_id'],
-                    'content' => '我创建了一个群' . Date('Y-m-d H:i:s'),
-                    'msg_type' => 1,
-                    'is_read' => 0,
-                    'talk_type' => 2,
-                    'action' => 'said',
-                    'group_receiver_id' => $topdata['user_id'],
-                ];
-                ChatRecords::insert($chatRecordsData);
-            } elseif ($data['status'] == 3) {
-                ChatRecords::where('receiver_id', $topdata['group_id'])->delete();
-                ChatGroupsMember::where('group_id', $topdata['group_id'])
-                    ->where([["user_id", '!=', $creatter]])->delete();
+           $group_id = '';
+            /**************************************new*************************************************************/
+            if($data['status']==2){
+                //同意-需要创建群聊-开始创建
+                if($topdata['is_group']==1){
+                    //是否已经创建过群聊-没有创建才进行创建
+                    if(!$topdata['group_id']){
+                        $url = env('IM_URL').'/api/v1/group/create';
+                        $dataIM = [
+                            'avatar' => '',
+                            'name' => $topdata['group_name'],
+                            'profile'=>'',
+                            'ids' => '',
+                            'create_user_id'=>$topdata['user_id']
+                        ];
+                        $options = [
+                            'authorization'=>$data['token']
+                        ];
+                        $res = PublicData::im_post($url,$dataIM,$options);
+                        if($res['code']==200){
+                            $group_id = $res['data']['group_id'];
+                        }
+                    }
+                }
+                $this->sendMessage([
+                    'talk_type'=>301,
+                    'title'=>$topdata['title'],
+                    'content'=>'审核通过',
+                    'messageType'=>4,
+                    'user_id'=>$topdata['user_id'],
+                ]);
+            }else if($data['status']==3){
+                if($topdata['group_id']){
+                    $url = env('IM_URL').'/api/v1/group/dismiss';
+                    $dataIM = [
+                        'group_id' => intval($topdata['group_id']),
+                        'create_user_id'=>$topdata['user_id']
+                    ];
+                    $options = [
+                        'authorization'=>$data['token']
+                    ];
+                    $res = PublicData::im_post($url,$dataIM,$options);
+                    if($res['code']!=200){
+                        //$group_id = $res['data']['group_id'];
+                        Db::rollBack();
+                        return Result::error($data, '群聊解散失败');
+                    }
+                    $group_id = '';
+                }
+                $this->sendMessage([
+                    'talk_type'=>301,
+                    'title'=>$topdata['title'],
+                    'content'=>'审核拒绝',
+                    'messageType'=>4,
+                    'user_id'=>$topdata['user_id'],
+                ]);
             }
+//====================================================================================
+//            $creatter = $topdata['user_id'];
+//            if ($data['status'] == 2 && $topdata['is_group'] == 1) {
+//                    $group_id = '';
+//                    if(empty($topdata['group_id'])){
+//                        $group_id = PublicData::uuid();
+//                        $groupData = [
+//                            'id' => $group_id,
+//                            'creator_id' => $topdata['user_id'],
+//                            'group_name' => $topdata['group_name'] ?? '',
+//                            'profile' => '',
+//                        ];
+//                        $groupResult = ChatGroups::insertGetId($groupData);
+//                        $groupMemberData = [
+//                            'id' => PublicData::uuid(),
+//                            'user_id' => $topdata['user_id'],
+//                            'group_id' => $group_id,
+//                            'leader' => 2,
+//                        ];
+//                        $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
+//                    }else{
+//                        $group_id = $topdata['group_id'];
+//                    }
+                    
+                    //更新result的 group_id
+//                    $datas['group_id'] = $group_id;
+
+//                    ChatTopic::where(['id' => $data['id']])->update($datas);
+
+                    //插入一条消息
+//                    $chatRecordsData = [
+//                        'user_id' => $topdata['user_id'],
+//                        'receiver_id' => $group_id,
+//                        'content' => '我创建了一个群' . Date('Y-m-d H:i:s'),
+//                        'msg_type' => 1,
+//                        'is_read' => 0,
+//                        'talk_type' => 2,
+//                        'action' => 'said',
+//                        'group_receiver_id' => $topdata['user_id'],
+//                    ];
+//                    ChatRecords::insert($chatRecordsData);
+                
+               
+//            } elseif ($data['status'] == 3) {
+//                if(isset($topdata['group_id']) && !empty($topdata['group_id'])){
+//                    ChatRecords::where('receiver_id', $topdata['group_id'])->delete();
+//                    ChatGroupsMember::where('group_id', $topdata['group_id'])
+//                        ->where([["user_id", '!=', $creatter]])->delete();
+//                }
+//            }
+//====================================================================================
+            $result = ChatTopic::where(['id' => $data['id']])->update(['status' => $data['status'],'group_id'=>$group_id]);
             Db::commit();
             if ($result) {
                 return Result::success($data);
@@ -932,7 +1064,17 @@ class ChatService implements ChatServiceInterface
         if (empty($data['id'])) {
             return Result::error('id不能为空');
         }
-
+        if($data['type_id'] != 10000){
+            $this->sendMessage([
+                'talk_type'=>300,
+                'title'=>$data['title'],
+                'content'=>'提交了审核',
+                'messageType'=>4,
+            ]);
+            $data['status'] = 1;
+        }
+        var_dump($data);
+        unset($data['type_id']);
         $result = ChatTopic::where(['id' => $data['id']])->update($data);
         if ($result) {
             return Result::success($data);
@@ -995,31 +1137,42 @@ class ChatService implements ChatServiceInterface
      */
     public function updateGroupMembers(array $data): array
     {
-        $where = [
-            'group_id' => $data['group_id'],
-        ];
-        $group_id = $data['group_id'];
-        //先删除群成员
-        $result = ChatGroupsMember::where($where)
-            ->where([["user_id", '!=', $data['user_id']]])->delete();
-        $groupMemberData = [];
-        foreach ($data['group_member'] as $value) {
-            $groupMemberData[] = [
-                'id' => PublicData::uuid(),
-                'user_id' => $value,
-                'group_id' => $group_id,
-                'leader' => 0,
+        DB::beginTransaction();
+        try{
+            $where = [
+                'group_id' => $data['group_id'],
             ];
-        }
-        $result = ChatGroupsMember::where($where)->insert($groupMemberData);
-        // 获取群信息
-        $groupInfo = ChatGroups::where(['id' => $group_id])->first();
-
-        if ($result) {
+            $group_id = $data['group_id'];
+            //先删除群成员
+            $result = ChatGroupsMember::where($where)
+                ->where([["user_id", '!=', $data['user_id']]])->delete();
+            $groupMemberData = [];
+            foreach ($data['group_member'] as $value) {
+                $groupMemberData[] = [
+                    'id' => PublicData::uuid(),
+                    'user_id' => $value,
+                    'group_id' => $group_id,
+                    'leader' => 0,
+                ];
+            }
+            $result = ChatGroupsMember::where($where)->insert($groupMemberData);
+            //删除会话踢出群的会话信息
+            // var_dump("data",$data);
+            //字符串转数组,
+            $groupIdList = $data['group_member'];
+            array_push($groupIdList,$data['user_id']);
+            // var_dump("几个",$groupIdList);
+            ChatRecords::whereNotIn('user_id',$groupIdList)->where('group_id',$data['group_id'])->delete();
+            
+            // 获取群信息
+            $groupInfo = ChatGroups::where(['id' => $group_id])->first();
+            DB::commit();
             return Result::success($groupInfo);
-        } else {
-            return Result::error($data);
+        }catch(\Exception $e){
+            DB::rollBack();
+            return Result::error($data, $e->getMessage());
         }
+       
     }
     public function clearGroupRecords(array $data): array
     {
@@ -1175,9 +1328,9 @@ class ChatService implements ChatServiceInterface
      */
     public function getBusinessDistrictList(array $data): array
     {
-        $query = ChatGroupsMember::Join('chat_topics', 'chat_topics.group_id', '=', 'chat_groups_members.group_id')
+        $query = ImGroupMember::Join('chat_topics', 'chat_topics.group_id', '=', 'im_group_member.group_id')
             ->leftJoin('chat_topic_class', 'chat_topic_class.id', '=', 'chat_topics.type')
-            ->where(['chat_groups_members.user_id' => $data['user_id']])
+            ->where(['im_group_member.user_id' => $data['user_id']])
             ->when($data, function ($query) use ($data) {
                 if (!empty($data['type'])) {
                     $query->where(['chat_topics.type' => $data['type']]);
@@ -1208,4 +1361,24 @@ class ChatService implements ChatServiceInterface
         ];
         return  Result::success($result);
     }
+     
+    /**
+     * 发送消息
+     * @param array $messageData
+     * @return void
+     */
+    public function sendMessage($messageData){
+        $msg =[
+          'talk_type'=>$messageData['talk_type'],
+          'title'=>$messageData['title'],
+          'content'=>$messageData['content'],
+          'messageType'=>$messageData['messageType'],
+          'user_id'=>$messageData['user_id']??'',
+          'time'=>microtime(),
+        ];
+        $message = new MqProducer($msg);
+        $producer = ContextApplicationContext::getContainer()->get(Producer::class);
+        $producer->produce($message);
+        
+    }
 }

+ 27 - 0
app/Model/ImGroup.php

@@ -0,0 +1,27 @@
+<?php
+
+declare (strict_types = 1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class ImGroup extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'im_group';
+
+    /**
+     * The attributes that are mass assignable.
+     */
+    protected array $fillable = [];
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}

+ 27 - 0
app/Model/ImGroupMember.php

@@ -0,0 +1,27 @@
+<?php
+
+declare (strict_types = 1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class ImGroupMember extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'im_group_member';
+
+    /**
+     * The attributes that are mass assignable.
+     */
+    protected array $fillable = [];
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}

+ 111 - 53
app/Tools/PublicData.php

@@ -1,54 +1,112 @@
-<?php
-namespace App\Tools;
-use App\Constants\ErrorCode;
-use Hyperf\Snowflake\IdGeneratorInterface;
-use Hyperf\Context\ApplicationContext;
-class PublicData
-{
-    /**
-     * 递归查询
-     * @param $menuItems
-     * @param $parentId
-     * @return array
-     */
-    public static  function buildMenuTree($menuItems, $parentId = 0) {
-        $tree = [];
-        foreach ($menuItems as $item) {
-            if ($item['pid'] == $parentId) {
-                // 找到子菜单
-                $children = self::buildMenuTree($menuItems, $item['id']);
-                // 如果子菜单存在,则添加到当前菜单的children中
-                if ($children) {
-                    $item['children'] = $children;
-                }
-                // 将当前菜单添加到树中
-                $tree[] = $item;
-            }
-        }
-        return $tree;
-    }
-
-    /**
-     * 计算两个时间差的天数
-     * @param $sTime
-     * @param $eTime
-     * @return float
-     */
-    public static function residueDay($sTime,$eTime)
-    {
-        $startTime = strtotime($sTime);
-        $endTime = strtotime($eTime);
-        $diffDays = floor(($endTime - $startTime) / (60 * 60 * 24));
-        return $diffDays;
-    }
-
-    public static function uuid()
-    {
-        var_dump("uuid==========");
-        $container = ApplicationContext::getContainer();
-        $generator = $container->get(IdGeneratorInterface::class);
-        var_dump("uuid==+++++++++++",$generator->generate());
-        return $generator->generate();
-    }
-
+<?php
+namespace App\Tools;
+use App\Constants\ErrorCode;
+use Hyperf\Snowflake\IdGeneratorInterface;
+use Hyperf\Context\ApplicationContext;
+class PublicData
+{
+    /**
+     * 递归查询
+     * @param $menuItems
+     * @param $parentId
+     * @return array
+     */
+    public static  function buildMenuTree($menuItems, $parentId = 0) {
+        $tree = [];
+        foreach ($menuItems as $item) {
+            if ($item['pid'] == $parentId) {
+                // 找到子菜单
+                $children = self::buildMenuTree($menuItems, $item['id']);
+                // 如果子菜单存在,则添加到当前菜单的children中
+                if ($children) {
+                    $item['children'] = $children;
+                }
+                // 将当前菜单添加到树中
+                $tree[] = $item;
+            }
+        }
+        return $tree;
+    }
+
+    /**
+     * 计算两个时间差的天数
+     * @param $sTime
+     * @param $eTime
+     * @return float
+     */
+    public static function residueDay($sTime,$eTime)
+    {
+        $startTime = strtotime($sTime);
+        $endTime = strtotime($eTime);
+        $diffDays = floor(($endTime - $startTime) / (60 * 60 * 24));
+        return $diffDays;
+    }
+
+    /**
+     * 生成雪花算法ID
+     * @return int|false
+     */
+    public static function uuid()
+    {
+        try {
+            $container = ApplicationContext::getContainer();
+            $generator = $container->get(IdGeneratorInterface::class);
+            return $generator->generate();
+        } catch (\Throwable $e) {
+            // 记录错误日志
+            error_log("Snowflake ID generation failed: " . $e->getMessage());
+            return false;
+        }
+    }
+    public static function im_post($url, $data, $options = [])
+    {
+        // 初始化CURL会话
+        $ch = curl_init($url);
+        // JSON 编码(保持中文不转义)
+        $jsonBody = is_string($data) ? $data : json_encode($data, JSON_UNESCAPED_UNICODE);
+        // 基础选项
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_HEADER, false);
+        curl_setopt($ch, CURLOPT_POST, true);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonBody);
+        // HTTPS 兼容
+        if (stripos($url, 'https://') === 0) {
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+        }
+        // Header:Content-Type JSON,Authorization(优先使用传入的)
+        $authorization = $options['authorization'] ?? 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI';
+        $headers = [
+            'Content-Type: application/json',
+            'Accept: application/json',
+            'Authorization: ' . $authorization,
+        ];
+        // 允许外部追加自定义 header(数组,形如 ['X-xxx: yyy'])
+        if (!empty($options['headers']) && is_array($options['headers'])) {
+            $headers = array_merge($headers, $options['headers']);
+        }
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+        // 超时设置(可通过 options 覆盖)
+        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, (int)($options['connect_timeout'] ?? 5));
+        curl_setopt($ch, CURLOPT_TIMEOUT, (int)($options['timeout'] ?? 15));
+        // 追加额外的 CURL 选项(如需)
+        if (!empty($options['curl']) && is_array($options['curl'])) {
+            curl_setopt_array($ch, $options['curl']);
+        }
+        // 执行请求
+        $response = curl_exec($ch);
+        if ($response === false) {
+            $errorMsg = curl_error($ch);
+            curl_close($ch);
+            throw new \Exception('CURL Error: ' . $errorMsg);
+        }
+        // 获取HTTP状态码
+        $httpCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
+        // 关闭会话
+        curl_close($ch);
+        // 返回结果
+        return json_decode($response,true);
+    }
+
+
 }

+ 1 - 1
composer.json

@@ -42,7 +42,7 @@
         "hyperf/socketio-server": "^3.1",
         "hyperf/utils": "^3.1",
         "hyperf/websocket-server": "^3.1",
-        "ramsey/uuid": "^4.7"
+        "ramsey/uuid": "^4.8"
     },
     "require-dev": {
         "friendsofphp/php-cs-fixer": "^3.0",

+ 51 - 49
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "6b9f543cda6751d2d957153d112192e9",
+    "content-hash": "9ca8016d57cfc223d0b85a820c0fc8bb",
     "packages": [
         {
             "name": "brick/math",
@@ -894,27 +894,36 @@
         },
         {
             "name": "hyperf/amqp",
-            "version": "v3.1.28",
+            "version": "v3.1.58",
             "source": {
                 "type": "git",
                 "url": "https://github.com/hyperf/amqp.git",
-                "reference": "c96e294e99e68113ed3e237db8f976308ee42ba7"
+                "reference": "15ed5c2e39d35e1b28be9afad635c3fd9f93841b"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/hyperf/amqp/zipball/c96e294e99e68113ed3e237db8f976308ee42ba7",
-                "reference": "c96e294e99e68113ed3e237db8f976308ee42ba7",
-                "shasum": ""
+                "url": "https://api.github.com/repos/hyperf/amqp/zipball/15ed5c2e39d35e1b28be9afad635c3fd9f93841b",
+                "reference": "15ed5c2e39d35e1b28be9afad635c3fd9f93841b",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
             },
             "require": {
                 "doctrine/instantiator": "^1.2.0",
                 "hyperf/codec": "~3.1.0",
+                "hyperf/collection": "~3.1.0",
+                "hyperf/context": "~3.1.0",
                 "hyperf/contract": "~3.1.0",
+                "hyperf/coordinator": "~3.1.0",
                 "hyperf/coroutine": "~3.1.0",
+                "hyperf/engine": "^2.0",
                 "hyperf/pool": "~3.1.0",
                 "hyperf/process": "~3.1.0",
                 "hyperf/support": "~3.1.0",
-                "hyperf/utils": "~3.1.0",
                 "php": ">=8.1",
                 "php-amqplib/php-amqplib": "^3.5",
                 "psr/container": "^1.0 || ^2.0",
@@ -927,11 +936,11 @@
             },
             "type": "library",
             "extra": {
-                "branch-alias": {
-                    "dev-master": "3.1-dev"
-                },
                 "hyperf": {
                     "config": "Hyperf\\Amqp\\ConfigProvider"
+                },
+                "branch-alias": {
+                    "dev-master": "3.1-dev"
                 }
             },
             "autoload": {
@@ -966,7 +975,7 @@
                     "type": "open_collective"
                 }
             ],
-            "time": "2024-06-24T01:53:39+00:00"
+            "time": "2025-06-23T03:55:31+00:00"
         },
         {
             "name": "hyperf/cache",
@@ -6342,20 +6351,26 @@
         },
         {
             "name": "ramsey/uuid",
-            "version": "4.7.6",
+            "version": "4.8.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/ramsey/uuid.git",
-                "reference": "91039bc1faa45ba123c4328958e620d382ec7088"
+                "reference": "fdf4dd4e2ff1813111bd0ad58d7a1ddbb5b56c28"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/ramsey/uuid/zipball/91039bc1faa45ba123c4328958e620d382ec7088",
-                "reference": "91039bc1faa45ba123c4328958e620d382ec7088",
-                "shasum": ""
+                "url": "https://api.github.com/repos/ramsey/uuid/zipball/fdf4dd4e2ff1813111bd0ad58d7a1ddbb5b56c28",
+                "reference": "fdf4dd4e2ff1813111bd0ad58d7a1ddbb5b56c28",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
             },
             "require": {
-                "brick/math": "^0.8.8 || ^0.9 || ^0.10 || ^0.11 || ^0.12",
+                "brick/math": "^0.8.8 || ^0.9 || ^0.10 || ^0.11 || ^0.12 || ^0.13",
                 "ext-json": "*",
                 "php": "^8.0",
                 "ramsey/collection": "^1.2 || ^2.0"
@@ -6364,26 +6379,23 @@
                 "rhumsaa/uuid": "self.version"
             },
             "require-dev": {
-                "captainhook/captainhook": "^5.10",
+                "captainhook/captainhook": "^5.25",
                 "captainhook/plugin-composer": "^5.3",
-                "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
-                "doctrine/annotations": "^1.8",
-                "ergebnis/composer-normalize": "^2.15",
-                "mockery/mockery": "^1.3",
+                "dealerdirect/phpcodesniffer-composer-installer": "^1.0",
+                "ergebnis/composer-normalize": "^2.47",
+                "mockery/mockery": "^1.6",
                 "paragonie/random-lib": "^2",
-                "php-mock/php-mock": "^2.2",
-                "php-mock/php-mock-mockery": "^1.3",
-                "php-parallel-lint/php-parallel-lint": "^1.1",
-                "phpbench/phpbench": "^1.0",
-                "phpstan/extension-installer": "^1.1",
-                "phpstan/phpstan": "^1.8",
-                "phpstan/phpstan-mockery": "^1.1",
-                "phpstan/phpstan-phpunit": "^1.1",
-                "phpunit/phpunit": "^8.5 || ^9",
-                "ramsey/composer-repl": "^1.4",
-                "slevomat/coding-standard": "^8.4",
-                "squizlabs/php_codesniffer": "^3.5",
-                "vimeo/psalm": "^4.9"
+                "php-mock/php-mock": "^2.6",
+                "php-mock/php-mock-mockery": "^1.5",
+                "php-parallel-lint/php-parallel-lint": "^1.4.0",
+                "phpbench/phpbench": "^1.2.14",
+                "phpstan/extension-installer": "^1.4",
+                "phpstan/phpstan": "^2.1",
+                "phpstan/phpstan-mockery": "^2.0",
+                "phpstan/phpstan-phpunit": "^2.0",
+                "phpunit/phpunit": "^9.6",
+                "slevomat/coding-standard": "^8.18",
+                "squizlabs/php_codesniffer": "^3.13"
             },
             "suggest": {
                 "ext-bcmath": "Enables faster math with arbitrary-precision integers using BCMath.",
@@ -6418,19 +6430,9 @@
             ],
             "support": {
                 "issues": "https://github.com/ramsey/uuid/issues",
-                "source": "https://github.com/ramsey/uuid/tree/4.7.6"
+                "source": "https://github.com/ramsey/uuid/tree/4.8.1"
             },
-            "funding": [
-                {
-                    "url": "https://github.com/ramsey",
-                    "type": "github"
-                },
-                {
-                    "url": "https://tidelift.com/funding/github/packagist/ramsey/uuid",
-                    "type": "tidelift"
-                }
-            ],
-            "time": "2024-04-27T21:32:50+00:00"
+            "time": "2025-06-01T06:28:46+00:00"
         },
         {
             "name": "swow/psr7-plus",
@@ -11192,12 +11194,12 @@
     ],
     "aliases": [],
     "minimum-stability": "dev",
-    "stability-flags": [],
+    "stability-flags": {},
     "prefer-stable": true,
     "prefer-lowest": false,
     "platform": {
         "php": ">=8.1"
     },
-    "platform-dev": [],
+    "platform-dev": {},
     "plugin-api-version": "2.6.0"
 }

+ 42 - 0
config/autoload/amqp.php

@@ -0,0 +1,42 @@
+<?php
+
+declare (strict_types = 1);
+use function Hyperf\Support\env;
+return [
+    'enable' => true,
+    'default' => [
+        'host' => env('AMQP_HOST', '192.168.1.127'),
+        'port' => (int) env('AMQP_PORT', 5672),
+        'user' => env('AMQP_USER', 'guest'),
+        'password' => env('AMQP_PASSWORD', 'guest'),
+        'vhost' => '/',
+        'concurrent' => [
+            'limit' => 1,
+        ],
+        'pool' => [
+            'min_connections' => 1,
+            'max_connections' => 1, // 限制最大连接数为1
+            'connect_timeout' => 1000.0,
+            'wait_timeout' => 3.0,
+            'heartbeat' => -1,
+            
+        ],
+        'params' => [
+            'insist' => false,
+            'login_method' => 'AMQPLAIN',
+            'login_response' => null,
+            'locale' => 'en_US',
+            'connection_timeout' => 3.0,
+            // 尽量保持是 heartbeat 数值的两倍
+            'read_write_timeout' => 6.0,
+            'context' => null,
+            'keepalive' => false,
+            // 尽量保证每个消息的消费时间小于心跳时间
+            'heartbeat' => 3,
+            'close_on_destruct' => false,
+        ],
+    ],
+    'pool2' => [
+
+    ],
+];

+ 1 - 1
config/autoload/cache.php

@@ -11,7 +11,7 @@ declare(strict_types=1);
  */
 return [
     'default' => [
-        'driver' => Hyperf\Cache\Driver\RedisDriver::class,
+        'driver' => Hyperf\Cache\Driver\FileSystemDriver::class,
         'packer' => Hyperf\Codec\Packer\PhpSerializerPacker::class,
         'prefix' => 'c:',
         'skip_cache_results' => [],

+ 2 - 2
config/autoload/redis.php

@@ -13,8 +13,8 @@ use function Hyperf\Support\env;
 
 return [
     'default' => [
-        'host' => env('REDIS_HOST', '192.168.31.193'),
-        'auth' => env('REDIS_AUTH', 123456),
+        'host' => env('REDIS_HOST', '127.0.0.1'),
+        'auth' => env('REDIS_AUTH', null),
         'port' => (int) env('REDIS_PORT', 6379),
         'db' => (int) env('REDIS_DB', 0),
         'pool' => [

+ 18 - 0
config/autoload/snowflake.php

@@ -0,0 +1,18 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * This file is part of Hyperf.
+ *
+ * @link     https://www.hyperf.io
+ * @document https://hyperf.wiki
+ * @contact  group@hyperf.io
+ * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
+ */
+use function Hyperf\Support\env;
+
+return [
+    'begin_second' => Hyperf\Snowflake\MetaGenerator::DEFAULT_BEGIN_SECOND,
+    'datacenter_id' => env('SNOWFLAKE_DATACENTER_ID', 1),
+    'worker_id' => env('SNOWFLAKE_WORKER_ID', 1),
+];