You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB
PHTML

2 years ago
<?php
declare(strict_types=1);
namespace App\Job;
use App\Exception\BusinessException;
use App\Service\SmsService;
class SmsJob extends Job
{
public $params;
protected $queueName = 'sms';
public function __construct($params)
{
$this->params = $params;
}
public function handle()
{
$mobile = $this->params['mobile'] ?? null;
$options = $this->params['options'] ?? [];
$type = $options['type'] ?? '';
if (!$mobile) {
throw new BusinessException('缺少手机号');
}
if (!$type) {
throw new BusinessException('缺少类型');
}
/**
* @var SmsService $smsService
*/
$smsService = make(SmsService::class);
if ($type == 'content') {
$content = $options['content'] ?? '';
$smsService->send($mobile, $content);
} elseif ($type == 'code') {
$clientIp = $options['client_ip'] ?? '';
$smsService->sendCode($mobile, ['client_ip' => $clientIp]);
} elseif ($type == 'batch') {
if (!is_array($mobile)) {
$mobile = [$mobile];
}
$content = $options['content'] ?? '';
$smsService->sendBatch($mobile, $content);
} else {
throw new BusinessException('类型错误');
}
}
}