123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types=1);
- namespace app\index\controller;
- use app\index\service\passport\MailCaptcha;
- use think\response\Json;
- use app\index\service\passport\{Captcha as CaptchaService,
- MailCaptcha as MailCaptchaService,
- SmsCaptcha as SmsCaptchaService};
- use cores\exception\BaseException;
- /**
- * 验证码管理
- * Class Captcha
- * @package app\api\controller
- */
- class Captcha extends Controller
- {
- /**
- * 图形验证码
- * @return Json
- */
- public function image(): Json
- {
- $CaptchaService = new CaptchaService;
- return $this->renderSuccess($CaptchaService->create());
- }
- /**
- * 发送短信验证码
- * @return Json
- * @throws BaseException
- */
- public function sendSmsCaptcha(): Json
- {
- $SmsCaptchaService = new SmsCaptchaService;
- if ($SmsCaptchaService->handle($this->postForm())) {
- return $this->renderSuccess('发送成功,请注意查收');
- }
- return $this->renderError($SmsCaptchaService->getError() ?: '短信发送失败');
- }
- /**
- * 发送邮箱验证码
- * @return Json
- * @throws BaseException
- */
- public function sendEmailCaptcha(): Json
- {
- //todo
- return $this->renderSuccess('Sent Successful!Please check your new mails.');
- $MailCaptchaService = new MailCaptchaService;
- if ($MailCaptchaService->handle($this->postForm())) {
- return $this->renderSuccess('Sent Successful!Please check your new mails.');
- }
- return $this->renderError($MailCaptchaService->getError() ?: 'Failed to send code. Please try again later');
- }
- public function checkEmailCaptcha(): Json
- {
- $code = $this->request->param('smsCode');
- $mobile = $this->request->param('mobile');
- $mailCaptcha = new MailCaptcha();
- $flag = $mailCaptcha->checkCaptcha($code, $mobile);
- if ($flag) {
- return $this->renderSuccess('Successful.');
- }
- return $this->renderError('not match');
- }
- }
|