Commit 94e17977 by fengshuonan

增加阿里云短信的常量配置

parent 7e184856
...@@ -16,7 +16,7 @@ USE guns; ...@@ -16,7 +16,7 @@ USE guns;
Target Server Version : 50724 Target Server Version : 50724
File Encoding : 65001 File Encoding : 65001
Date: 25/06/2019 09:21:13 Date: 25/06/2019 13:20:39
*/ */
SET NAMES utf8mb4; SET NAMES utf8mb4;
...@@ -43,7 +43,7 @@ CREATE TABLE `database_info` ( ...@@ -43,7 +43,7 @@ CREATE TABLE `database_info` (
-- Records of database_info -- Records of database_info
-- ---------------------------- -- ----------------------------
BEGIN; BEGIN;
INSERT INTO `database_info` VALUES (1143320353162928129, 'master', 'com.mysql.cj.jdbc.Driver', 'root', 'root', 'jdbc:mysql://127.0.0.1:3306/guns?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT', '主数据源,项目启动数据源!', '2019-06-25 08:49:48'); INSERT INTO `database_info` VALUES (1143387804278038529, 'master', 'com.mysql.cj.jdbc.Driver', 'root', 'root', 'jdbc:mysql://127.0.0.1:3306/guns?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT', '主数据源,项目启动数据源!', '2019-06-25 13:17:50');
COMMIT; COMMIT;
-- ---------------------------- -- ----------------------------
...@@ -95,6 +95,11 @@ CREATE TABLE `sys_config` ( ...@@ -95,6 +95,11 @@ CREATE TABLE `sys_config` (
-- ---------------------------- -- ----------------------------
BEGIN; BEGIN;
INSERT INTO `sys_config` VALUES (1143324237579165697, '验证码开关', 'GUNS_KAPTCHA_OPEN', 'Y', 1106120265689055233, 'DISABLE', '是否开启验证码', '2019-06-24 12:46:43', 1, '2019-06-25 09:04:42', 1); INSERT INTO `sys_config` VALUES (1143324237579165697, '验证码开关', 'GUNS_KAPTCHA_OPEN', 'Y', 1106120265689055233, 'DISABLE', '是否开启验证码', '2019-06-24 12:46:43', 1, '2019-06-25 09:04:42', 1);
INSERT INTO `sys_config` VALUES (1143386834613694465, '阿里云短信的keyId', 'GUNS_SMS_ACCESSKEY_ID', 'N', NULL, 'xxxkey', '阿里云短信的密钥key', '2019-06-25 13:13:59', 1, '2019-06-25 13:19:21', 1);
INSERT INTO `sys_config` VALUES (1143386953933254657, '阿里云短信的secret', 'GUNS_SMS_ACCESSKEY_SECRET', 'N', NULL, 'xxxsecret', '阿里云短信的secret', '2019-06-25 13:14:28', 1, NULL, NULL);
INSERT INTO `sys_config` VALUES (1143387023449649154, '阿里云短信的签名', 'GUNS_SMS_SIGN_NAME', 'N', NULL, 'xxxsign', '阿里云短信的签名', '2019-06-25 13:14:44', 1, NULL, NULL);
INSERT INTO `sys_config` VALUES (1143387131109044225, '阿里云短信登录的模板号', 'GUNS_SMS_LOGIN_TEMPLATE_CODE', 'N', NULL, 'SMS_XXXXXX', '阿里云短信登录的模板号', '2019-06-25 13:15:10', 1, NULL, NULL);
INSERT INTO `sys_config` VALUES (1143387225019510785, '验证码短信失效时间', 'GUNS_SMS_INVALIDATE_MINUTES', 'N', NULL, '2', '验证码短信失效时间', '2019-06-25 13:15:32', 1, NULL, NULL);
COMMIT; COMMIT;
-- ---------------------------- -- ----------------------------
......
package cn.stylefeng.guns.sms.config; package cn.stylefeng.guns.sms.config;
import cn.stylefeng.guns.sms.config.properties.AliyunSmsProperties;
import cn.stylefeng.guns.sms.core.cache.impl.MapSignManager; import cn.stylefeng.guns.sms.core.cache.impl.MapSignManager;
import cn.stylefeng.guns.sms.core.sms.service.AliyunSmsManager; import cn.stylefeng.guns.sms.core.sms.service.AliyunSmsManager;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -17,18 +15,6 @@ import org.springframework.context.annotation.Configuration; ...@@ -17,18 +15,6 @@ import org.springframework.context.annotation.Configuration;
public class SmsAutoConfiguration { public class SmsAutoConfiguration {
/** /**
* 阿里云短信发送的配置
*
* @author fengshuonan
* @Date 2018/7/6 下午3:24
*/
@Bean
@ConfigurationProperties(prefix = "aliyun.sms")
public AliyunSmsProperties aliyunSmsProperties() {
return new AliyunSmsProperties();
}
/**
* 短信发送管理器 * 短信发送管理器
* *
* @author fengshuonan * @author fengshuonan
......
package cn.stylefeng.guns.sms.core.sms.service; package cn.stylefeng.guns.sms.core.sms.service;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.stylefeng.guns.sms.config.properties.AliyunSmsProperties; import cn.stylefeng.guns.base.consts.ConstantsContext;
import cn.stylefeng.guns.base.sms.AliyunSmsProperties;
import cn.stylefeng.guns.sms.core.cache.MultiSignManager; import cn.stylefeng.guns.sms.core.cache.MultiSignManager;
import cn.stylefeng.guns.sms.core.enums.SmsResultEnum; import cn.stylefeng.guns.sms.core.enums.SmsResultEnum;
import cn.stylefeng.guns.sms.core.exception.SmsException; import cn.stylefeng.guns.sms.core.exception.SmsException;
...@@ -40,9 +41,6 @@ import static cn.hutool.core.date.DatePattern.PURE_DATE_PATTERN; ...@@ -40,9 +41,6 @@ import static cn.hutool.core.date.DatePattern.PURE_DATE_PATTERN;
public class AliyunSmsManager implements SmsManager { public class AliyunSmsManager implements SmsManager {
@Autowired @Autowired
private AliyunSmsProperties aliyunSmsProperties;
@Autowired
private MultiSignManager multiSignManager; private MultiSignManager multiSignManager;
@Override @Override
...@@ -50,6 +48,9 @@ public class AliyunSmsManager implements SmsManager { ...@@ -50,6 +48,9 @@ public class AliyunSmsManager implements SmsManager {
log.info("开始发送阿里云短信,手机号是:" + phoneNumber + ",模板号是:" + templateCode + ",参数是:" + JSON.toJSONString(params)); log.info("开始发送阿里云短信,手机号是:" + phoneNumber + ",模板号是:" + templateCode + ",参数是:" + JSON.toJSONString(params));
//获取发送短信的配置
AliyunSmsProperties aliyunSmsProperties = ConstantsContext.getAliyunSmsProperties();
//检验参数是否合法 //检验参数是否合法
assertSendSmsParams(phoneNumber, templateCode, params, aliyunSmsProperties); assertSendSmsParams(phoneNumber, templateCode, params, aliyunSmsProperties);
...@@ -143,6 +144,8 @@ public class AliyunSmsManager implements SmsManager { ...@@ -143,6 +144,8 @@ public class AliyunSmsManager implements SmsManager {
//初始化ascClient需要的几个参数 //初始化ascClient需要的几个参数
final String product = "Dysmsapi"; //短信API产品名称(短信产品名固定,无需修改) final String product = "Dysmsapi"; //短信API产品名称(短信产品名固定,无需修改)
final String domain = "dysmsapi.aliyuncs.com"; //短信API产品域名(接口地址固定,无需修改) final String domain = "dysmsapi.aliyuncs.com"; //短信API产品域名(接口地址固定,无需修改)
AliyunSmsProperties aliyunSmsProperties = ConstantsContext.getAliyunSmsProperties();
final String accessKeyId = aliyunSmsProperties.getAccessKeyId(); final String accessKeyId = aliyunSmsProperties.getAccessKeyId();
final String accessKeySecret = aliyunSmsProperties.getAccessKeySecret(); final String accessKeySecret = aliyunSmsProperties.getAccessKeySecret();
...@@ -231,7 +234,8 @@ public class AliyunSmsManager implements SmsManager { ...@@ -231,7 +234,8 @@ public class AliyunSmsManager implements SmsManager {
* @Date 2018/8/13 21:23 * @Date 2018/8/13 21:23
*/ */
private String getSmsSign(String phone) { private String getSmsSign(String phone) {
String signName = this.aliyunSmsProperties.getSignName(); AliyunSmsProperties aliyunSmsProperties = ConstantsContext.getAliyunSmsProperties();
String signName = aliyunSmsProperties.getSignName();
//如果是单个签名就用一个签名发 //如果是单个签名就用一个签名发
if (!signName.contains(",")) { if (!signName.contains(",")) {
......
package cn.stylefeng.guns.sms.modular.service; package cn.stylefeng.guns.sms.modular.service;
import cn.stylefeng.guns.sms.config.properties.AliyunSmsProperties; import cn.stylefeng.guns.base.sms.AliyunSmsProperties;
import cn.stylefeng.guns.sms.core.enums.SmsResultEnum; import cn.stylefeng.guns.sms.core.enums.SmsResultEnum;
import cn.stylefeng.guns.sms.core.enums.SmsSendStatus; import cn.stylefeng.guns.sms.core.enums.SmsSendStatus;
import cn.stylefeng.guns.sms.core.enums.SmsVerifyResult; import cn.stylefeng.guns.sms.core.enums.SmsVerifyResult;
......
package cn.stylefeng.guns.base.consts; package cn.stylefeng.guns.base.consts;
import cn.stylefeng.guns.base.enums.CommonStatus; import cn.stylefeng.guns.base.enums.CommonStatus;
import cn.stylefeng.guns.base.sms.AliyunSmsProperties;
import cn.stylefeng.roses.core.util.ToolUtil; import cn.stylefeng.roses.core.util.ToolUtil;
import java.util.Map; import java.util.Map;
...@@ -53,7 +54,7 @@ public class ConstantsContext { ...@@ -53,7 +54,7 @@ public class ConstantsContext {
} }
/** /**
* 获取开关 * 获取验证码开关
*/ */
public static Boolean getKaptchaOpen() { public static Boolean getKaptchaOpen() {
String gunsKaptchaOpen = (String) CONSTNTS_HOLDER.get("GUNS_KAPTCHA_OPEN"); String gunsKaptchaOpen = (String) CONSTNTS_HOLDER.get("GUNS_KAPTCHA_OPEN");
...@@ -63,4 +64,23 @@ public class ConstantsContext { ...@@ -63,4 +64,23 @@ public class ConstantsContext {
return false; return false;
} }
} }
/**
* 获取短信的配置
*/
public static AliyunSmsProperties getAliyunSmsProperties() {
String gunsSmsAccesskeyId = (String) CONSTNTS_HOLDER.get("GUNS_SMS_ACCESSKEY_ID");
String gunsSmsAccesskeySecret = (String) CONSTNTS_HOLDER.get("GUNS_SMS_ACCESSKEY_SECRET");
String gunsSmsSignName = (String) CONSTNTS_HOLDER.get("GUNS_SMS_SIGN_NAME");
String gunsSmsLoginTemplateCode = (String) CONSTNTS_HOLDER.get("GUNS_SMS_LOGIN_TEMPLATE_CODE");
String gunsSmsInvalidateMinutes = (String) CONSTNTS_HOLDER.get("GUNS_SMS_INVALIDATE_MINUTES");
AliyunSmsProperties aliyunSmsProperties = new AliyunSmsProperties();
aliyunSmsProperties.setAccessKeyId(gunsSmsAccesskeyId);
aliyunSmsProperties.setAccessKeySecret(gunsSmsAccesskeySecret);
aliyunSmsProperties.setSignName(gunsSmsSignName);
aliyunSmsProperties.setLoginTemplateCode(gunsSmsLoginTemplateCode);
aliyunSmsProperties.setInvalidateMinutes(Integer.valueOf(gunsSmsInvalidateMinutes));
return aliyunSmsProperties;
}
} }
package cn.stylefeng.guns.sms.config.properties; package cn.stylefeng.guns.base.sms;
import lombok.Data; import lombok.Data;
......
...@@ -41,13 +41,6 @@ spring: ...@@ -41,13 +41,6 @@ spring:
username: sn93@qq.com username: sn93@qq.com
password: xxxpassword password: xxxpassword
# 阿里云短信发送配置
aliyun:
sms:
accessKeyId: xxxkey
accessKeySecret: xxxSecret
signName: mySignName
# 邮件发送(改为自己的账号) # 邮件发送(改为自己的账号)
mail: mail:
from: sn93@qq.com from: sn93@qq.com
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment