1
0
mirror of https://gitee.com/coder-xiaomo/flashsale synced 2025-09-12 23:11:38 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

otp验证码获取

This commit is contained in:
2022-03-01 18:59:29 +08:00
parent 897f69970a
commit f52fa51895
2 changed files with 60 additions and 20 deletions

View File

@@ -10,6 +10,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Random;
@Controller("user") // 允许被SpringBoot扫描到
@RequestMapping("/user") // 通过 "/user" 访问到
@@ -18,6 +21,27 @@ public class UserController extends BaseController {
@Autowired
private UserService userService;
@Autowired
private HttpServletRequest httpServletRequest;
// 用户获取OTP短信接口
@RequestMapping("/getotp")
@ResponseBody
public CommonReturnType getOtp(@RequestParam(name = "telephone") String telephone) {
// 需要按照一定的规则生成OTP验证码
Random random = new Random();
int randomInt = random.nextInt(99999);// [0,99999)
String otpCode = String.format("%05d", randomInt);
// 将OTP验证码同对应用户的手机号关联 使用
httpServletRequest.getSession().setAttribute(telephone, otpCode);
// 将OTP验证码通过短信通道发送给用户
System.out.println("telephone = " + telephone + " & otpCode = " + otpCode);
return CommonReturnType.create(null);
}
@RequestMapping("/get")
@ResponseBody
public CommonReturnType getUser(@RequestParam(name = "id") Integer id) throws BusinessException {