From 508abf7aef8c91f8092c69ffd64f9c8a4d04566c Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Wed, 17 Sep 2025 17:48:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0open=20api=20client?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command/OpenApiMgr/AddClient.php | 42 ++++++++++++++++++++++++++++ config/console.php | 3 ++ 2 files changed, 45 insertions(+) create mode 100644 app/command/OpenApiMgr/AddClient.php diff --git a/app/command/OpenApiMgr/AddClient.php b/app/command/OpenApiMgr/AddClient.php new file mode 100644 index 00000000..23605312 --- /dev/null +++ b/app/command/OpenApiMgr/AddClient.php @@ -0,0 +1,42 @@ +setName('OpenApiMgr:AddClient') + ->addArgument('salt', Argument::OPTIONAL, "开放API的client_secret密钥的盐值") + ->setDescription('开放API的client管理'); + } + + protected function execute(Input $input, Output $output) + { + $salt = $input->getArgument('salt'); + $salt = empty($salt) ? null : trim($salt); + + // 指令输出 + $oauth = new OAuthStorage($salt); + + $client_id = random_str(13, 'all', 0); + $client_secret = random_str(32, 'all', 0); + + $ok = $oauth->addClient($client_id, $client_secret, null); + if (!$ok) { + $output->writeln("添加失败"); + return; + } + + $output->writeln("添加成功:\nClientID: {$client_id}\nClientSecret: {$client_secret}\n"); + } +} diff --git a/config/console.php b/config/console.php index 22916796..f67b365f 100644 --- a/config/console.php +++ b/config/console.php @@ -2,9 +2,12 @@ // +---------------------------------------------------------------------- // | 控制台配置 // +---------------------------------------------------------------------- + + return [ // 指令定义 'commands' => [ 'data:migrate' => \app\command\DataMigration::class, + 'openapi:addclient' => \app\command\OpenApiMgr\AddClient::class, ], ];