VerificationCodeMessage.php 619 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\utils;
  8. class VerificationCodeMessage
  9. {
  10. public $code;
  11. public function getCode()
  12. {
  13. if (!$this->code) {
  14. $this->code = $this->generate();
  15. }
  16. return $this->code;
  17. }
  18. protected function generate($length = 6)
  19. {
  20. return mt_rand(pow(10, ($length - 1)), pow(10, $length) - 1);
  21. }
  22. public function validate($input)
  23. {
  24. return $this->code === $input;
  25. }
  26. }