Sms.php 751 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * User: 林志杰
  5. * Email: [email protected]
  6. * Time: 2020/1/11 17:56
  7. */
  8. declare(strict_types=1);
  9. namespace app\common\business;
  10. use AlibabaCloud\Client\Exception\ClientException;
  11. use app\common\lib\sms\AliSms;
  12. class Sms
  13. {
  14. public static function sendCode(string $phoneNumber): bool
  15. {
  16. // 生成短信验证码
  17. $code = random_int(100000, 999999);
  18. $sms = AliSms::sendCode($phoneNumber, $code);
  19. if ($sms) {
  20. // 将验证码记录到redis,并设置失效时间
  21. // 检查php环境是否有redis拓展
  22. // redis服务
  23. cache(config('redis.code_pre').$phoneNumber,$code,config('redis.expire'));
  24. }
  25. return true;
  26. }
  27. }