<?php
/**
 * Created by PhpStorm
 * User: 林志杰
 * Email: 598287049@qq.com
 * 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;
    }
}