Files
swiftadmin/app/api/controller/Ajax.php

65 lines
1.6 KiB
PHP
Raw Normal View History

2022-08-19 19:48:37 +08:00
<?php
declare (strict_types=1);
namespace app\api\controller;
use app\ApiController;
2023-06-19 14:32:30 +08:00
use app\common\exception\OperateException;
use app\common\service\notice\EmailService;
use app\common\service\notice\SmsService;
use Psr\SimpleCache\InvalidArgumentException;
2022-11-28 19:11:12 +08:00
use support\Response;
2022-08-19 19:48:37 +08:00
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/**
* 异步调用
*/
class Ajax extends ApiController
{
/**
2023-06-19 14:32:30 +08:00
* 首页
2022-08-19 19:48:37 +08:00
*/
2023-06-19 14:32:30 +08:00
public function index(): Response
2022-08-19 19:48:37 +08:00
{
2023-06-19 14:32:30 +08:00
return response('Hello swiftadmin!');
2022-08-19 19:48:37 +08:00
}
/**
2023-06-19 14:32:30 +08:00
* 发送短信验证码
* @return Response
* @throws InvalidArgumentException
2022-08-19 19:48:37 +08:00
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
2023-06-19 14:32:30 +08:00
public function smsSend(): Response
2022-08-19 19:48:37 +08:00
{
2023-06-19 14:32:30 +08:00
$mobile = input('mobile', '');
$event = input('event', 'register');
if (!SmsService::filterMobile($mobile)) {
return $this->error('手机号码不正确');
}
SmsService::send($mobile, $event);
return $this->success("验证码发送成功!");
}
2022-08-19 19:48:37 +08:00
2023-06-19 14:32:30 +08:00
/**
* 发送邮件验证码
* @return Response
* @throws InvalidArgumentException
* @throws OperateException
*/
public function emailSend(): Response
{
$email = input('email');
$event = input('event', 'register');
if (!EmailService::filterEmail($email)) {
return $this->error('邮件格式不正确');
2022-08-19 19:48:37 +08:00
}
2023-06-19 14:32:30 +08:00
EmailService::captcha($email, $event);
return $this->success("验证码发送成功!");
2022-08-19 19:48:37 +08:00
}
}