SmsController.java 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. package com.izouma.awesomeAdmin.web;
  2. import com.izouma.awesomeAdmin.config.Constants;
  3. import com.izouma.awesomeAdmin.exception.BusinessException;
  4. import com.izouma.awesomeAdmin.service.sms.SmsService;
  5. import lombok.AllArgsConstructor;
  6. import org.springframework.web.bind.annotation.GetMapping;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RequestParam;
  9. import org.springframework.web.bind.annotation.RestController;
  10. import java.util.regex.Pattern;
  11. @RestController
  12. @RequestMapping("/sms")
  13. @AllArgsConstructor
  14. public class SmsController {
  15. private SmsService smsService;
  16. @GetMapping("/sendVerify")
  17. public String sendVerify(@RequestParam String phone) {
  18. if (!Pattern.matches(Constants.Regex.PHONE, phone)) {
  19. throw new BusinessException("请输入正确的手机号");
  20. }
  21. return smsService.sendVerify(phone);
  22. }
  23. @GetMapping("/verify")
  24. public void verify(@RequestParam String phone, @RequestParam String code) throws SmsService.SmsVerifyException {
  25. smsService.verify(phone, code);
  26. }
  27. }