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.
57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Exception\BusinessException;
|
|
use App\Helper\Queue;
|
|
use App\Job\SmsJob;
|
|
use App\Service\SmsService;
|
|
|
|
class SmsController extends AbstractController
|
|
{
|
|
/**
|
|
* @var SmsService
|
|
*/
|
|
protected $smsService;
|
|
|
|
public function __construct(SmsService $smsService)
|
|
{
|
|
$this->smsService = $smsService;
|
|
}
|
|
|
|
public function send()
|
|
{
|
|
$mobile = $this->request->input('mobile', null);
|
|
$options = $this->request->input('options', []);
|
|
if (!$mobile) {
|
|
throw new BusinessException('缺少参数[mobile]');
|
|
}
|
|
if (!isset($options['type'])) {
|
|
throw new BusinessException('缺少参数options[type]');
|
|
}
|
|
Queue::push(SmsJob::class, [
|
|
'mobile' => $mobile,
|
|
'options' => $options,
|
|
]);
|
|
return $this->success();
|
|
}
|
|
|
|
public function check()
|
|
{
|
|
$mobile = $this->request->input('mobile', '');
|
|
$code = $this->request->input('code', '');
|
|
|
|
if (!$mobile) {
|
|
throw new BusinessException('缺少参数[mobile]');
|
|
}
|
|
if (!$code) {
|
|
throw new BusinessException('缺少参数[code]');
|
|
}
|
|
if (!$this->smsService->check($mobile, $code)) {
|
|
throw new BusinessException('验证失败');
|
|
}
|
|
return $this->success('验证成功');
|
|
}
|
|
} |