parent
1fb255174c
commit
ab4356c846
@ -0,0 +1,113 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* 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
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.opsli.core.options;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import opsli.plugins.crypto.enums.CryptoAsymmetricType;
|
||||||
|
import opsli.plugins.crypto.enums.CryptoSymmetricType;
|
||||||
|
import opsli.plugins.crypto.model.CryptoAsymmetric;
|
||||||
|
import org.opsli.common.utils.WrapperUtil;
|
||||||
|
import org.opsli.common.annotation.OptionDict;
|
||||||
|
import org.opsli.core.utils.OptionsUtil;
|
||||||
|
import org.opsli.core.utils.ValidatorUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密参数
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2020-09-19 20:03
|
||||||
|
*/
|
||||||
|
public enum CryptoConfigFactory {
|
||||||
|
|
||||||
|
/** 实例对象 */
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得配置信息
|
||||||
|
* @return LocalConfig
|
||||||
|
*/
|
||||||
|
public CryptoAsymmetric getCryptoSymmetric() {
|
||||||
|
CryptoSymmetricOption option = new CryptoSymmetricOption();
|
||||||
|
// 获得缓存参数配置
|
||||||
|
OptionsUtil.getOptionByBean(option);
|
||||||
|
// 验证配置
|
||||||
|
ValidatorUtil.verify(option);
|
||||||
|
|
||||||
|
// 转化对象
|
||||||
|
return WrapperUtil.transformInstance(option, CryptoAsymmetric.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得配置信息
|
||||||
|
* @return LocalConfig
|
||||||
|
*/
|
||||||
|
public CryptoAsymmetric getCryptoAsymmetric() {
|
||||||
|
CryptoAsymmetricOption option = new CryptoAsymmetricOption();
|
||||||
|
// 获得缓存参数配置
|
||||||
|
OptionsUtil.getOptionByBean(option);
|
||||||
|
// 验证配置
|
||||||
|
ValidatorUtil.verify(option);
|
||||||
|
|
||||||
|
// 转化对象
|
||||||
|
return WrapperUtil.transformInstance(option, CryptoAsymmetric.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// =======================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对称加密
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2021年5月17日15:59:52
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class CryptoSymmetricOption {
|
||||||
|
|
||||||
|
/** 加解密类别 */
|
||||||
|
@OptionDict("crypto_symmetric")
|
||||||
|
private CryptoSymmetricType cryptoType;
|
||||||
|
|
||||||
|
/** 私钥 */
|
||||||
|
@OptionDict("crypto_symmetric_private_key")
|
||||||
|
private String privateKey;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 非对称加密
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2021年5月17日15:59:52
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class CryptoAsymmetricOption {
|
||||||
|
|
||||||
|
/** 加解密类别 */
|
||||||
|
@OptionDict("crypto_asymmetric")
|
||||||
|
private CryptoAsymmetricType cryptoType;
|
||||||
|
|
||||||
|
/** 公钥 */
|
||||||
|
@OptionDict("crypto_asymmetric_public_key")
|
||||||
|
private String publicKey;
|
||||||
|
|
||||||
|
/** 私钥 */
|
||||||
|
@OptionDict("crypto_asymmetric_private_key")
|
||||||
|
private String privateKey;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,106 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* 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
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.opsli.core.options;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.opsli.common.annotation.OptionDict;
|
||||||
|
import org.opsli.common.annotation.validator.Validator;
|
||||||
|
import org.opsli.common.enums.ValidatorType;
|
||||||
|
import org.opsli.common.utils.WrapperUtil;
|
||||||
|
import org.opsli.core.utils.OptionsUtil;
|
||||||
|
import org.opsli.core.utils.ValidatorUtil;
|
||||||
|
import org.opsli.plugins.email.conf.EmailConfig;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮件配置
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2020-09-19 20:03
|
||||||
|
*/
|
||||||
|
public enum EmailConfigFactory {
|
||||||
|
|
||||||
|
/** 实例对象 */
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得配置信息
|
||||||
|
* @return LocalConfig
|
||||||
|
*/
|
||||||
|
public EmailConfig getConfig() {
|
||||||
|
EmailConfigOption option = new EmailConfigOption();
|
||||||
|
// 获得缓存参数配置
|
||||||
|
OptionsUtil.getOptionByBean(option);
|
||||||
|
// 验证配置
|
||||||
|
ValidatorUtil.verify(option);
|
||||||
|
|
||||||
|
// 转化对象
|
||||||
|
return WrapperUtil.transformInstance(option, EmailConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// =======================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮件配置
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class EmailConfigOption implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** SMTP地址 */
|
||||||
|
@ApiModelProperty(value = "SMTP地址")
|
||||||
|
@Validator({ValidatorType.IS_NOT_NULL})
|
||||||
|
@OptionDict("email_smtp")
|
||||||
|
private String smtp;
|
||||||
|
|
||||||
|
/** SMTP端口 */
|
||||||
|
@ApiModelProperty(value = "SMTP端口")
|
||||||
|
@Validator({ValidatorType.IS_NOT_NULL})
|
||||||
|
@OptionDict("email_port")
|
||||||
|
private Integer port;
|
||||||
|
|
||||||
|
/** 开启SSL认证 */
|
||||||
|
@ApiModelProperty(value = "开启SSL认证")
|
||||||
|
@Validator({ValidatorType.IS_NOT_NULL})
|
||||||
|
@OptionDict("email_ssl_enable")
|
||||||
|
private String sslEnable;
|
||||||
|
|
||||||
|
/** 邮箱账号 */
|
||||||
|
@ApiModelProperty(value = "邮箱账号")
|
||||||
|
@Validator({ValidatorType.IS_NOT_NULL})
|
||||||
|
@OptionDict("email_account")
|
||||||
|
private String account;
|
||||||
|
|
||||||
|
/** 邮箱密码 */
|
||||||
|
@ApiModelProperty(value = "邮箱密码")
|
||||||
|
@Validator({ValidatorType.IS_NOT_NULL})
|
||||||
|
@OptionDict("email_password")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/** 发件人 */
|
||||||
|
@ApiModelProperty(value = "发件人")
|
||||||
|
@Validator({ValidatorType.IS_NOT_NULL})
|
||||||
|
@OptionDict("email_addresser")
|
||||||
|
private String addresser;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,63 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
|
||||||
* <p>
|
|
||||||
* 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
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
package org.opsli.plugins.email.enums;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Email 参数类型
|
|
||||||
*
|
|
||||||
* @author Parker
|
|
||||||
* @date 2020-09-19 20:03
|
|
||||||
*/
|
|
||||||
public enum EmailType {
|
|
||||||
|
|
||||||
/** SMTP 服务 */
|
|
||||||
EMAIL_SMTP("email_smtp", "SMTP地址"),
|
|
||||||
EMAIL_PORT("email_port", "SMTP端口"),
|
|
||||||
EMAIL_SSL_ENABLE("email_ssl_enable", "开启SSL认证"),
|
|
||||||
EMAIL_ACCOUNT("email_account", "邮箱账号"),
|
|
||||||
EMAIL_PASSWORD("email_password", "邮箱账号密码"),
|
|
||||||
EMAIL_ADDRESSER("email_addresser", "发件人"),
|
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
private final String code;
|
|
||||||
private final String desc;
|
|
||||||
|
|
||||||
public static EmailType getType(String cacheType) {
|
|
||||||
EmailType[] types = values();
|
|
||||||
for (EmailType type : types) {
|
|
||||||
if (type.code.equalsIgnoreCase(cacheType)) {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCode() {
|
|
||||||
return this.code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDesc() {
|
|
||||||
return this.desc;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =================
|
|
||||||
|
|
||||||
EmailType(final String code, final String desc) {
|
|
||||||
this.code = code;
|
|
||||||
this.desc = desc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,102 +0,0 @@
|
|||||||
package org.opsli.plugins.email.service.impl;
|
|
||||||
|
|
||||||
import cn.hutool.core.convert.Convert;
|
|
||||||
import cn.hutool.extra.mail.MailAccount;
|
|
||||||
import cn.hutool.extra.mail.MailUtil;
|
|
||||||
import org.opsli.api.wrapper.system.options.OptionsModel;
|
|
||||||
import org.opsli.common.enums.DictType;
|
|
||||||
import org.opsli.core.utils.OptionsUtil;
|
|
||||||
import org.opsli.core.utils.ValidatorUtil;
|
|
||||||
import org.opsli.plugins.email.enums.EmailType;
|
|
||||||
import org.opsli.plugins.email.service.IEmailService;
|
|
||||||
import org.opsli.plugins.email.wrapper.EmailModel;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 邮件 接口实现类
|
|
||||||
*
|
|
||||||
* @author Parker
|
|
||||||
* @date 2020-09-19 20:03
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class EmailServiceImpl implements IEmailService {
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String send(String to, String subject, String content) {
|
|
||||||
// 发送邮件
|
|
||||||
return this.send(Collections.singletonList(to), subject ,content);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String send(Collection<String> tos, String subject, String content) {
|
|
||||||
// 发送邮件
|
|
||||||
return this.send(tos, subject ,content, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String send(String to, String subject, String content, boolean isHtml) {
|
|
||||||
// 发送邮件
|
|
||||||
return this.send(Collections.singletonList(to), subject ,content, isHtml);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String send(Collection<String> tos, String subject, String content, boolean isHtml) {
|
|
||||||
|
|
||||||
// 校验发送邮件数据是否正确
|
|
||||||
for (String to : tos) {
|
|
||||||
EmailModel emailModel = new EmailModel();
|
|
||||||
emailModel.setTo(to);
|
|
||||||
emailModel.setSubject(subject);
|
|
||||||
emailModel.setContent(content);
|
|
||||||
ValidatorUtil.verify(emailModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获得配置信息
|
|
||||||
MailAccount mailAccount = this.getMailAccount();
|
|
||||||
|
|
||||||
// 发送邮件
|
|
||||||
return MailUtil.send(mailAccount, tos , subject ,content, isHtml);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得 配置信息
|
|
||||||
* @return MailAccount
|
|
||||||
*/
|
|
||||||
private MailAccount getMailAccount(){
|
|
||||||
// 获得配置数据
|
|
||||||
OptionsModel smtp = OptionsUtil.getOptionByCode(EmailType.EMAIL_SMTP.getCode());
|
|
||||||
OptionsModel port = OptionsUtil.getOptionByCode(EmailType.EMAIL_PORT.getCode());
|
|
||||||
OptionsModel sslEnable = OptionsUtil.getOptionByCode(EmailType.EMAIL_SSL_ENABLE.getCode());
|
|
||||||
OptionsModel account = OptionsUtil.getOptionByCode(EmailType.EMAIL_ACCOUNT.getCode());
|
|
||||||
OptionsModel password = OptionsUtil.getOptionByCode(EmailType.EMAIL_PASSWORD.getCode());
|
|
||||||
OptionsModel addresser = OptionsUtil.getOptionByCode(EmailType.EMAIL_ADDRESSER.getCode());
|
|
||||||
|
|
||||||
MailAccount mailAccount = new MailAccount();
|
|
||||||
mailAccount.setAuth(true);
|
|
||||||
if(smtp != null){
|
|
||||||
mailAccount.setHost(smtp.getOptionValue());
|
|
||||||
}
|
|
||||||
if(port != null){
|
|
||||||
mailAccount.setPort(Convert.toInt(port.getOptionValue()));
|
|
||||||
}
|
|
||||||
if(sslEnable != null){
|
|
||||||
mailAccount.setSslEnable(
|
|
||||||
DictType.NO_YES_YES.getValue().equals(sslEnable.getOptionValue()));
|
|
||||||
}
|
|
||||||
if(account != null){
|
|
||||||
mailAccount.setUser(account.getOptionValue());
|
|
||||||
}
|
|
||||||
if(password != null){
|
|
||||||
mailAccount.setPass(password.getOptionValue());
|
|
||||||
}
|
|
||||||
if(addresser != null){
|
|
||||||
mailAccount.setFrom(addresser.getOptionValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
return mailAccount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,39 +0,0 @@
|
|||||||
package org.opsli.plugins.email.wrapper;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import org.opsli.common.annotation.validator.Validator;
|
|
||||||
import org.opsli.common.annotation.validator.ValidatorLenMax;
|
|
||||||
import org.opsli.common.enums.ValidatorType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 邮件服务
|
|
||||||
*
|
|
||||||
* @author Parker
|
|
||||||
* @date 2020-09-19 20:03
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
public class EmailModel {
|
|
||||||
|
|
||||||
|
|
||||||
/** 收件人 */
|
|
||||||
@ApiModelProperty(value = "收件人")
|
|
||||||
@Validator({ValidatorType.IS_EMAIL, ValidatorType.IS_NOT_NULL})
|
|
||||||
@ValidatorLenMax(200)
|
|
||||||
private String to;
|
|
||||||
|
|
||||||
/** 主题 */
|
|
||||||
@ApiModelProperty(value = "主题")
|
|
||||||
@Validator({ValidatorType.IS_NOT_NULL})
|
|
||||||
@ValidatorLenMax(200)
|
|
||||||
private String subject;
|
|
||||||
|
|
||||||
/** 内容 */
|
|
||||||
@ApiModelProperty(value = "内容")
|
|
||||||
@ValidatorLenMax(20000)
|
|
||||||
private String content;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.opsli.plugins.oss.factory;
|
package org.opsli.plugins.oss.conf;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -0,0 +1,102 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* 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
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.opsli.plugins.oss.conf;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.opsli.common.annotation.OptionDict;
|
||||||
|
import org.opsli.common.annotation.validator.Validator;
|
||||||
|
import org.opsli.common.annotation.validator.ValidatorLenMax;
|
||||||
|
import org.opsli.common.enums.ValidatorType;
|
||||||
|
import org.opsli.core.utils.OptionsUtil;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 又拍云存储配置工厂
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2020-09-19 20:03
|
||||||
|
*/
|
||||||
|
public enum UpYunConfigFactory implements ConfigFactory<UpYunConfigFactory.UpYunConfig> {
|
||||||
|
|
||||||
|
/** 实例对象 */
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得配置信息
|
||||||
|
* @return LocalConfig
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public UpYunConfig getConfig() {
|
||||||
|
UpYunConfig config = new UpYunConfig();
|
||||||
|
// 获得缓存参数配置
|
||||||
|
OptionsUtil.getOptionByBean(config);
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// =======================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地存储配置
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class UpYunConfig implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 域名 */
|
||||||
|
@ApiModelProperty(value = "域名")
|
||||||
|
@Validator({ValidatorType.IS_NOT_NULL})
|
||||||
|
@ValidatorLenMax(100)
|
||||||
|
@OptionDict("storage_upyun_domain")
|
||||||
|
private String domain;
|
||||||
|
|
||||||
|
/** 前缀 */
|
||||||
|
@ApiModelProperty(value = "前缀")
|
||||||
|
@ValidatorLenMax(100)
|
||||||
|
@OptionDict("storage_upyun_path_prefix")
|
||||||
|
private String pathPrefix;
|
||||||
|
|
||||||
|
|
||||||
|
/** 操作员用户名 */
|
||||||
|
@ApiModelProperty(value = "操作员用户名")
|
||||||
|
@Validator({ValidatorType.IS_NOT_NULL})
|
||||||
|
@ValidatorLenMax(100)
|
||||||
|
@OptionDict("storage_upyun_username")
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/** 操作员密码 */
|
||||||
|
@ApiModelProperty(value = "操作员密码")
|
||||||
|
@Validator({ValidatorType.IS_NOT_NULL})
|
||||||
|
@ValidatorLenMax(100)
|
||||||
|
@OptionDict("storage_upyun_password")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/** 存储仓库名 */
|
||||||
|
@ApiModelProperty(value = "存储仓库名")
|
||||||
|
@Validator({ValidatorType.IS_NOT_NULL})
|
||||||
|
@ValidatorLenMax(100)
|
||||||
|
@OptionDict("storage_upyun_bucket_name")
|
||||||
|
private String bucketName;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* 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
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.opsli.plugins.oss.exception;
|
||||||
|
|
||||||
|
import org.opsli.common.base.msg.BaseMsg;
|
||||||
|
import org.opsli.common.exception.ServiceException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储服务 异常
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2020-09-16 11:47
|
||||||
|
*/
|
||||||
|
public class StoragePluginException extends ServiceException {
|
||||||
|
|
||||||
|
public StoragePluginException(Integer code, String errorMessage) {
|
||||||
|
super(code, errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StoragePluginException(Integer code, String errorMessage, Throwable e) {
|
||||||
|
super(code, errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StoragePluginException(BaseMsg msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StoragePluginException(BaseMsg msg, Throwable e) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,169 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* 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
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.opsli.plugins.oss.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.upyun.RestManager;
|
||||||
|
import com.upyun.UpException;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.opsli.core.autoconfigure.properties.GlobalProperties;
|
||||||
|
import org.opsli.core.utils.GlobalPropertiesUtil;
|
||||||
|
import org.opsli.core.utils.ValidatorUtil;
|
||||||
|
import org.opsli.plugins.oss.conf.LocalConfigFactory;
|
||||||
|
import org.opsli.plugins.oss.conf.UpYunConfigFactory;
|
||||||
|
import org.opsli.plugins.oss.enums.OssStorageType;
|
||||||
|
import org.opsli.plugins.oss.exception.StoragePluginException;
|
||||||
|
import org.opsli.plugins.oss.msg.OssMsg;
|
||||||
|
import org.opsli.plugins.oss.service.BaseOssStorageService;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 又拍云文件上传
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2021年4月30日14:09:08
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class UpYunStorageServiceImpl extends BaseOssStorageService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssStorageType getType() {
|
||||||
|
return OssStorageType.UP_YUN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDomain() {
|
||||||
|
// 获得配置信息
|
||||||
|
UpYunConfigFactory.UpYunConfig config = UpYunConfigFactory.INSTANCE.getConfig();
|
||||||
|
return config.getDomain();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileAttr upload(File file) {
|
||||||
|
// 非空判断
|
||||||
|
if(FileUtil.isEmpty(file)){
|
||||||
|
return new FileAttr();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获得配置信息
|
||||||
|
UpYunConfigFactory.UpYunConfig config = UpYunConfigFactory.INSTANCE.getConfig();
|
||||||
|
|
||||||
|
// 验证对象
|
||||||
|
ValidatorUtil.verify(config);
|
||||||
|
|
||||||
|
// 当前时间戳
|
||||||
|
long currentTimeMillis = System.currentTimeMillis();
|
||||||
|
|
||||||
|
// 当前时间
|
||||||
|
Date currDate = DateUtil.date(currentTimeMillis);
|
||||||
|
|
||||||
|
// 静态路径前缀 默认为空
|
||||||
|
String pathPrefix = StrUtil.isNotEmpty(config.getPathPrefix())?config.getPathPrefix():"";
|
||||||
|
|
||||||
|
// 文件夹名称
|
||||||
|
String folderName = DateUtil.format(currDate, "yyyyMMdd");
|
||||||
|
|
||||||
|
// 包 名称
|
||||||
|
String packageName = StrUtil.appendIfMissing(
|
||||||
|
super.handlePath(pathPrefix) + super.handlePath(folderName),
|
||||||
|
BaseOssStorageService.FOLDER_PREFIX);
|
||||||
|
|
||||||
|
// 文件属性
|
||||||
|
FileAttr fileAttr = super.getFileAttr(file);
|
||||||
|
// 设置文件路径
|
||||||
|
fileAttr.setFileStoragePath(packageName + fileAttr.getName() + fileAttr.getSuffix());
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获得又拍云 服务
|
||||||
|
RestManager restManager = this.getService(config);
|
||||||
|
restManager.writeFile(fileAttr.getFileStoragePath(), file, null);
|
||||||
|
}catch (IOException | UpException e){
|
||||||
|
// 上传文件失败,请检查配置信息
|
||||||
|
throw new StoragePluginException(OssMsg.EXCEPTION_UPLOAD_ERROR, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileAttr;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileAttr upload(InputStream inputStream, String suffix) {
|
||||||
|
// 获得配置信息
|
||||||
|
UpYunConfigFactory.UpYunConfig config = UpYunConfigFactory.INSTANCE.getConfig();
|
||||||
|
|
||||||
|
// 验证对象
|
||||||
|
ValidatorUtil.verify(config);
|
||||||
|
|
||||||
|
// 当前时间戳
|
||||||
|
long currentTimeMillis = System.currentTimeMillis();
|
||||||
|
|
||||||
|
// 当前时间
|
||||||
|
Date currDate = DateUtil.date(currentTimeMillis);
|
||||||
|
|
||||||
|
// 静态路径前缀 默认为空
|
||||||
|
String pathPrefix = StrUtil.isNotEmpty(config.getPathPrefix())?config.getPathPrefix():"";
|
||||||
|
|
||||||
|
// 文件夹名称
|
||||||
|
String folderName = DateUtil.format(currDate, "yyyyMMdd");
|
||||||
|
|
||||||
|
// 包 名称
|
||||||
|
String packageName = StrUtil.appendIfMissing(
|
||||||
|
super.handlePath(pathPrefix) + super.handlePath(folderName),
|
||||||
|
BaseOssStorageService.FOLDER_PREFIX);
|
||||||
|
|
||||||
|
// 文件属性
|
||||||
|
FileAttr fileAttr = super.getFileAttr(inputStream, suffix);
|
||||||
|
// 设置文件路径
|
||||||
|
fileAttr.setFileStoragePath(
|
||||||
|
config.getDomain() + packageName + fileAttr.getRandomFileNameAndSuffix());
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获得又拍云 服务
|
||||||
|
RestManager restManager = this.getService(config);
|
||||||
|
Response response = restManager.writeFile(packageName + fileAttr.getRandomFileNameAndSuffix(),
|
||||||
|
inputStream, null);
|
||||||
|
int code = response.code();
|
||||||
|
if(HttpStatus.UNAUTHORIZED.value() == code){
|
||||||
|
// 权限认证异常
|
||||||
|
throw new StoragePluginException(OssMsg.EXCEPTION_UPLOAD_AUTH_ERROR);
|
||||||
|
}
|
||||||
|
}catch (IOException | UpException e){
|
||||||
|
// 上传文件失败,请检查配置信息
|
||||||
|
throw new StoragePluginException(OssMsg.EXCEPTION_UPLOAD_ERROR, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileAttr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得 又拍云 服务
|
||||||
|
* @return RestManager
|
||||||
|
*/
|
||||||
|
private RestManager getService(UpYunConfigFactory.UpYunConfig config){
|
||||||
|
return new RestManager(config.getBucketName(),
|
||||||
|
config.getUsername(), config.getPassword());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>opsli-plugins</artifactId>
|
||||||
|
<groupId>org.opsliframework.boot</groupId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>opsli-plugins-email</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package org.opsli.plugins.email.conf;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地存储配置
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class EmailConfig implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** SMTP地址 */
|
||||||
|
private String smtp;
|
||||||
|
|
||||||
|
/** SMTP端口 */
|
||||||
|
private Integer port;
|
||||||
|
|
||||||
|
/** 开启SSL认证 */
|
||||||
|
private String sslEnable;
|
||||||
|
|
||||||
|
/** 邮箱账号 */
|
||||||
|
private String account;
|
||||||
|
|
||||||
|
/** 邮箱密码 */
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/** 发件人 */
|
||||||
|
private String addresser;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* 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
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.opsli.plugins.email.exception;
|
||||||
|
|
||||||
|
import org.opsli.common.base.msg.BaseMsg;
|
||||||
|
import org.opsli.common.exception.ServiceException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮件 异常
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2020-09-16 11:47
|
||||||
|
*/
|
||||||
|
public class EmailPluginException extends ServiceException {
|
||||||
|
|
||||||
|
public EmailPluginException(Integer code, String errorMessage) {
|
||||||
|
super(code, errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EmailPluginException(BaseMsg msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,58 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* 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
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.opsli.plugins.email.msg;
|
||||||
|
|
||||||
|
|
||||||
|
import org.opsli.common.base.msg.BaseMsg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮件服务异常 - 消息
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2020-09-19 20:03
|
||||||
|
*/
|
||||||
|
public enum EmailMsg implements BaseMsg {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮件服务异常
|
||||||
|
*/
|
||||||
|
EXCEPTION_CONFIG_INIT_NULL(90400, "邮件服务初始化异常"),
|
||||||
|
|
||||||
|
EXCEPTION_MODEL_TO_NULL(90401, "收件人不可为空"),
|
||||||
|
EXCEPTION_MODEL_SUBJECT_NULL(90402, "主题不可为空"),
|
||||||
|
EXCEPTION_MODEL_CONTENT_NULL(90403, "内容不可为空"),
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
EmailMsg(int code, String message){
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getCode() {
|
||||||
|
return this.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return this.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,105 @@
|
|||||||
|
package org.opsli.plugins.email.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.extra.mail.MailAccount;
|
||||||
|
import cn.hutool.extra.mail.MailUtil;
|
||||||
|
import org.opsli.common.enums.DictType;
|
||||||
|
import org.opsli.plugins.email.EmailPlugin;
|
||||||
|
import org.opsli.plugins.email.conf.EmailConfig;
|
||||||
|
import org.opsli.plugins.email.exception.EmailPluginException;
|
||||||
|
import org.opsli.plugins.email.msg.EmailMsg;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮件 接口实现类
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2020-09-19 20:03
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class EmailPluginImpl implements EmailPlugin {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String send(String to, String subject, String content, EmailConfig emailConfig) {
|
||||||
|
// 发送邮件
|
||||||
|
return this.send(Collections.singletonList(to), subject , content, emailConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String send(Collection<String> tos, String subject, String content,
|
||||||
|
EmailConfig emailConfig) {
|
||||||
|
// 发送邮件
|
||||||
|
return this.send(tos, subject ,content, false, emailConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String send(String to, String subject, String content,
|
||||||
|
boolean isHtml, EmailConfig emailConfig) {
|
||||||
|
// 发送邮件
|
||||||
|
return this.send(Collections.singletonList(to), subject ,
|
||||||
|
content, isHtml, emailConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String send(Collection<String> tos, String subject, String content,
|
||||||
|
boolean isHtml, EmailConfig emailConfig) {
|
||||||
|
|
||||||
|
// 校验发送邮件数据是否正确
|
||||||
|
this.verify(tos, subject, content);
|
||||||
|
|
||||||
|
// 获得配置信息
|
||||||
|
MailAccount mailAccount = this.getMailAccount(emailConfig);
|
||||||
|
|
||||||
|
// 发送邮件
|
||||||
|
return MailUtil.send(mailAccount, tos , subject ,content, isHtml);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证
|
||||||
|
* @param tos 收件人(可多人发送)
|
||||||
|
* @param subject 主题
|
||||||
|
* @param content 内容
|
||||||
|
*/
|
||||||
|
private void verify(Collection<String> tos, String subject, String content){
|
||||||
|
// 校验发送邮件数据是否正确
|
||||||
|
for (String to : tos) {
|
||||||
|
if(StrUtil.isEmpty(to)){
|
||||||
|
// 收件人不可为空
|
||||||
|
throw new EmailPluginException(EmailMsg.EXCEPTION_MODEL_TO_NULL);
|
||||||
|
}
|
||||||
|
if(StrUtil.isEmpty(subject)){
|
||||||
|
// 主题不可为空
|
||||||
|
throw new EmailPluginException(EmailMsg.EXCEPTION_MODEL_SUBJECT_NULL);
|
||||||
|
}
|
||||||
|
if(StrUtil.isEmpty(content)){
|
||||||
|
// 内容不可为空
|
||||||
|
throw new EmailPluginException(EmailMsg.EXCEPTION_MODEL_CONTENT_NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得 配置信息
|
||||||
|
* @return MailAccount
|
||||||
|
*/
|
||||||
|
private MailAccount getMailAccount(EmailConfig emailConfig){
|
||||||
|
if(emailConfig == null){
|
||||||
|
// 邮件服务初始化异常
|
||||||
|
throw new EmailPluginException(EmailMsg.EXCEPTION_CONFIG_INIT_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
MailAccount mailAccount = new MailAccount();
|
||||||
|
mailAccount.setAuth(true);
|
||||||
|
mailAccount.setHost(emailConfig.getSmtp());
|
||||||
|
mailAccount.setPort(emailConfig.getPort());
|
||||||
|
mailAccount.setSslEnable(
|
||||||
|
DictType.NO_YES_YES.getValue().equals(emailConfig.getSslEnable()));
|
||||||
|
mailAccount.setUser(emailConfig.getAccount());
|
||||||
|
mailAccount.setPass(emailConfig.getPassword());
|
||||||
|
mailAccount.setFrom(emailConfig.getAddresser());
|
||||||
|
return mailAccount;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
package org.opsli.plugins.email.wrapper;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮件服务
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2020-09-19 20:03
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class EmailModel {
|
||||||
|
|
||||||
|
/** 收件人 */
|
||||||
|
private String to;
|
||||||
|
|
||||||
|
/** 主题 */
|
||||||
|
private String subject;
|
||||||
|
|
||||||
|
/** 内容 */
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in new issue