SmsController.java 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package com.izouma.nineth.web;
  2. import com.izouma.nineth.config.Constants;
  3. import com.izouma.nineth.exception.BusinessException;
  4. import com.izouma.nineth.service.CaptchaService;
  5. import com.izouma.nineth.service.sms.SmsService;
  6. import lombok.AllArgsConstructor;
  7. import org.springframework.data.redis.core.RedisTemplate;
  8. import org.springframework.web.bind.annotation.GetMapping;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestParam;
  11. import org.springframework.web.bind.annotation.RestController;
  12. import java.util.regex.Pattern;
  13. @RestController
  14. @RequestMapping("/sms")
  15. @AllArgsConstructor
  16. public class SmsController {
  17. private SmsService smsService;
  18. private CaptchaService captchaService;
  19. @GetMapping("/sendVerify")
  20. public String sendVerify(@RequestParam String phone) {
  21. throw new BusinessException("此接口已停用,请重启APP或刷新网页");
  22. // if (!Pattern.matches(Constants.Regex.PHONE, phone)) {
  23. // throw new BusinessException("请输入正确的手机号");
  24. // }
  25. // return smsService.sendVerify(phone);
  26. }
  27. @GetMapping("/sendSecureVerify")
  28. public String sendVerify(@RequestParam String phone, @RequestParam String captcha, @RequestParam String captchaKey) {
  29. if (!Pattern.matches(Constants.Regex.PHONE, phone)) {
  30. throw new BusinessException("请输入正确的手机号");
  31. }
  32. if (!captchaService.verify(captchaKey, captcha)) {
  33. throw new BusinessException("验证码错误");
  34. }
  35. return smsService.sendVerify(phone);
  36. }
  37. @GetMapping("/verify")
  38. public String verify(@RequestParam String phone, @RequestParam String code) throws SmsService.SmsVerifyException {
  39. return smsService.verify(phone, code);
  40. }
  41. }