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, ], ];