mirror of https://gitee.com/stylefeng/roses
【sms】增加图形验证码验证和短信发送
parent
cd2f4a1fc0
commit
d3e6943810
|
@ -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.
|
||||
|
||||
Guns采用APACHE 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -28,6 +28,16 @@ public class SysSmsSendParam {
|
|||
@NotBlank(message = "模板号为空,请检查templateCode参数")
|
||||
private String templateCode;
|
||||
|
||||
/**
|
||||
* 图形验证码
|
||||
*/
|
||||
private String verCode;
|
||||
|
||||
/**
|
||||
* 缓存 key
|
||||
*/
|
||||
private String verKey;
|
||||
|
||||
/**
|
||||
* 模板中的参数
|
||||
*/
|
||||
|
|
|
@ -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. 如果是纯消息发送,直接发送,校验类短信要把验证码存库
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
Loading…
Reference in New Issue