@RestController @RequestMapping("/user") public class UserController { @Autowired private UserService userService; /** * * @param user * @param session 发送登录验证码 * @return http://localhost:8080/user/sendMsgApi */ @PostMapping("/sendMsg") public R<String> getPhoneCode(@RequestBody User user, HttpSession session){ //1.从页面获取用户输入的手机号码 String phone = user.getPhone(); //2.判断用户输入的手机号码是否为空,代码更为严谨 if(phone != null){ //3.使用工具类生成四位验证码 String code = ValidateCodeUtils.generateValidateCode(4).toString(); System.out.println("程序生成的验证码:"+code); //5.用阿里云短信服务发送验证码给用户 //SMSUtils.sendMessage("瑞吉外卖","SMS_249930476",phone,code); //6.把验证码存进session里方便登录时与用户提交的验证码比对 session.setAttribute(phone,code); return R.succe