package com.imooc.controller;
import com.imooc.grace.result.GraceJSONResult;
import com.imooc.utils.IPUtil;
import com.imooc.utils.MyInfo;
import com.imooc.utils.SMSUtils;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@RestController
@Slf4j
@Api(tags = "PassportController 通信证接口模块")
@RequestMapping("passport")
public class PassportController extends BaseInfoProperties{
@Autowired
private SMSUtils smsUtils;
@PostMapping("getSMSCode")
public GraceJSONResult getSMSCode(@RequestParam String mobile,
HttpServletRequest request) throws Exception {
if (StringUtils.isBlank(mobile)) {
return GraceJSONResult.ok();
}
// 获得用户ip,
String userIp = IPUtil.getRequestIp(request);
// 根据用户ip进行限制,限制用户在60秒之内只能获得一次验证码
redis.setnx60s(MOBILE_SMSCODE + ":" + userIp, userIp);
String code = (int)((Math.random() * 9 + 1) * 100000) + "";
smsUtils.sendSMS(MyInfo.getMobile(), code);
// smsUtils.sendSMS(mobile, code);
log.info(code);
// 把验证码放入到redis中,用于后续的验证
redis.set(MOBILE_SMSCODE + ":" + mobile, code, 30 * 60);
return GraceJSONResult.ok();
}
}
使用新版SpringBoot技术结合Uniapp,完成仿抖音短视频项目
了解课程