SmsController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Http\Controllers\Web\Common;
  3. use Aix\Sms\Contracts\Smser;
  4. use App\Http\Controllers\Web\WebBaseController;
  5. use App\Services\Auth\AuthService;
  6. use App\Services\Common\GeetestService;
  7. use App\Services\Common\SmsService;
  8. use App\Validators\SmsValidatorRequest;
  9. class SmsController extends WebBaseController
  10. {
  11. /**
  12. * @var SmsService
  13. */
  14. protected $smsService;
  15. /**
  16. * @var GeetestService
  17. */
  18. private $geetestService;
  19. /**
  20. * @var AuthService
  21. */
  22. private $authService;
  23. /**
  24. * CommonController constructor.
  25. * @param AuthService $authService
  26. * @param SmsService $smsService
  27. * @param GeetestService $geetestService
  28. */
  29. public function __construct(AuthService $authService, SmsService $smsService, GeetestService $geetestService)
  30. {
  31. $this->smsService = $smsService;
  32. $this->geetestService = $geetestService;
  33. $this->authService = $authService;
  34. }
  35. public function sendSms(SmsValidatorRequest $smsValidatorRequest)
  36. {
  37. $method=$smsValidatorRequest->type.'Sms';
  38. $result=$this->$method($smsValidatorRequest->mobile);
  39. return $result;
  40. }
  41. protected function loginSms($mobile)
  42. {
  43. if (!$this->authService->checkUser($mobile, "", 2)) {
  44. return $this->sendErrorResponse("该手机号码没有绑定账号,请先注册");
  45. }
  46. $this->smsService->sendAuthSms($mobile, Smser::TEMPLATE_AUTH_LOGIN);
  47. return $this->sendSuccessResponse();
  48. }
  49. protected function registerSms($mobile)
  50. {
  51. // if (config('aix.system.site_safety.site_vo_code.captcha_open') == 1) {
  52. // if (!$this->geetestService->checkGeetest()) {
  53. // return $this->sendErrorResponse("验证码不通过,请重新验证");
  54. // }
  55. // }
  56. $this->smsService->sendAuthSms($mobile, Smser::TEMPLATE_AUTH_REGISTER);
  57. return $this->sendSuccessResponse();
  58. }
  59. protected function checkSms($mobile)
  60. {
  61. // if (config('aix.system.site_safety.site_vo_code.captcha_open') == 1) {
  62. // if (!$this->geetestService->checkGeetest()) {
  63. // return $this->sendErrorResponse("验证码不通过,请重新验证");
  64. // }
  65. // }
  66. $this->smsService->sendAuthSms($mobile, Smser::TEMPLATE_AUTH_CHECK);
  67. return $this->sendSuccessResponse();
  68. }
  69. }