1234567891011121314151617181920212223242526272829303132 |
- <?php
- /**
- * Created by PhpStorm
- * User: 林志杰
- * Email: [email protected]
- * Time: 2020/1/11 17:56
- */
- declare(strict_types=1);
- namespace app\common\business;
- use AlibabaCloud\Client\Exception\ClientException;
- use app\common\lib\Num;
- use app\common\lib\sms\AliSms;
- class Sms
- {
- public static function sendCode(string $phoneNumber, int $len): bool
- {
- // 生成短信验证码
- $code = Num::getCode($len);
- $sms = AliSms::sendCode($phoneNumber, $code);
- if ($sms) {
- // 将验证码记录到redis,并设置失效时间
- // 检查php环境是否有redis拓展
- // redis服务
- cache(config('redis.code_pre') . $phoneNumber, $code, config('redis.expire'));
- }
- return true;
- }
- }
|