|
@@ -11,20 +11,21 @@ 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): bool
|
|
|
+ public static function sendCode(string $phoneNumber, int $len): bool
|
|
|
{
|
|
|
// 生成短信验证码
|
|
|
- $code = random_int(100000, 999999);
|
|
|
+ $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'));
|
|
|
+ cache(config('redis.code_pre') . $phoneNumber, $code, config('redis.expire'));
|
|
|
}
|
|
|
return true;
|
|
|
}
|