diff --git a/backend/config/autoload/mq_user.php b/backend/config/autoload/mq_user.php new file mode 100644 index 0000000..dfadeef --- /dev/null +++ b/backend/config/autoload/mq_user.php @@ -0,0 +1,59 @@ + [ + 'user' => 'user_dataflow_consumer', + 'password' => env('MQ_PASSWORD_CONSUMER', ''), + ], + + // 运维用户 + 'ops' => [ + 'user' => 'user_ops', + 'password' => env('MQ_PASSWORD_OPS', ''), + ], + + // 平台用户(动态从数据库读取) + 'platforms' => (static function (): array { + $platforms = []; + + try { + // 从数据库获取所有启用的平台 + $rows = Db::table('platforms') + ->where('enabled', true) + ->orderBy('id') + ->get(['name']); + + foreach ($rows as $row) { + // 平台名称标准化:空格转下划线,全部小写 + $normalizedName = strtolower(str_replace(' ', '_', $row->name)); + // 环境变量名:大写 + $envKey = 'MQ_PASSWORD_' . strtoupper($normalizedName); + + $platforms[$normalizedName] = [ + 'user' => 'user_' . $normalizedName, + 'password' => env($envKey, ''), + ]; + } + } catch (\Throwable $e) { + // 数据库不可用时返回空数组,避免应用启动失败 + } + + return $platforms; + })(), +];