ShopwwiAuthCommand.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\command;
  3. use Shopwwi\WebmanAuth\Facade\Str;
  4. use Symfony\Component\Console\Command\Command;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Input\InputOption;
  7. use Symfony\Component\Console\Input\InputArgument;
  8. use Symfony\Component\Console\Output\OutputInterface;
  9. class ShopwwiAuthCommand extends Command
  10. {
  11. protected static $defaultName = 'shopwwi:auth';
  12. protected static $defaultDescription = 'shopwwi auth';
  13. /**
  14. * @return void
  15. */
  16. protected function configure()
  17. {
  18. $this->addArgument('name', InputArgument::OPTIONAL, 'Name description');
  19. }
  20. /**
  21. * @param InputInterface $input
  22. * @param OutputInterface $output
  23. * @return int
  24. */
  25. protected function execute(InputInterface $input, OutputInterface $output)
  26. {
  27. $name = $input->getArgument('name');
  28. $output->writeln('生成jwtKey 开始');
  29. $key = Str::random(64);
  30. file_put_contents(base_path()."/config/plugin/shopwwi/auth/app.php", str_replace(
  31. "'access_secret_key' => '".config('plugin.shopwwi.auth.app.jwt.access_secret_key')."'",
  32. "'access_secret_key' => '".$key."'",
  33. file_get_contents(base_path()."/config/plugin/shopwwi/auth/app.php")
  34. ));
  35. file_put_contents(base_path()."/config/plugin/shopwwi/auth/app.php", str_replace(
  36. "'refresh_secret_key' => '".config('plugin.shopwwi.auth.app.jwt.refresh_secret_key')."'",
  37. "'refresh_secret_key' => '".$key."'",
  38. file_get_contents(base_path()."/config/plugin/shopwwi/auth/app.php")
  39. ));
  40. $output->writeln('生成jwtKey 结束'.$key);
  41. return self::SUCCESS;
  42. }
  43. }