Browse Source

message模块,发送手机验证码

dev
yujintao 6 years ago
parent
commit
956b3aadf8
  1. 1
      esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/constant/NumConstant.java
  2. 12
      esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/RedisKeys.java
  3. 28
      esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/RedisUtils.java
  4. 1
      esua-epdc/epdc-gateway/src/main/resources/application.yml
  5. 4
      esua-epdc/epdc-module/epdc-message/epdc-message-server/pom.xml
  6. 23
      esua-epdc/epdc-module/epdc-message/epdc-message-server/src/main/java/com/elink/esua/epdc/controller/SmsController.java
  7. 52
      esua-epdc/epdc-module/epdc-message/epdc-message-server/src/main/java/com/elink/esua/epdc/redis/SmsRedis.java
  8. 17
      esua-epdc/epdc-module/epdc-message/epdc-message-server/src/main/java/com/elink/esua/epdc/service/SysSmsService.java
  9. 25
      esua-epdc/epdc-module/epdc-message/epdc-message-server/src/main/java/com/elink/esua/epdc/service/impl/SysSmsServiceImpl.java

1
esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/constant/NumConstant.java

@ -14,6 +14,7 @@ public interface NumConstant {
int TWO = 2;
int THREE = 3;
int FOUR = 4;
int SIX = 6;
int TEN = 10;
int FIFTEEN = 15;

12
esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/RedisKeys.java

@ -102,4 +102,16 @@ public class RedisKeys {
public static String getSimpleDictKey(String dictType) {
return rootPrefix.concat("config:simple:dict:").concat(dictType);
}
/**
* 拼接手机验证码key
*
* @param phone
* @return java.lang.String
* @author yujintao
* @date 2019/9/6 17:03
*/
public static String getPhoneSmsCodeKey(String phone) {
return rootPrefix.concat("phone:sms:code:").concat(phone);
}
}

28
esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/RedisUtils.java

@ -29,13 +29,33 @@ public class RedisUtils {
@Autowired
private RedisTemplate<String, Object> redisTemplate;
/** 默认过期时长为24小时,单位:秒 */
/**
* 默认过期时长为24小时单位
*/
public final static long DEFAULT_EXPIRE = 60 * 60 * 24L;
/** 过期时长为1小时,单位:秒 */
/**
* 过期时长为1小时单位
*/
public final static long HOUR_ONE_EXPIRE = 60 * 60 * 1L;
/** 过期时长为6小时,单位:秒 */
/**
* 过期时长为6小时单位
*/
public final static long HOUR_SIX_EXPIRE = 60 * 60 * 6L;
/** 不设置过期时长 */
/**
* 过期时长为5分钟单位
*/
public final static long MINUTE_FIVE_EXPIRE = 60 * 5 * 1L;
/**
* 过期时长为10分钟单位
*/
public final static long MINUTE_TEN_EXPIRE = 60 * 10 * 1L;
/**
* 过期时长为30分钟单位
*/
public final static long MINUTE_THIRTY_EXPIRE = 60 * 30 * 1L;
/**
* 不设置过期时长
*/
public final static long NOT_EXPIRE = -1L;
public void set(String key, Object value, long expire) {

1
esua-epdc/epdc-gateway/src/main/resources/application.yml

@ -179,6 +179,7 @@ renren:
- /activiti/modeler.html
- /activiti/service/**
- /activiti/editor-app/**
- /message/sms/sendCode #发送验证码
- /heart/**

4
esua-epdc/epdc-module/epdc-message/epdc-message-server/pom.xml

@ -124,7 +124,7 @@
<![CDATA[jdbc:mysql://47.104.224.45:3308/esua_epdc_admin?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai]]>
</spring.datasource.druid.url>
<spring.datasource.druid.username>epdc</spring.datasource.druid.username>
<spring.datasource.druid.password>elink888</spring.datasource.druid.password>
<spring.datasource.druid.password>elink833066</spring.datasource.druid.password>
<nacos.register-enabled>false</nacos.register-enabled>
<nacos.server-addr>47.104.224.45:8848</nacos.server-addr>
@ -147,7 +147,7 @@
<![CDATA[jdbc:mysql://47.104.224.45:3308/esua_epdc_admin?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai]]>
</spring.datasource.druid.url>
<spring.datasource.druid.username>epdc</spring.datasource.druid.username>
<spring.datasource.druid.password>elink888</spring.datasource.druid.password>
<spring.datasource.druid.password>elink833066</spring.datasource.druid.password>
<nacos.register-enabled>false</nacos.register-enabled>
<nacos.server-addr>47.104.224.45:8848</nacos.server-addr>

23
esua-epdc/epdc-module/epdc-message/epdc-message-server/src/main/java/com/elink/esua/epdc/controller/SmsController.java

@ -1,8 +1,8 @@
/**
* Copyright (c) 2018 人人开源 All rights reserved.
*
* <p>
* https://www.renren.io
*
* <p>
* 版权所有侵权必究
*/
@ -19,7 +19,6 @@ import com.elink.esua.epdc.commons.tools.validator.group.AliyunGroup;
import com.elink.esua.epdc.commons.tools.validator.group.QcloudGroup;
import com.elink.esua.epdc.dto.SysSmsDTO;
import com.elink.esua.epdc.enums.PlatformEnum;
import com.elink.esua.epdc.remote.ParamsRemoteService;
import com.elink.esua.epdc.service.SysSmsService;
import com.elink.esua.epdc.sms.SmsConfig;
import com.elink.esua.epdc.utils.ModuleConstant;
@ -27,6 +26,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
@ -107,6 +107,23 @@ public class SmsController {
return new Result();
}
/**
* 发送手机验证码
*
* @param mobile
* @return com.elink.esua.epdc.commons.tools.utils.Result
* @author yujintao
* @date 2019/9/6 16:50
*/
@GetMapping("sendCode")
public Result sendCode(String mobile) {
if (StringUtils.isBlank(mobile)) {
return new Result().error();
}
sysSmsService.sendCode(mobile);
return new Result();
}
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")

52
esua-epdc/epdc-module/epdc-message/epdc-message-server/src/main/java/com/elink/esua/epdc/redis/SmsRedis.java

@ -0,0 +1,52 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.redis;
import com.elink.esua.epdc.commons.tools.redis.RedisKeys;
import com.elink.esua.epdc.commons.tools.redis.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 区划信息表
*
* @author yujintao yujintao@elink-cn.com
* @since v1.0.0 2019-05-08
*/
@Component
public class SmsRedis {
@Autowired
private RedisUtils redisUtils;
/**
* 缓存短信验证码十分钟过期
*
* @param phone 手机号
* @param smsCode 验证码
* @return void
* @author yujintao
* @date 2019/9/6 17:01
*/
public void setSmsCode(String phone, String smsCode) {
String key = RedisKeys.getPhoneSmsCodeKey(phone);
redisUtils.set(key, smsCode, RedisUtils.MINUTE_TEN_EXPIRE);
}
}

17
esua-epdc/epdc-module/epdc-message/epdc-message-server/src/main/java/com/elink/esua/epdc/service/SysSmsService.java

@ -1,14 +1,13 @@
/**
* Copyright (c) 2018 人人开源 All rights reserved.
*
* <p>
* https://www.renren.io
*
* <p>
* 版权所有侵权必究
*/
package com.elink.esua.epdc.service;
import com.elink.esua.epdc.commons.mybatis.service.BaseService;
import com.elink.esua.epdc.commons.mybatis.service.BaseService;
import com.elink.esua.epdc.commons.tools.page.PageData;
import com.elink.esua.epdc.dto.SysSmsDTO;
@ -28,6 +27,7 @@ public interface SysSmsService extends BaseService<SysSmsEntity> {
/**
* 发送短信
*
* @param mobile 手机号
* @param params 短信参数
*/
@ -35,11 +35,22 @@ public interface SysSmsService extends BaseService<SysSmsEntity> {
/**
* 保存短信发送记录
*
* @param platform 平台
* @param mobile 手机号
* @param params 短信参数
* @param status 发送状态
*/
void save(Integer platform, String mobile, LinkedHashMap<String, String> params, Integer status);
/**
* 发送手机短信验证吗
*
* @param mobile 手机号
* @return void
* @author yujintao
* @date 2019/9/6 16:48
*/
void sendCode(String mobile);
}

25
esua-epdc/epdc-module/epdc-message/epdc-message-server/src/main/java/com/elink/esua/epdc/service/impl/SysSmsServiceImpl.java

@ -1,32 +1,34 @@
/**
* Copyright (c) 2018 人人开源 All rights reserved.
*
* <p>
* https://www.renren.io
*
* <p>
* 版权所有侵权必究
*/
package com.elink.esua.epdc.service.impl;
import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl;
import com.elink.esua.epdc.commons.tools.constant.NumConstant;
import com.elink.esua.epdc.commons.tools.exception.ErrorCode;
import com.elink.esua.epdc.commons.tools.utils.RandomUtil;
import com.elink.esua.epdc.exception.ModuleErrorCode;
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl;
import com.elink.esua.epdc.commons.tools.constant.Constant;
import com.elink.esua.epdc.commons.tools.exception.ErrorCode;
import com.elink.esua.epdc.commons.tools.exception.RenException;
import com.elink.esua.epdc.commons.tools.page.PageData;
import com.elink.esua.epdc.dao.SysSmsDao;
import com.elink.esua.epdc.dto.SysSmsDTO;
import com.elink.esua.epdc.entity.SysSmsEntity;
import com.elink.esua.epdc.exception.ModuleErrorCode;
import com.elink.esua.epdc.redis.SmsRedis;
import com.elink.esua.epdc.service.SysSmsService;
import com.elink.esua.epdc.sms.AbstractSmsService;
import com.elink.esua.epdc.sms.SmsFactory;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.LinkedHashMap;
@ -35,6 +37,9 @@ import java.util.Map;
@Service
public class SysSmsServiceImpl extends BaseServiceImpl<SysSmsDao, SysSmsEntity> implements SysSmsService {
@Autowired
private SmsRedis smsRedis;
@Override
public PageData<SysSmsDTO> page(Map<String, Object> params) {
IPage<SysSmsEntity> page = baseDao.selectPage(
@ -74,6 +79,16 @@ public class SysSmsServiceImpl extends BaseServiceImpl<SysSmsDao, SysSmsEntity>
service.sendSms(mobile, map);
}
@Override
public void sendCode(String mobile) {
String smsCode = RandomUtil.getNewRandomCode(NumConstant.SIX);
// 缓存手机验证码
smsRedis.setSmsCode(mobile, smsCode);
JSONObject param = new JSONObject();
param.put("code", smsCode);
this.send(mobile, param.toJSONString());
}
@Override
public void save(Integer platform, String mobile, LinkedHashMap<String, String> params, Integer status) {
SysSmsEntity sms = new SysSmsEntity();

Loading…
Cancel
Save