优化: 短信发送 和 验证码验证功能
This commit is contained in:
parent
1c480b9630
commit
546889cf6f
|
|
@ -4,7 +4,6 @@ import com.alibaba.fastjson2.JSONArray;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.mdd.admin.LikeAdminThreadLocal;
|
||||
import com.mdd.admin.config.AdminConfig;
|
||||
import com.mdd.admin.service.ISystemAuthMenuService;
|
||||
import com.mdd.admin.service.ISystemAuthPermService;
|
||||
import com.mdd.admin.validate.system.SystemMenuCreateValidate;
|
||||
|
|
@ -13,7 +12,6 @@ import com.mdd.admin.vo.system.SystemAuthMenuVo;
|
|||
import com.mdd.common.entity.system.SystemAuthMenu;
|
||||
import com.mdd.common.mapper.system.SystemAuthMenuMapper;
|
||||
import com.mdd.common.util.ArrayUtils;
|
||||
import com.mdd.common.util.RedisUtils;
|
||||
import com.mdd.common.util.TimeUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
|
|||
|
|
@ -1,22 +1,16 @@
|
|||
package com.mdd.admin.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mdd.admin.config.AdminConfig;
|
||||
import com.mdd.admin.service.ISystemAuthPermService;
|
||||
import com.mdd.common.entity.system.SystemAuthMenu;
|
||||
import com.mdd.common.entity.system.SystemAuthPerm;
|
||||
import com.mdd.common.entity.system.SystemAuthRole;
|
||||
import com.mdd.common.mapper.system.SystemAuthMenuMapper;
|
||||
import com.mdd.common.mapper.system.SystemAuthPermMapper;
|
||||
import com.mdd.common.mapper.system.SystemAuthRoleMapper;
|
||||
import com.mdd.common.util.ArrayUtils;
|
||||
import com.mdd.common.util.RedisUtils;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -29,9 +23,6 @@ public class SystemAuthPermServiceImpl implements ISystemAuthPermService {
|
|||
@Resource
|
||||
SystemAuthPermMapper systemAuthPermMapper;
|
||||
|
||||
@Resource
|
||||
SystemAuthMenuMapper systemAuthMenuMapper;
|
||||
|
||||
@Resource
|
||||
SystemAuthRoleMapper systemAuthRoleMapper;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.lang.annotation.*;
|
|||
|
||||
/**
|
||||
* 免登录校验注解类
|
||||
* PS: 改注解无需实现类,由拦截器监听
|
||||
*/
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.lang.annotation.*;
|
|||
|
||||
/**
|
||||
* 免权限校验注解类
|
||||
* PS: 改注解无需实现类,由拦截器监听
|
||||
*/
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
|
|
|||
|
|
@ -6,13 +6,32 @@ import lombok.Data;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 通知记录实体
|
||||
*/
|
||||
@Data
|
||||
public class NoticeRecord implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value="id", type= IdType.AUTO)
|
||||
private Integer id; // 主键ID
|
||||
private Integer id;
|
||||
private Integer scene;
|
||||
private Integer userId;
|
||||
private String account;
|
||||
private String title;
|
||||
private String code;
|
||||
private String content;
|
||||
private String error;
|
||||
private Integer sender;
|
||||
private Integer receiver;
|
||||
private Integer status;
|
||||
private Integer isRead;
|
||||
private Integer isCaptcha;
|
||||
private Integer isDelete;
|
||||
private Long expireTime;
|
||||
private Long createTime;
|
||||
private Long updateTime;
|
||||
private Long deleteTime;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +0,0 @@
|
|||
package com.mdd.common.entity.system;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 系统短信日志实体
|
||||
*/
|
||||
@Data
|
||||
public class SystemLogSms implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value="id", type= IdType.AUTO)
|
||||
private Integer id; // 主键
|
||||
private String scene; // 场景编号
|
||||
private String mobile; // 手机号码
|
||||
private String content; // 发送内容
|
||||
private Integer status; // 发送状态:[0=发送中, 1=发送成功, 2=发送失败]
|
||||
private String results; // 发送结果
|
||||
private Long sendTime; // 发送时间
|
||||
private Long createTime; // 创建时间
|
||||
private Long updateTime; // 更新时间
|
||||
|
||||
}
|
||||
|
|
@ -5,10 +5,22 @@ package com.mdd.common.enums;
|
|||
*/
|
||||
public enum NoticeEnum {
|
||||
|
||||
SMS_LOGIN_CODE(101, "登录验证码"),
|
||||
SMS_BIND_MOBILE_CODE(102, "绑定手机验证码"),
|
||||
SMS_CHANGE_MOBILE_CODE(103, "变更手机验证码"),
|
||||
SMS_FORGOT_PASSWORD_CODE(104, "找回登录密码验证码");
|
||||
STATUS_WAIT(0, "等待"),
|
||||
STATUS_OK(1, "成功"),
|
||||
STATUS_FAIL(2, "失败"),
|
||||
|
||||
VIEW_UNREAD(0, "未读"),
|
||||
VIEW_READ(0, "已读"),
|
||||
|
||||
SENDER_SYS(1, "系统类型"),
|
||||
SENDER_SMS(2, "短信类型"),
|
||||
SENDER_MNP(3, "小程序类型"),
|
||||
SENDER_OA(4, "公众号类型"),
|
||||
|
||||
LOGIN_CODE(101, "登录验证码"),
|
||||
BIND_MOBILE_CODE(102, "绑定手机验证码"),
|
||||
CHANGE_MOBILE_CODE(103, "变更手机验证码"),
|
||||
FORGOT_PASSWORD_CODE(104, "找回登录密码验证码");
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package com.mdd.common.mapper.notice;
|
||||
|
||||
import com.mdd.common.core.basics.IBaseMapper;
|
||||
import com.mdd.common.entity.notice.NoticeRecord;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 通知记录Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface NoticeRecordMapper extends IBaseMapper<NoticeRecord> {
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package com.mdd.common.mapper.system;
|
||||
|
||||
import com.mdd.common.core.basics.IBaseMapper;
|
||||
import com.mdd.common.entity.system.SystemLogSms;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 系统短信日志Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemLogSmsMapper extends IBaseMapper<SystemLogSms> {
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package com.mdd.common.plugin.notice;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mdd.common.entity.notice.NoticeRecord;
|
||||
import com.mdd.common.entity.server.Sys;
|
||||
import com.mdd.common.mapper.notice.NoticeRecordMapper;
|
||||
import com.mdd.common.util.SpringUtils;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 通知验证码验证器
|
||||
*/
|
||||
public class NoticeCheck {
|
||||
|
||||
public static Boolean verify(Integer scene, Object code) {
|
||||
NoticeRecordMapper noticeRecordMapper = SpringUtils.getBean(NoticeRecordMapper.class);
|
||||
|
||||
NoticeRecord noticeRecord = noticeRecordMapper.selectOne(new QueryWrapper<NoticeRecord>()
|
||||
.eq("scene", scene)
|
||||
.eq("status", 1)
|
||||
.eq("is_read", 0)
|
||||
.eq("is_captcha", 1)
|
||||
.eq("is_delete", 0)
|
||||
.eq("code", code.toString().toLowerCase())
|
||||
.last("limit 1"));
|
||||
|
||||
if (StringUtils.isNull(noticeRecord)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean result = noticeRecord.getExpireTime() > (System.currentTimeMillis() / 1000);
|
||||
|
||||
noticeRecord.setIsRead(1);
|
||||
noticeRecord.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
noticeRecordMapper.updateById(noticeRecord);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,8 +4,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||
import com.mdd.common.entity.notice.NoticeSetting;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.notice.NoticeSettingMapper;
|
||||
import com.mdd.common.plugin.notice.engine.SmsNotice;
|
||||
import com.mdd.common.plugin.notice.engine.SmsNoticeHandle;
|
||||
import com.mdd.common.plugin.notice.template.SmsTemplate;
|
||||
import com.mdd.common.plugin.notice.vo.NoticeSmsVo;
|
||||
import com.mdd.common.util.SpringUtils;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
|
||||
|
|
@ -14,12 +15,12 @@ import com.mdd.common.util.StringUtils;
|
|||
*/
|
||||
public class NoticeDriver {
|
||||
|
||||
public void handle(NoticeParams noticeParams) {
|
||||
// 获取场景模板
|
||||
public static void handle(NoticeSmsVo noticeSmsVo) {
|
||||
// 场景模板
|
||||
NoticeSettingMapper noticeSettingMapper = SpringUtils.getBean(NoticeSettingMapper.class);
|
||||
NoticeSetting noticeSetting = noticeSettingMapper.selectOne(
|
||||
new QueryWrapper<NoticeSetting>()
|
||||
.eq("scene", noticeParams.getScene())
|
||||
.eq("scene", noticeSmsVo.getScene())
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
|
|
@ -29,10 +30,11 @@ public class NoticeDriver {
|
|||
|
||||
// 短信通知
|
||||
SmsTemplate smsTemplate = new SmsTemplate();
|
||||
smsTemplate.setName(noticeSetting.getName());
|
||||
smsTemplate.setType(noticeSetting.getType());
|
||||
smsTemplate.setParams(noticeSetting.getSmsNotice());
|
||||
if (StringUtils.isNotNull(smsTemplate.getStatus()) && smsTemplate.getStatus().equals(1)) {
|
||||
(new SmsNotice()).send(noticeParams, smsTemplate);
|
||||
(new SmsNoticeHandle()).send(noticeSmsVo, smsTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package com.mdd.common.plugin.notice.engine;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
public class OaNotice {
|
||||
public class MpNoticeHandle {
|
||||
|
||||
public void send(Map<String, String> config, Map<String, String> params, Map<String, String> smsTemplate) {
|
||||
|
||||
|
|
@ -2,7 +2,7 @@ package com.mdd.common.plugin.notice.engine;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
public class MpNotice {
|
||||
public class OaNoticeHandle {
|
||||
|
||||
public void send(Map<String, String> config, Map<String, String> params, Map<String, String> smsTemplate) {
|
||||
|
||||
|
|
@ -1,11 +1,16 @@
|
|||
package com.mdd.common.plugin.notice.engine;
|
||||
|
||||
import com.mdd.common.config.GlobalConfig;
|
||||
import com.mdd.common.plugin.notice.NoticeParams;
|
||||
import com.mdd.common.entity.notice.NoticeRecord;
|
||||
import com.mdd.common.enums.NoticeEnum;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.notice.NoticeRecordMapper;
|
||||
import com.mdd.common.plugin.notice.vo.NoticeSmsVo;
|
||||
import com.mdd.common.plugin.notice.template.SmsTemplate;
|
||||
import com.mdd.common.plugin.sms.SmsDriver;
|
||||
import com.mdd.common.util.ConfigUtils;
|
||||
import com.mdd.common.util.RedisUtils;
|
||||
import com.mdd.common.util.SpringUtils;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
|
@ -13,22 +18,24 @@ import java.util.*;
|
|||
/**
|
||||
* 短信通知
|
||||
*/
|
||||
public class SmsNotice {
|
||||
public class SmsNoticeHandle {
|
||||
|
||||
/**
|
||||
* 发送短信通知
|
||||
*
|
||||
* @author fzr
|
||||
* @param noticeParams 基础配置
|
||||
* @param noticeSmsVo 基础配置
|
||||
* @param smsTemplate 短信模板
|
||||
*/
|
||||
public void send(NoticeParams noticeParams, SmsTemplate smsTemplate) {
|
||||
String mobile = noticeParams.getMobile();
|
||||
Integer scene = noticeParams.getScene();
|
||||
public void send(NoticeSmsVo noticeSmsVo, SmsTemplate smsTemplate) {
|
||||
// 基础参数
|
||||
String mobile = noticeSmsVo.getMobile();
|
||||
Integer scene = noticeSmsVo.getScene();
|
||||
|
||||
// 模板参数
|
||||
Map<String, String> params = new LinkedHashMap<>();
|
||||
if (StringUtils.isNotNull(noticeParams.getParams())) {
|
||||
for (String s : noticeParams.getParams()) {
|
||||
if (StringUtils.isNotNull(noticeSmsVo.getParams())) {
|
||||
for (String s : noticeSmsVo.getParams()) {
|
||||
String[] arr = s.split(":");
|
||||
String key = arr[0].trim();
|
||||
String val = arr[1].trim();
|
||||
|
|
@ -36,14 +43,43 @@ public class SmsNotice {
|
|||
}
|
||||
}
|
||||
|
||||
// 消息记录
|
||||
NoticeRecordMapper noticeRecordMapper = SpringUtils.getBean(NoticeRecordMapper.class);
|
||||
int expire = StringUtils.isNull(noticeSmsVo.getExpire()) ? 0 : noticeSmsVo.getExpire();
|
||||
NoticeRecord noticeRecord = new NoticeRecord();
|
||||
noticeRecord.setScene(scene);
|
||||
noticeRecord.setUserId(0);
|
||||
noticeRecord.setAccount(mobile);
|
||||
noticeRecord.setTitle(smsTemplate.getName());
|
||||
noticeRecord.setCode(params.getOrDefault("code", ""));
|
||||
noticeRecord.setContent(this.getContent(params, smsTemplate.getContent()));
|
||||
noticeRecord.setReceiver(NoticeEnum.SENDER_SMS.getCode());
|
||||
noticeRecord.setStatus(NoticeEnum.STATUS_WAIT.getCode());
|
||||
noticeRecord.setIsRead(NoticeEnum.VIEW_UNREAD.getCode());
|
||||
noticeRecord.setIsCaptcha(smsTemplate.getType().equals(2) ? 1 : 0);
|
||||
noticeRecord.setExpireTime(expire + (System.currentTimeMillis() / 1000));
|
||||
noticeRecord.setCreateTime(System.currentTimeMillis() / 1000);
|
||||
noticeRecord.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
noticeRecordMapper.insert(noticeRecord);
|
||||
|
||||
// 消息发送
|
||||
if (StringUtils.isNotEmpty(mobile)) {
|
||||
(new SmsDriver())
|
||||
.setScene(scene)
|
||||
.setMobile(mobile)
|
||||
.setTemplateCode(smsTemplate.getTemplateId())
|
||||
.setTemplateParam(this.getSmsParams(params, smsTemplate.getContent()))
|
||||
.setSmsContent(this.getContent(params, smsTemplate.getContent()))
|
||||
.sendSms();
|
||||
try {
|
||||
(new SmsDriver())
|
||||
.setMobile(mobile)
|
||||
.setTemplateCode(smsTemplate.getTemplateId())
|
||||
.setTemplateParam(this.getSmsParams(params, smsTemplate.getContent()))
|
||||
.sendSms();
|
||||
|
||||
noticeRecord.setStatus(NoticeEnum.STATUS_OK.getCode());
|
||||
noticeRecord.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
noticeRecordMapper.updateById(noticeRecord);
|
||||
} catch (OperateException e) {
|
||||
noticeRecord.setError(e.getMsg());
|
||||
noticeRecord.setStatus(NoticeEnum.STATUS_FAIL.getCode());
|
||||
noticeRecord.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
noticeRecordMapper.updateById(noticeRecord);
|
||||
}
|
||||
|
||||
// 通知类型: [1=业务, 2=验证码]
|
||||
if (smsTemplate.getType().equals(2) && StringUtils.isNotNull(params.get("code"))) {
|
||||
|
|
@ -8,6 +8,9 @@ import java.util.Map;
|
|||
@Data
|
||||
public class SmsTemplate {
|
||||
|
||||
/** 通知名称 */
|
||||
private String name;
|
||||
|
||||
/** 通知类型: 1=业务,2=验证码 */
|
||||
private Integer type;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
package com.mdd.common.plugin.notice;
|
||||
package com.mdd.common.plugin.notice.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class NoticeParams {
|
||||
public class NoticeSmsVo {
|
||||
|
||||
private Integer scene;
|
||||
private String mobile;
|
||||
private Integer expire;
|
||||
private String[] params;
|
||||
|
||||
}
|
||||
|
|
@ -1,24 +1,17 @@
|
|||
package com.mdd.common.plugin.sms;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.mdd.common.entity.system.SystemLogSms;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.system.SystemLogSmsMapper;
|
||||
import com.mdd.common.plugin.sms.engine.AliSms;
|
||||
import com.mdd.common.plugin.sms.engine.TencentSms;
|
||||
import com.mdd.common.util.ConfigUtils;
|
||||
import com.mdd.common.util.SpringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class SmsDriver {
|
||||
|
||||
private final SystemLogSmsMapper systemLogSmsMapper;
|
||||
|
||||
private Integer scene; // 场景编码
|
||||
private String mobile; // 手机号码
|
||||
private String templateCode; // 短信模板
|
||||
private String smsContent = ""; // 短信内容
|
||||
private Map<String, String> templateParam; // 短信参数
|
||||
private final String engine; // 短信引擎
|
||||
private final Map<String, String> config; // 短信配置
|
||||
|
|
@ -29,7 +22,6 @@ public class SmsDriver {
|
|||
public SmsDriver() {
|
||||
this.engine = ConfigUtils.get("sms", "default", "");
|
||||
this.config = ConfigUtils.getMap("sms", this.engine);
|
||||
this.systemLogSmsMapper = SpringUtils.getBean(SystemLogSmsMapper.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -68,30 +60,6 @@ public class SmsDriver {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置模板内容
|
||||
*
|
||||
* @author fze
|
||||
* @param content 内容
|
||||
* @return SmsDriver
|
||||
*/
|
||||
public SmsDriver setSmsContent(String content) {
|
||||
this.smsContent = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置场景编码
|
||||
*
|
||||
* @author fzr
|
||||
* @param scene 场景编码
|
||||
* @return SmsDriver
|
||||
*/
|
||||
public SmsDriver setScene(Integer scene) {
|
||||
this.scene = scene;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信
|
||||
*
|
||||
|
|
@ -99,7 +67,6 @@ public class SmsDriver {
|
|||
*/
|
||||
public void sendSms() {
|
||||
String templateParam = JSON.toJSONString(this.templateParam);
|
||||
Integer logId = this.writeSmsLog();
|
||||
Integer sendResult = 0;
|
||||
String results = "";
|
||||
|
||||
|
|
@ -110,6 +77,7 @@ public class SmsDriver {
|
|||
.setTemplateId(this.templateCode)
|
||||
.setTemplateParams(templateParam)
|
||||
.send();
|
||||
|
||||
sendResult = aliSms.getSendResult();
|
||||
break;
|
||||
case "tencent":
|
||||
|
|
@ -122,47 +90,9 @@ public class SmsDriver {
|
|||
break;
|
||||
}
|
||||
|
||||
this.updateSmsLog(logId, sendResult, results);
|
||||
if (sendResult == 2) {
|
||||
throw new OperateException("短信发送失败");
|
||||
throw new OperateException(results);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入短信日志
|
||||
*
|
||||
* @author fzr
|
||||
*/
|
||||
private Integer writeSmsLog() {
|
||||
SystemLogSms model = new SystemLogSms();
|
||||
model.setMobile(this.mobile);
|
||||
model.setContent(this.smsContent);
|
||||
model.setResults("");
|
||||
model.setStatus(0);
|
||||
model.setCreateTime(System.currentTimeMillis() / 1000);
|
||||
model.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
systemLogSmsMapper.insert(model);
|
||||
return model.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新短信日志
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 主键
|
||||
* @param status 状态
|
||||
* @param result 结果
|
||||
*/
|
||||
private void updateSmsLog(Integer id, Integer status, String result) {
|
||||
SystemLogSms model = new SystemLogSms();
|
||||
model.setId(id);
|
||||
model.setScene(String.valueOf(this.scene));
|
||||
model.setMobile(this.mobile);
|
||||
model.setStatus(status);
|
||||
model.setResults(result);
|
||||
model.setSendTime(System.currentTimeMillis() / 1000);
|
||||
model.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
systemLogSmsMapper.updateById(model);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import org.springframework.web.bind.annotation.*;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
package com.mdd.front.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.entity.system.SystemLogSms;
|
||||
import com.mdd.common.entity.notice.NoticeRecord;
|
||||
import com.mdd.common.enums.NoticeEnum;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.system.SystemLogSmsMapper;
|
||||
import com.mdd.common.mapper.notice.NoticeRecordMapper;
|
||||
import com.mdd.common.plugin.notice.NoticeDriver;
|
||||
import com.mdd.common.plugin.notice.NoticeParams;
|
||||
import com.mdd.common.plugin.notice.vo.NoticeSmsVo;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
import com.mdd.common.util.ToolsUtils;
|
||||
import com.mdd.front.validate.commons.SmsValidate;
|
||||
|
|
@ -28,7 +28,7 @@ import java.util.Arrays;
|
|||
public class SmsController {
|
||||
|
||||
@Resource
|
||||
SystemLogSmsMapper systemLogSmsMapper;
|
||||
NoticeRecordMapper noticeRecordMapper;
|
||||
|
||||
/**
|
||||
* 发送短信
|
||||
|
|
@ -39,30 +39,28 @@ public class SmsController {
|
|||
*/
|
||||
@PostMapping("/send")
|
||||
public AjaxResult<Object> send(@Validated @RequestBody SmsValidate smsValidate) {
|
||||
Assert.notNull(smsValidate.getMobile(), "mobile参数缺失!");
|
||||
Assert.notNull(smsValidate.getScene(), "scene参数缺失!");
|
||||
|
||||
SystemLogSms systemLogSms = systemLogSmsMapper.selectOne(new QueryWrapper<SystemLogSms>()
|
||||
NoticeRecord noticeRecord = noticeRecordMapper.selectOne(new QueryWrapper<NoticeRecord>()
|
||||
.eq("mobile", smsValidate.getMobile())
|
||||
.eq("scene", smsValidate.getScene())
|
||||
.in("status", Arrays.asList(0, 1))
|
||||
.eq("status", Arrays.asList(NoticeEnum.STATUS_WAIT, NoticeEnum.STATUS_OK))
|
||||
.orderByDesc("id")
|
||||
.last("limit 1"));
|
||||
|
||||
if (StringUtils.isNotNull(systemLogSms)) {
|
||||
if (systemLogSms.getCreateTime() >= (System.currentTimeMillis() / 1000 - 60)){
|
||||
if (StringUtils.isNotNull(noticeRecord)) {
|
||||
if (noticeRecord.getCreateTime() >= (System.currentTimeMillis() / 1000 - 60)){
|
||||
throw new OperateException("操作频繁,请稍后再试!");
|
||||
}
|
||||
}
|
||||
|
||||
NoticeParams params = new NoticeParams()
|
||||
NoticeSmsVo params = new NoticeSmsVo()
|
||||
.setScene(smsValidate.getScene())
|
||||
.setMobile(smsValidate.getMobile())
|
||||
.setExpire(900)
|
||||
.setParams(new String[] {
|
||||
"code:" + ToolsUtils.randomInt(4)
|
||||
});
|
||||
|
||||
(new NoticeDriver()).handle(params);
|
||||
NoticeDriver.handle(params);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
|
|||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.mdd.common.config.GlobalConfig;
|
||||
import com.mdd.common.entity.user.User;
|
||||
import com.mdd.common.entity.user.UserAuth;
|
||||
import com.mdd.common.enums.ClientEnum;
|
||||
|
|
@ -12,6 +11,7 @@ import com.mdd.common.enums.NoticeEnum;
|
|||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.user.UserAuthMapper;
|
||||
import com.mdd.common.mapper.user.UserMapper;
|
||||
import com.mdd.common.plugin.notice.NoticeCheck;
|
||||
import com.mdd.common.util.*;
|
||||
import com.mdd.front.config.FrontConfig;
|
||||
import com.mdd.front.service.ILoginService;
|
||||
|
|
@ -128,15 +128,11 @@ public class LoginServiceImpl implements ILoginService {
|
|||
String code = params.get("code").toLowerCase();
|
||||
|
||||
// 校验验证码
|
||||
int typeCode = NoticeEnum.SMS_LOGIN_CODE.getCode();
|
||||
Object smsCode = RedisUtils.get(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
if (StringUtils.isNull(smsCode) || !smsCode.toString().equals(code)) {
|
||||
int sceneCode = NoticeEnum.LOGIN_CODE.getCode();
|
||||
if (!NoticeCheck.verify(sceneCode, code)) {
|
||||
throw new OperateException("验证码错误!");
|
||||
}
|
||||
|
||||
// 删除验证码
|
||||
RedisUtils.del(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
|
||||
// 查询手机号
|
||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.select("id,username,mobile,is_disable")
|
||||
|
|
@ -226,15 +222,11 @@ public class LoginServiceImpl implements ILoginService {
|
|||
String password = forgetPwdValidate.getPassword();
|
||||
|
||||
// 校验验证码
|
||||
int typeCode = NoticeEnum.SMS_FORGOT_PASSWORD_CODE.getCode();
|
||||
Object smsCode = RedisUtils.get(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
if (StringUtils.isNull(smsCode) || !smsCode.toString().equals(code)) {
|
||||
int sceneCode = NoticeEnum.FORGOT_PASSWORD_CODE.getCode();
|
||||
if (!NoticeCheck.verify(sceneCode, code)) {
|
||||
throw new OperateException("验证码错误!");
|
||||
}
|
||||
|
||||
// 删除验证码
|
||||
RedisUtils.del(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
|
||||
// 查询手机号
|
||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.select("id,username,mobile,is_disable")
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import com.mdd.common.enums.NoticeEnum;
|
|||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.user.UserAuthMapper;
|
||||
import com.mdd.common.mapper.user.UserMapper;
|
||||
import com.mdd.common.plugin.notice.NoticeCheck;
|
||||
import com.mdd.common.util.*;
|
||||
import com.mdd.front.LikeFrontThreadLocal;
|
||||
import com.mdd.front.service.IUserService;
|
||||
|
|
@ -214,9 +215,8 @@ public class UserServiceImpl implements IUserService {
|
|||
String code = mobileValidate.getCode().toLowerCase();
|
||||
|
||||
// 校验验证码
|
||||
int typeCode = type.equals("bind") ? NoticeEnum.SMS_BIND_MOBILE_CODE.getCode() : NoticeEnum.SMS_CHANGE_MOBILE_CODE.getCode() ;
|
||||
Object smsCode = RedisUtils.get(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||
if (StringUtils.isNull(smsCode) || !smsCode.toString().equals(code)) {
|
||||
int sceneCode = type.equals("bind") ? NoticeEnum.BIND_MOBILE_CODE.getCode() : NoticeEnum.CHANGE_MOBILE_CODE.getCode() ;
|
||||
if (!NoticeCheck.verify(sceneCode, code)) {
|
||||
throw new OperateException("验证码错误!");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue