fix: send verification SMS synchronously

This commit is contained in:
danaisuiyuan
2026-05-20 20:44:52 +08:00
parent f4e8dab88a
commit ab65147b82
2 changed files with 8 additions and 4 deletions

View File

@@ -35,11 +35,13 @@ class SmsSendServices extends BaseServices
$services = app()->make(ServeServices::class); $services = app()->make(ServeServices::class);
$type = $this->smsType[sys_config('sms_type', 0)]; $type = $this->smsType[sys_config('sms_type', 0)];
$templateMark = strtolower($template);
//获取短信ID //获取短信ID
$templateId = CacheService::handler('TEMPLATE')->remember('NOTICE_SMS_' . $type . '_' . $template, function () use ($services, $template) { $templateId = CacheService::handler('TEMPLATE')->remember('NOTICE_SMS_' . $type . '_' . $templateMark, function () use ($template, $templateMark) {
/** @var SystemNotificationServices $notifyServices */ /** @var SystemNotificationServices $notifyServices */
$notifyServices = app()->make(SystemNotificationServices::class); $notifyServices = app()->make(SystemNotificationServices::class);
return $notifyServices->value(['mark' => $template], 'sms_id') ?? 0; return $notifyServices->value(['mark' => $template], 'sms_id')
?: ($templateMark === $template ? 0 : ($notifyServices->value(['mark' => $templateMark], 'sms_id') ?? 0));
}); });
//获取发送短信驱动类型 //获取发送短信驱动类型
$smsMake = $services->sms($type); $smsMake = $services->sms($type);

View File

@@ -7,9 +7,9 @@ declare (strict_types=1);
namespace app\services\user; namespace app\services\user;
use app\jobs\notice\SmsJob;
use app\services\BaseServices; use app\services\BaseServices;
use app\dao\user\UserDao; use app\dao\user\UserDao;
use app\services\message\sms\SmsSendServices;
use app\services\message\sms\SmsRecordServices; use app\services\message\sms\SmsRecordServices;
use app\services\wechat\WechatUserServices; use app\services\wechat\WechatUserServices;
use crmeb\exceptions\ApiException; use crmeb\exceptions\ApiException;
@@ -165,7 +165,9 @@ class LoginServices extends BaseServices
$code = rand(100000, 999999); $code = rand(100000, 999999);
$data['code'] = $code; $data['code'] = $code;
$data['time'] = $time; $data['time'] = $time;
$res = SmsJob::dispatch([$phone, $data, 'VERIFICATION_CODE_TIME']); /** @var SmsSendServices $smsServices */
$smsServices = app()->make(SmsSendServices::class);
$res = $smsServices->send(true, $phone, $data, 'VERIFICATION_CODE_TIME');
if (!$res) if (!$res)
throw new ValidateException('短信平台验证码发送失败'); throw new ValidateException('短信平台验证码发送失败');
return $code; return $code;