Commit 0b265281 by 徐高华

企微托管

parent 04bf3326
......@@ -3,6 +3,8 @@ package com.gic.haoban.manage.web.controller;
import com.alibaba.fastjson.JSON;
import com.gic.clerk.api.dto.ClerkDTO;
import com.gic.clerk.api.service.ClerkService;
import com.gic.commons.util.DateUtil;
import com.gic.commons.util.GlobalVar;
import com.gic.enterprise.api.service.StoreService;
import com.gic.haoban.common.utils.CheckSmsCodeUtil;
import com.gic.haoban.common.utils.GooglePhoneNumberUtil;
......@@ -11,6 +13,7 @@ import com.gic.haoban.manage.api.response.SendSmsResponse;
import com.gic.haoban.manage.api.service.ValidationCodeApiService;
import com.gic.haoban.manage.web.errCode.HaoBanErrCode;
import com.gic.redis.data.util.RedisUtil;
import com.task.allocation.util.MemCachedInstance;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -19,6 +22,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
@RestController
public class SendCodeController extends WebBaseController {
private static Logger logger = LoggerFactory.getLogger(SendCodeController.class);
......@@ -27,6 +32,8 @@ public class SendCodeController extends WebBaseController {
private ValidationCodeApiService validationCodeService;
@Autowired
private ClerkService clerkService ;
static MemCachedInstance memCachedInstance = MemCachedInstance.getInstance(
GlobalVar.getMemCachedIp(), GlobalVar.getMemCachedPort());
/**
* 验证码发送
......@@ -61,7 +68,10 @@ public class SendCodeController extends WebBaseController {
} else {
RedisUtil.setCache(cacheKey, true, 60L);
}
if (this.getVcodeTimes(phoneNumber) <= 0) {
logger.info("验证 达到上线");
return this.fail("验证码发送达到上限") ;
}
String smsCode = "";
if (CheckSmsCodeUtil.getCacheSmsCode(nationcode + "-" + phoneNumber, type) != null) {
smsCode = (String) CheckSmsCodeUtil.getCacheSmsCode(nationcode + "-" + phoneNumber, type);
......@@ -111,4 +121,23 @@ public class SendCodeController extends WebBaseController {
}
}
public static int getVcodeTimes(String phoneNumber) {
String key = phoneNumber
+ DateUtil.dateToStr(new Date(), DateUtil.FORMAT_DATE_8);
int times = 10;
Object res = memCachedInstance.getValue(key);
logger.info("好办验证码次数={}",res);
if (null == res) {
memCachedInstance.setValue(key, 10, 24 * 60 * 60 * 1000);
}
else {
times = Integer.parseInt(String.valueOf(res));
}
if (times > 0) {
memCachedInstance.setValue(key, (times - 1), 24 * 60 * 60 * 1000);
}
return times;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment