diff --git a/pmapi/pom.xml b/pmapi/pom.xml index 3db2e93..c89bd42 100644 --- a/pmapi/pom.xml +++ b/pmapi/pom.xml @@ -250,11 +250,11 @@ com.ningdatech nd-flowable-starter - - com.ningdatech - nd-yxt-starter - 1.0.0 - + + + + + com.alibaba.xxpt diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sms/controller/VerificationCodeController.java b/pmapi/src/main/java/com/ningdatech/pmapi/sms/controller/VerificationCodeController.java index 1b6733e..b766142 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sms/controller/VerificationCodeController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sms/controller/VerificationCodeController.java @@ -35,7 +35,7 @@ public class VerificationCodeController { @ApiOperation(value = "发送验证码", notes = "发送验证码") @PostMapping(value = "/send") public void send(@Validated @RequestBody ReqVerificationCodePO request) { - smsManage.sendVerificationCode(request); +// smsManage.sendVerificationCode(request); } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sms/manage/SmsManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/sms/manage/SmsManage.java index 8f3e276..4891d4a 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sms/manage/SmsManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sms/manage/SmsManage.java @@ -32,66 +32,65 @@ import java.util.Collections; @Component @RequiredArgsConstructor public class SmsManage { - - private final YxtClient yxtClient; - private final CachePlusOps cachePlusOps; - - public void sendVerificationCode(ReqVerificationCodePO request) { - Assert.isTrue(PhoneUtil.isMobile(request.getMobile()), "手机号码格式不正确"); - String verificationType = request.getVerificationType(); - VerificationCodeType verificationCodeTypeEnum = VerificationCodeType.of(verificationType); - - // 验证是否被锁定 - String lockKey = SmsRedisKeyUtils.smsSendLockKey(verificationCodeTypeEnum, request.getMobile()); - if (StringUtils.isNotBlank(cachePlusOps.get(lockKey))) { - throw BizException.wrap("今日" + verificationCodeTypeEnum.getDesc() + "的验证码发送次数过多,已被锁定"); - } - // 验证发送间隔 - String cacheKey = SmsRedisKeyUtils.smsCodeVerifyKey(verificationCodeTypeEnum, request.getMobile()); - VerifyCodeCacheDTO preCache = (VerifyCodeCacheDTO) cachePlusOps.get(cacheKey); - if (preCache != null) { - if (LocalDateTime.now().minusMinutes(verificationCodeTypeEnum.getSendInterval()) - .isBefore(preCache.getSendTime())) { - throw BizException.wrap(verificationCodeTypeEnum.getSendInterval() + "分钟之内已发送过验证码,请稍后重试"); - } - } - String code = RandomUtil.randomNumbers(6); - VerifyCodeCacheDTO cache = VerifyCodeCacheDTO.builder() - .code(code) - .sendTime(LocalDateTime.now()) - .mobile(request.getMobile()) - .build(); - - // 创建短信内容 - SendSmsCmd sendSmsCmd = new SendSmsCmd(); - switch (verificationCodeTypeEnum) { - case LOGIN: - SendSmsCmd.SendSmsContext sendSmsContext = new SendSmsCmd.SendSmsContext(); - sendSmsContext.setReceiveNumber(request.getMobile()); - sendSmsContext.setContent(String.format(YxtSmsTemplateConst.SMS_LOGIN_TEMPLATE, code, verificationCodeTypeEnum.getExpireTime())); - sendSmsCmd.setContextList(Collections.singletonList(sendSmsContext)); - sendSmsCmd.setSmsSignEnum(YxtSmsSignEnum.ZJS_ELECTRONIC_EXPERT_LIB); - break; - default: - throw new IllegalArgumentException("非法的短信发送类型"); - } - // 发送 短信 - yxtClient.submitSmsTask(sendSmsCmd); - log.info("send verificationCode mobile = {},code = {}", request.getMobile(), code); - - cachePlusOps.set(new CacheKey(cacheKey, Duration.ofMinutes(verificationCodeTypeEnum.getExpireTime())), cache); - String limitKey = SmsRedisKeyUtils.smsSendLimitKey(verificationCodeTypeEnum, request.getMobile()); - if (StringUtils.isNotBlank(cachePlusOps.get(limitKey))) { - long limitCount = cachePlusOps.incr(new CacheKey(limitKey, Duration.ofSeconds(DateUtil.restSecondsFromNowToNoon()))); - // 超出单日发送次数之后直接锁定 - if (limitCount >= verificationCodeTypeEnum.getSendTimesByDay().longValue()) { - cachePlusOps.set(new CacheKey(lockKey, Duration.ofSeconds(DateUtil.restSecondsFromNowToNoon())), request.getMobile()); - } - } else { - cachePlusOps.set(new CacheKey(limitKey, Duration.ofSeconds(DateUtil.restSecondsFromNowToNoon())), 1); - } - - } +// +// private final YxtClient yxtClient; +// private final CachePlusOps cachePlusOps; +// +// public void sendVerificationCode(ReqVerificationCodePO request) { +// Assert.isTrue(PhoneUtil.isMobile(request.getMobile()), "手机号码格式不正确"); +// String verificationType = request.getVerificationType(); +// VerificationCodeType verificationCodeTypeEnum = VerificationCodeType.of(verificationType); +// +// // 验证是否被锁定 +// String lockKey = SmsRedisKeyUtils.smsSendLockKey(verificationCodeTypeEnum, request.getMobile()); +// if (StringUtils.isNotBlank(cachePlusOps.get(lockKey))) { +// throw BizException.wrap("今日" + verificationCodeTypeEnum.getDesc() + "的验证码发送次数过多,已被锁定"); +// } +// // 验证发送间隔 +// String cacheKey = SmsRedisKeyUtils.smsCodeVerifyKey(verificationCodeTypeEnum, request.getMobile()); +// VerifyCodeCacheDTO preCache = (VerifyCodeCacheDTO) cachePlusOps.get(cacheKey); +// if (preCache != null) { +// if (LocalDateTime.now().minusMinutes(verificationCodeTypeEnum.getSendInterval()) +// .isBefore(preCache.getSendTime())) { +// throw BizException.wrap(verificationCodeTypeEnum.getSendInterval() + "分钟之内已发送过验证码,请稍后重试"); +// } +// } +// String code = RandomUtil.randomNumbers(6); +// VerifyCodeCacheDTO cache = VerifyCodeCacheDTO.builder() +// .code(code) +// .sendTime(LocalDateTime.now()) +// .mobile(request.getMobile()) +// .build(); +// +// // 创建短信内容 +// SendSmsCmd sendSmsCmd = new SendSmsCmd(); +// switch (verificationCodeTypeEnum) { +// case LOGIN: +// SendSmsCmd.SendSmsContext sendSmsContext = new SendSmsCmd.SendSmsContext(); +// sendSmsContext.setReceiveNumber(request.getMobile()); +// sendSmsContext.setContent(String.format(YxtSmsTemplateConst.SMS_LOGIN_TEMPLATE, code, verificationCodeTypeEnum.getExpireTime())); +// sendSmsCmd.setContextList(Collections.singletonList(sendSmsContext)); +// sendSmsCmd.setSmsSignEnum(YxtSmsSignEnum.ZJS_ELECTRONIC_EXPERT_LIB); +// break; +// default: +// throw new IllegalArgumentException("非法的短信发送类型"); +// } +// // 发送 短信 +// yxtClient.submitSmsTask(sendSmsCmd); +// log.info("send verificationCode mobile = {},code = {}", request.getMobile(), code); +// +// cachePlusOps.set(new CacheKey(cacheKey, Duration.ofMinutes(verificationCodeTypeEnum.getExpireTime())), cache); +// String limitKey = SmsRedisKeyUtils.smsSendLimitKey(verificationCodeTypeEnum, request.getMobile()); +// if (StringUtils.isNotBlank(cachePlusOps.get(limitKey))) { +// long limitCount = cachePlusOps.incr(new CacheKey(limitKey, Duration.ofSeconds(DateUtil.restSecondsFromNowToNoon()))); +// // 超出单日发送次数之后直接锁定 +// if (limitCount >= verificationCodeTypeEnum.getSendTimesByDay().longValue()) { +// cachePlusOps.set(new CacheKey(lockKey, Duration.ofSeconds(DateUtil.restSecondsFromNowToNoon())), request.getMobile()); +// } +// } else { +// cachePlusOps.set(new CacheKey(limitKey, Duration.ofSeconds(DateUtil.restSecondsFromNowToNoon())), 1); +// } +// } } diff --git a/pmapi/src/main/resources/application-dev.yml b/pmapi/src/main/resources/application-dev.yml index 31e1d00..4a58719 100644 --- a/pmapi/src/main/resources/application-dev.yml +++ b/pmapi/src/main/resources/application-dev.yml @@ -159,4 +159,15 @@ sa-token: # token风格 token-style: uuid # 是否输出操作日志 - is-log: false \ No newline at end of file + is-log: false + +yxt: + wsdl-url: http://115.239.137.23:9501/ws/v1?wsdl + #wsdl-url: file:///opt/nd-emapi/wsdl.xml + #账号 + user-code: hzndkj + #密码 + password: hzndkj@2021 + #音信通开关 + sms-enable: true + tel-enable: true \ No newline at end of file