pref: 增加服务类优化UI版面
This commit is contained in:
@@ -4,11 +4,10 @@ declare (strict_types=1);
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\ApiController;
|
||||
|
||||
use app\common\library\Email;
|
||||
use app\common\library\Sms;
|
||||
use app\common\model\system\User;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
use app\common\exception\OperateException;
|
||||
use app\common\service\notice\EmailService;
|
||||
use app\common\service\notice\SmsService;
|
||||
use Psr\SimpleCache\InvalidArgumentException;
|
||||
use support\Response;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
@@ -19,87 +18,47 @@ use think\db\exception\ModelNotFoundException;
|
||||
*/
|
||||
class Ajax extends ApiController
|
||||
{
|
||||
|
||||
public bool $needLogin = true;
|
||||
|
||||
/**
|
||||
* 发送短信
|
||||
* @return Response|void
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* 首页
|
||||
*/
|
||||
public function smsSend()
|
||||
public function index(): Response
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
|
||||
$mobile = input('mobile');
|
||||
$event = input('event', 'register');
|
||||
|
||||
if (!is_mobile($mobile)) {
|
||||
return $this->error('手机号码不正确');
|
||||
}
|
||||
|
||||
$sms = Sms::instance();
|
||||
$data = $sms->getLast($mobile);
|
||||
if ($data && (time() - strtotime($data['create_time'])) < 60) {
|
||||
return $this->error(__('发送频繁'));
|
||||
}
|
||||
|
||||
$user = User::getByMobile($mobile);
|
||||
if (in_array($event, ['register', 'changer']) && $user) {
|
||||
return $this->error('当前手机号已被占用');
|
||||
} else if ($event == 'forgot' && !$user) {
|
||||
return $this->error('当前手机号未注册');
|
||||
}
|
||||
|
||||
if ($sms->send($mobile, $event)) {
|
||||
return $this->success("验证码发送成功!");
|
||||
} else {
|
||||
return $this->error($sms->getError());
|
||||
}
|
||||
}
|
||||
|
||||
return json(['msg' => 'success', 'data' => 'Hello']);
|
||||
return response('Hello swiftadmin!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
* @return Response|void
|
||||
* 发送短信验证码
|
||||
* @return Response
|
||||
* @throws InvalidArgumentException
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function emailSend()
|
||||
public function smsSend(): Response
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
|
||||
$email = input('email');
|
||||
$event = input('event', 'register');
|
||||
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
return $this->error('邮件格式不正确');
|
||||
}
|
||||
|
||||
$Ems = Email::instance();
|
||||
$data = $Ems->getLast($email);
|
||||
|
||||
if ($data && (time() - strtotime($data['create_time'])) < 60) {
|
||||
return $this->error(__('发送频繁'));
|
||||
}
|
||||
|
||||
$user = User::getByEmail($email);
|
||||
if (in_array($event, ['register', 'changer']) && $user) {
|
||||
return $this->error('当前邮箱已被注册');
|
||||
} else if ($event == 'forgot' && !$user) {
|
||||
return $this->error('当前邮箱不存在');
|
||||
}
|
||||
|
||||
if ($Ems->captcha($email, $event)->send()) {
|
||||
return $this->success("验证码发送成功!");
|
||||
} else {
|
||||
return $this->error($Ems->getError());
|
||||
}
|
||||
$mobile = input('mobile', '');
|
||||
$event = input('event', 'register');
|
||||
if (!SmsService::filterMobile($mobile)) {
|
||||
return $this->error('手机号码不正确');
|
||||
}
|
||||
SmsService::send($mobile, $event);
|
||||
return $this->success("验证码发送成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送邮件验证码
|
||||
* @return Response
|
||||
* @throws InvalidArgumentException
|
||||
* @throws OperateException
|
||||
*/
|
||||
public function emailSend(): Response
|
||||
{
|
||||
$email = input('email');
|
||||
$event = input('event', 'register');
|
||||
if (!EmailService::filterEmail($email)) {
|
||||
return $this->error('邮件格式不正确');
|
||||
}
|
||||
EmailService::captcha($email, $event);
|
||||
return $this->success("验证码发送成功!");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user