Sms.php 781 B

1234567891011121314151617181920212223242526272829303132
  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\Num;
  12. use app\common\lib\sms\AliSms;
  13. class Sms
  14. {
  15. public static function sendCode(string $phoneNumber, int $len): bool
  16. {
  17. // 生成短信验证码
  18. $code = Num::getCode($len);
  19. $sms = AliSms::sendCode($phoneNumber, $code);
  20. if ($sms) {
  21. // 将验证码记录到redis,并设置失效时间
  22. // 检查php环境是否有redis拓展
  23. // redis服务
  24. cache(config('redis.code_pre') . $phoneNumber, $code, config('redis.expire'));
  25. }
  26. return true;
  27. }
  28. }