You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 satır
1.8KB

  1. <?php
  2. namespace App\Console\Commands\QRCode;
  3. use App\Console\Commands\BaseCommand;
  4. use App\Logics\QRService\QRCryptoLogic;
  5. use Str;
  6. class サービス券復号化 extends BaseCommand
  7. {
  8. const COMMAND = "qrcode:decrypto {input}";
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = self::COMMAND;
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'QRサービス券(取得)を復号化する。';
  21. static public function getCommand()
  22. {
  23. return self::COMMAND;
  24. }
  25. /**
  26. * Create a new command instance.
  27. *
  28. * @return void
  29. */
  30. public function __construct()
  31. {
  32. parent::__construct();
  33. }
  34. /**
  35. * Execute the console command.
  36. *
  37. * @return int
  38. */
  39. public function service(): int
  40. {
  41. $input = $this->argument("input");
  42. if (!$input) {
  43. $this->outputError("入力エラー");
  44. return self::RESULTCODE_FAILED;
  45. }
  46. $origin = Str::substr($input, 5);
  47. $result = QRCryptoLogic::decrypt($origin);
  48. $this->outputInfo(sprintf("復号化:[%s]->[%s]", $origin, $result));
  49. $this->qrParse($result);
  50. return self::RESULTCODE_SUCCESS;
  51. }
  52. private function qrParse(string $input)
  53. {
  54. $発行端末 = Str::substr($input, 0, 2);
  55. $発行日 = Str::substr($input, 2, 8);
  56. $発行連番 = Str::substr($input, 10, 6);
  57. $店舗番号 = Str::substr($input, 16, 2);
  58. $券コード = Str::substr($input, 18, 2);
  59. $this->outputInfo(sprintf("発行端末[%s] 発行日[%s] 発行連番[%s] 店舗番号[%s] 券コード[%s]", $発行端末, $発行日, $発行連番, $店舗番号, $券コード));
  60. }
  61. }