diff --git a/src/com/engine/salary/service/SalarySendService.java b/src/com/engine/salary/service/SalarySendService.java index 15747572a..b63c6231e 100644 --- a/src/com/engine/salary/service/SalarySendService.java +++ b/src/com/engine/salary/service/SalarySendService.java @@ -184,11 +184,14 @@ public interface SalarySendService { */ void sendMobileCode(SMSCodeSendParam param); + void sendMobileCode(); + /** * 校验验证码 * @param param */ Boolean checkMobileCode(SMSCodeCheckParam param); + Boolean checkMobileCode2(SMSCodeCheckParam param); /** * 获取工资单id下需要发放的工资单明细 diff --git a/src/com/engine/salary/service/impl/SalarySendServiceImpl.java b/src/com/engine/salary/service/impl/SalarySendServiceImpl.java index 74268d450..ad442614b 100644 --- a/src/com/engine/salary/service/impl/SalarySendServiceImpl.java +++ b/src/com/engine/salary/service/impl/SalarySendServiceImpl.java @@ -1770,6 +1770,42 @@ public class SalarySendServiceImpl extends Service implements SalarySendService MessageUtil.sendSMS(mobile, "【西部信托】验证码:" + mobileCode + ",有效时间10分钟。此验证码用于查看工资单明细,请勿告诉他人。"); } + @Override + public void sendMobileCode() { + if(user == null){ + throw new SalaryRunTimeException("未获取用户信息"); + } + + + int uid = user.getUID(); + DataCollectionEmployee employee = getSalaryEmployeeService(user).getEmployeeById((long) uid); + if (employee == null) { + throw new SalaryRunTimeException("未获取人员信息"); + } + + String mobile = employee.getMobile(); + if (mobile == null) { + throw new SalaryRunTimeException("未获取手机号"); + } + + boolean checkSendSMS = MessageUtil.checkSendSMS(); + if (!checkSendSMS) { + throw new SalaryRunTimeException("短信服务异常"); + } + + //1、生成6位验证码 + String mobileCode = (int) ((Math.random() * 9 + 1) * 100000) + ""; + //失效时间 + long expirationTime = LocalDateTime.now().plusMinutes(10L).toInstant(ZoneOffset.ofHours(8)).toEpochMilli(); + String cacheValue = mobileCode + "_" + expirationTime; + + //2、验证码缓存,10分钟失效 + getSalaryCacheService(user).set(SALARY_CACHE_SMS_CODE + "_" + uid, cacheValue); + + //3、发送短信 + MessageUtil.sendSMS(mobile, "【西部信托】验证码:" + mobileCode + ",有效时间10分钟。此验证码用于查看工资单明细,请勿告诉他人。"); + } + @Override public Boolean checkMobileCode(SMSCodeCheckParam param) { Long id = param.getId(); @@ -1798,6 +1834,37 @@ public class SalarySendServiceImpl extends Service implements SalarySendService return true; } + @Override + public Boolean checkMobileCode2(SMSCodeCheckParam param) { + if(user == null){ + throw new SalaryRunTimeException("未获取用户信息"); + } + int uid = user.getUID(); + + String mobileCode = param.getMobileCode(); + + //取出验证码 + String cacheValue = getSalaryCacheService(user).get(SALARY_CACHE_SMS_CODE + "_" + uid); + if (cacheValue == null) { + throw new SalaryRunTimeException("未获取到验证码,请重新发送"); + } + String[] cache = cacheValue.split("_"); + String code = cache[0]; + //失效时间 + long expirationTime = Long.parseLong(cache[1]); + + long nowTime = LocalDateTime.now().toInstant(ZoneOffset.ofHours(8)).toEpochMilli(); + if (nowTime > expirationTime) { + throw new SalaryRunTimeException("验证码已失效,请重新发送"); + } + + if (!StringUtils.equals(code, mobileCode)) { + throw new SalaryRunTimeException("验证码错误"); + } + + return true; + } + @Override public List getNeedSendInfoList(List salarySendIds) { if (CollectionUtils.isEmpty(salarySendIds)) { diff --git a/src/com/engine/salary/wrapper/SalarySendWrapper.java b/src/com/engine/salary/wrapper/SalarySendWrapper.java index cf263db9d..536ffb222 100644 --- a/src/com/engine/salary/wrapper/SalarySendWrapper.java +++ b/src/com/engine/salary/wrapper/SalarySendWrapper.java @@ -691,7 +691,7 @@ public class SalarySendWrapper extends Service implements SalarySendWrapperProxy * @param param 短信验证码发送参数 */ public void sendMobileCode(SMSCodeSendParam param) { - getSalarySendService(user).sendMobileCode(param); + getSalarySendService(user).sendMobileCode(); } /** @@ -700,7 +700,7 @@ public class SalarySendWrapper extends Service implements SalarySendWrapperProxy * @return */ public Boolean checkMobileCode(SMSCodeCheckParam param) { - return getSalarySendService(user).checkMobileCode(param); + return getSalarySendService(user).checkMobileCode2(param); } public PayrollCheckTypeEnum payrollCheckType() {