1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace App\Http\Controllers\Web\Common;
- use Aix\Sms\Contracts\Smser;
- use App\Http\Controllers\Web\WebBaseController;
- use App\Services\Auth\AuthService;
- use App\Services\Common\GeetestService;
- use App\Services\Common\SmsService;
- use App\Services\Common\TencentCaptchaService;
- use App\Validators\SmsValidatorRequest;
- class SmsController extends WebBaseController
- {
- /**
- * @var SmsService
- */
- protected $smsService;
- /**
- * @var GeetestService
- */
- private $geetestService;
- /**
- * @var AuthService
- */
- private $authService;
- private $tencentCaptchaService;
- /**
- * CommonController constructor.
- * @param AuthService $authService
- * @param SmsService $smsService
- * @param GeetestService $geetestService
- */
- public function __construct(AuthService $authService, SmsService $smsService, GeetestService $geetestService, TencentCaptchaService $tencentCaptchaService)
- {
- $this->smsService = $smsService;
- $this->geetestService = $geetestService;
- $this->authService = $authService;
- $this->tencentCaptchaService = $tencentCaptchaService;
- }
- public function sendSms(SmsValidatorRequest $smsValidatorRequest)
- {
- $method=$smsValidatorRequest->type.'Sms';
- $result=$this->$method($smsValidatorRequest->mobile);
- return $result;
- }
- protected function loginSms($mobile)
- {
- if (!$this->authService->checkUser($mobile, "", 2)) {
- return $this->sendErrorResponse("该手机号码没有绑定账号,请先注册");
- }
- $this->smsService->sendAuthSms($mobile, Smser::TEMPLATE_AUTH_LOGIN);
- return $this->sendSuccessResponse();
- }
- protected function registerSms($mobile)
- {
- // if (config('aix.system.site_safety.site_vo_code.captcha_open') == 1) {
- // if (!$this->geetestService->checkGeetest()) {
- // return $this->sendErrorResponse("验证码不通过,请重新验证");
- // }
- // }
- $this->smsService->sendAuthSms($mobile, Smser::TEMPLATE_AUTH_REGISTER);
- return $this->sendSuccessResponse();
- }
- protected function checkSms($mobile)
- {
- // if (config('aix.system.site_safety.site_vo_code.captcha_open') == 1) {
- // if (!$this->geetestService->checkGeetest()) {
- // return $this->sendErrorResponse("验证码不通过,请重新验证");
- // }
- // }
- if(!$this->tencentCaptchaService->check(request()->input('randstr'),request()->input('ticket'),request()->ip())){
- return $this->sendErrorResponse("验证码不通过,请重新验证");
- }
- $this->smsService->sendAuthSms($mobile, Smser::TEMPLATE_AUTH_CHECK);
- return $this->sendSuccessResponse();
- }
- }
|