SmsController.php 2.7 KB

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