CommonController.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. *
  11. */
  12. namespace App\Controller\Api;
  13. use App\Model\User;
  14. use Hyperf\HttpServer\Annotation\AutoController;
  15. /**
  16. * Class LotteryController
  17. * @package App\Controller\Api
  18. * @AutoController()
  19. */
  20. class CommonController extends BaseController
  21. {
  22. public function verifyCode()
  23. {
  24. $redis = $this->container->get(\Hyperf\Redis\Redis::class);
  25. $config = new \EasySwoole\VerifyCode\Conf();
  26. $code = new \EasySwoole\VerifyCode\VerifyCode($config);
  27. //重写验证码
  28. // $img_code = mt_rand(1000,9999);
  29. // $result = $code->DrawCode($img_code);
  30. //系统验证码
  31. $result = $code->DrawCode();
  32. $img_code = $result->getImageCode();
  33. //写入缓存 用于其他方法验证 并且设置过期时间
  34. $redis->set('codes:'.session_id(), $img_code, 180);
  35. return $result->getImageByte();
  36. }
  37. }