mirror of
https://gitee.com/coder-xiaomo/flashsale
synced 2025-09-12 23:11:38 +08:00
otp验证码获取
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user