@PostMapping("getYzm")
@ResponseBody
public Result getYzm(HttpServletRequest request) {
String mobile = HttpParameterUtil.getString(request, "mobile");
Integer sguserid = CampSessionDataHelper.getSguserid(request);
String dateStr = DateUtil.getCurDate();
String countKey = SysConstant.MOBILE_VERIFY_CODE_REDIS_NAME_SPACE+"count_"+dateStr + "_" + mobile;
String valueKey = SysConstant.MOBILE_VERIFY_CODE_REDIS_NAME_SPACE+campCode + "_" + mobile;
// 验证短信验证次数
Integer count = (Integer) redisTemplate.opsForValue()
.get(countKey);
if (count != null && count >= 5) {
return Result.error(-1, "验证码次数已超过限制,请明天再尝试");
}
String res = (String) redisTemplate.opsForValue().get(valueKey);
if (res != null) {
return Result.error(-1, "请勿重复点击");
}
String templateid = campCfgSubmitInfo.getMobileVerifyCodeSmsTplid();
int code = RandomUtil.random(1000, 9999);
//发送验证码逻辑
JSONObject json = PsvHttpUtil.post(PsvConstant.SEND_MOBILE_VERIFY_CODE_URL, params);
if (json.getInt("error") != 0) {
return Result.error(-1, json.getString("errmsg"));
}
// 设置到redis,并且设置过期时间为60s
redisTemplate.opsForValue().set(valueKey, code, 60L, TimeUnit.SECONDS);
// 增加当天访问验证码次数
if(count == null || count ==0) {
//设置为两天过期
redisTemplate.opsForValue().set(countKey, 1, 2L, TimeUnit.DAYS);
}else {
redisTemplate.opsForValue().increment(countKey, 1L);
}
return Result.success(code);
}