【sms】增加图形验证码验证和短信发送

pull/3/head
chenjinlong 2021-01-15 18:57:43 +08:00
parent cd2f4a1fc0
commit d3e6943810
6 changed files with 110 additions and 6 deletions

View File

@ -0,0 +1,66 @@
/*
Copyright [2020] [https://www.stylefeng.cn]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
GunsAPACHE LICENSE 2.0使
1.LICENSE
2.Guns
3.
4. https://gitee.com/stylefeng/guns-separation
5. https://gitee.com/stylefeng/guns-separation
6.Guns https://www.stylefeng.cn
*/
package cn.stylefeng.roses.kernel.system.exception.enums;
import cn.stylefeng.roses.kernel.rule.abstracts.AbstractExceptionEnum;
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
import cn.stylefeng.roses.kernel.system.constants.SystemConstants;
import lombok.Getter;
/**
*
*
* @author majianguo
* @date 2020/11/5 11:06
*/
@Getter
public enum SysSmsExceptionEnum implements AbstractExceptionEnum {
/**
*
*/
KAPTCHA_EMPTY(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "101", "验证码不能为空"),
/**
*
*/
KAPTCHA_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "102", "验证码错误");
/**
*
*/
private final String errorCode;
/**
*
*/
private final String userTip;
SysSmsExceptionEnum(String errorCode, String userTip) {
this.errorCode = errorCode;
this.userTip = userTip;
}
}

View File

@ -17,10 +17,10 @@
<dependencies>
<!--短信发送模块api-->
<!--系统管理的api-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>sms-api</artifactId>
<artifactId>system-api</artifactId>
<version>1.0.0</version>
</dependency>
@ -32,6 +32,13 @@
<version>1.0.0</version>
</dependency>
<!--短信发送模块api-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>sms-api</artifactId>
<version>1.0.0</version>
</dependency>
<!--参数校验模块-->
<!--用在控制器,参数校验-->
<dependency>

View File

@ -8,9 +8,9 @@ import cn.stylefeng.roses.kernel.resource.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsInfoParam;
import cn.stylefeng.roses.kernel.sms.modular.service.SysSmsInfoService;
import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsSendParam;
import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsVerifyParam;
import cn.stylefeng.roses.kernel.sms.modular.service.SysSmsInfoService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@ -48,8 +48,8 @@ public class SmsSenderController {
* @author fengshuonan
* @date 2020/10/26 18:34
*/
@PostResource(name = "发送验证码短信", path = "/sms/sendLoginMessage")
public ResponseData sendLoginMessage(@RequestBody @Validated SysSmsSendParam sysSmsSendParam) {
@PostResource(name = "发送验证码短信", path = "/sms/sendLoginMessage", requiredLogin = false, requiredPermission = false)
public ResponseData sendMessage(@RequestBody @Validated SysSmsSendParam sysSmsSendParam) {
// 清空params参数
sysSmsSendParam.setParams(null);

View File

@ -28,6 +28,16 @@ public class SysSmsSendParam {
@NotBlank(message = "模板号为空请检查templateCode参数")
private String templateCode;
/**
*
*/
private String verCode;
/**
* key
*/
private String verKey;
/**
*
*/

View File

@ -3,6 +3,7 @@ package cn.stylefeng.roses.kernel.sms.modular.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
@ -17,6 +18,9 @@ import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsInfoParam;
import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsSendParam;
import cn.stylefeng.roses.kernel.sms.modular.param.SysSmsVerifyParam;
import cn.stylefeng.roses.kernel.sms.modular.service.SysSmsInfoService;
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
import cn.stylefeng.roses.kernel.system.exception.enums.SysSmsExceptionEnum;
import cn.stylefeng.roses.kernel.validator.CaptchaApi;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -46,10 +50,21 @@ public class SysSmsInfoServiceImpl extends ServiceImpl<SysSmsMapper, SysSms> imp
@Resource
private SmsSenderApi smsSenderApi;
@Resource
private CaptchaApi captchaApi;
@Transactional(rollbackFor = Exception.class)
@Override
public boolean sendShortMessage(SysSmsSendParam sysSmsSendParam) {
String verCode = sysSmsSendParam.getVerCode();
String verKey = sysSmsSendParam.getVerKey();
if (StrUtil.isEmpty(verCode) || StrUtil.isEmpty(verKey)) {
throw new SystemModularException(SysSmsExceptionEnum.KAPTCHA_EMPTY);
}
if (!captchaApi.validate(verCode, verKey)) {
throw new SystemModularException(SysSmsExceptionEnum.KAPTCHA_ERROR);
}
Map<String, Object> params = sysSmsSendParam.getParams();
// 1. 如果是纯消息发送,直接发送,校验类短信要把验证码存库

View File

@ -73,6 +73,12 @@
<version>1.0.0</version>
</dependency>
<!-- 注册短信的业务 -->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>system-business-sms</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>