|
@@ -9,18 +9,24 @@ declare(strict_types=1);
|
|
|
|
|
|
namespace app\common\business;
|
|
namespace app\common\business;
|
|
|
|
|
|
-
|
|
|
|
use AlibabaCloud\Client\Exception\ClientException;
|
|
use AlibabaCloud\Client\Exception\ClientException;
|
|
use app\common\lib\Num;
|
|
use app\common\lib\Num;
|
|
use app\common\lib\sms\AliSms;
|
|
use app\common\lib\sms\AliSms;
|
|
|
|
|
|
class Sms
|
|
class Sms
|
|
{
|
|
{
|
|
- public static function sendCode(string $phoneNumber, int $len): bool
|
|
|
|
|
|
+ public static function sendCode(string $phoneNumber, int $len, string $type = 'ali'): bool
|
|
{
|
|
{
|
|
// 生成短信验证码
|
|
// 生成短信验证码
|
|
$code = Num::getCode($len);
|
|
$code = Num::getCode($len);
|
|
- $sms = AliSms::sendCode($phoneNumber, $code);
|
|
|
|
|
|
+ // 普通模式
|
|
|
|
+ // $sms = AliSms::sendCode($phoneNumber, $code);
|
|
|
|
+
|
|
|
|
+ // 工厂模式1
|
|
|
|
+ $type = ucfirst($type);
|
|
|
|
+ $class = "app\common\lib\sms\{$type}Sms";
|
|
|
|
+ $sms = $class::sendCode($phoneNumber, $code);
|
|
|
|
+
|
|
if ($sms) {
|
|
if ($sms) {
|
|
// 将验证码记录到redis,并设置失效时间
|
|
// 将验证码记录到redis,并设置失效时间
|
|
// 检查php环境是否有redis拓展
|
|
// 检查php环境是否有redis拓展
|