## 去掉发送邮件相关内容;
This commit is contained in:
parent
6b72082f4f
commit
7c274a3b0a
|
@ -1,23 +0,0 @@
|
|||
package com.hzs.third.sms;
|
||||
|
||||
import com.hzs.common.core.domain.R;
|
||||
import com.hzs.third.sms.dto.MailServiceDTO;
|
||||
import com.hzs.third.sms.dto.SmsServiceDTO;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: yuhui
|
||||
* @Time: 2023/3/30 17:05
|
||||
* @Classname: IMailServiceApi
|
||||
* @PackageName: com.hzs.third.sms
|
||||
*/
|
||||
public interface IMailServiceApi {
|
||||
|
||||
/**
|
||||
* 发送
|
||||
*
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
R<Boolean> send(MailServiceDTO param);
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package com.hzs.third.sms.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*@BelongsProject: hzs_cloud
|
||||
*@BelongsPackage: com.hzs.third.sms.dto
|
||||
*@Author: yh
|
||||
*@CreateTime: 2023-03-30 17:09
|
||||
*@Description: TODO
|
||||
*@Version: 1.0
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@Data
|
||||
public class MailServiceDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4260605256535168912L;
|
||||
|
||||
/**
|
||||
* 邮箱地址
|
||||
*/
|
||||
private String mail;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private String content;
|
||||
}
|
|
@ -57,13 +57,6 @@ import java.util.*;
|
|||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: sui q
|
||||
* @Time: 2022/9/30 15:58
|
||||
* @Classname: CuMemberController
|
||||
* @PackageName: com.hzs.member.base.controller.manager
|
||||
*/
|
||||
@RequestMapping("/manager/member")
|
||||
@RestController
|
||||
public class CuMemberController extends BaseController {
|
||||
|
@ -437,24 +430,6 @@ public class CuMemberController extends BaseController {
|
|||
return AjaxResult.success(theLableVOList);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 真实信息显示隐藏表头列表
|
||||
* @author: zhang jing
|
||||
* @date: 2022/11/17 15:39
|
||||
* @param: []
|
||||
* @return: com.hzs.common.core.web.domain.AjaxResult
|
||||
**/
|
||||
@Log(module = EOperationModule.MEMBER_INFORMATION)
|
||||
@GetMapping("/real-theLable")
|
||||
public AjaxResult realTheLable() {
|
||||
List<TheLableVO> theLableVOList = new ArrayList<>();
|
||||
for (ERealTheLable value : ERealTheLable.values()) {
|
||||
theLableVOList.add(new TheLableVO(value.getTitel(), value.getProp(), value.getKeyId(), value.getShow()));
|
||||
}
|
||||
return AjaxResult.success(theLableVOList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description: 真实信息
|
||||
* @author: zhang jing
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.hzs.member.sms.controller.api;
|
|||
|
||||
import com.hzs.common.core.annotation.RepeatSubmitSimple;
|
||||
import com.hzs.common.core.constant.CountryConstants;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import com.hzs.common.core.constant.msg.ConfigMsgConstants;
|
||||
import com.hzs.common.core.constant.msg.MemberMsgConstants;
|
||||
import com.hzs.common.core.enums.ESmsTemplate;
|
||||
|
@ -63,26 +62,11 @@ public class ApiSmsController extends BaseController {
|
|||
return AjaxResult.error(TransactionUtils.getContent(MemberMsgConstants.MEMBER_INFO_ERROR));
|
||||
}
|
||||
|
||||
if (cuMember.getPkSettleCountry().equals(CountryConstants.CHINA_COUNTRY)) {
|
||||
// 如果是中国,则走短信方式
|
||||
if (!cuMember.getPhone().equals(phone)) {
|
||||
// 会员不存在,或者手机号不相同
|
||||
return AjaxResult.error(TransactionUtils.getContent(MemberMsgConstants.MEMBER_INFO_ERROR));
|
||||
}
|
||||
return toAjax(iApiSmsService.verificationSms(cuMember.getPkId(), cuMember.getPkSettleCountry(), phone, ESmsTemplate.FORGET_PASSWORD));
|
||||
} else {
|
||||
// 非中国,走邮箱方式
|
||||
if (!cuMember.getEmail().equals(phone)) {
|
||||
// 会员不存在,或者手机号不相同
|
||||
return AjaxResult.error(TransactionUtils.getContent(MemberMsgConstants.MEMBER_INFO_ERROR));
|
||||
}
|
||||
|
||||
if (!Validator.isEmail(phone)) {
|
||||
return AjaxResult.error("邮箱地址不可用");
|
||||
}
|
||||
iApiSmsService.verificationEmailSms(cuMember.getPkId(), cuMember.getPkSettleCountry(), phone, ESmsTemplate.FORGET_PASSWORD);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -60,13 +60,4 @@ public interface IApiSmsService {
|
|||
*/
|
||||
boolean verificationSmsByPhone(Integer pkCountry, String phone, ESmsTemplate eSmsTemplate);
|
||||
|
||||
/**
|
||||
* 国外发送邮箱验证码
|
||||
* @param pkMember
|
||||
* @param pkSettleCountry
|
||||
* @param email
|
||||
* @param forgetPassword
|
||||
* @return
|
||||
*/
|
||||
boolean verificationEmailSms(Long pkMember, Integer pkSettleCountry, String email, ESmsTemplate forgetPassword);
|
||||
}
|
||||
|
|
|
@ -6,16 +6,13 @@ import com.hzs.common.core.domain.R;
|
|||
import com.hzs.common.core.enums.ESmsTemplate;
|
||||
import com.hzs.common.core.exception.ServiceException;
|
||||
import com.hzs.common.core.service.RedisService;
|
||||
import com.hzs.common.core.utils.SloganUtil;
|
||||
import com.hzs.common.core.utils.StringUtils;
|
||||
import com.hzs.common.core.utils.VerificationCodeUtil;
|
||||
import com.hzs.common.domain.member.base.CuMember;
|
||||
import com.hzs.common.util.TransactionUtils;
|
||||
import com.hzs.member.base.service.ICuMemberService;
|
||||
import com.hzs.member.sms.service.IApiSmsService;
|
||||
import com.hzs.third.sms.IMailServiceApi;
|
||||
import com.hzs.third.sms.ISmsServiceApi;
|
||||
import com.hzs.third.sms.dto.MailServiceDTO;
|
||||
import com.hzs.third.sms.dto.SmsServiceDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
|
@ -43,8 +40,6 @@ public class ApiSmsServiceImpl implements IApiSmsService {
|
|||
|
||||
@DubboReference
|
||||
ISmsServiceApi iSmsServiceApi;
|
||||
@DubboReference
|
||||
IMailServiceApi mailServiceApi;
|
||||
|
||||
@Override
|
||||
public String checkSms(String cacheKey, String code) {
|
||||
|
@ -126,30 +121,4 @@ public class ApiSmsServiceImpl implements IApiSmsService {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 国外发送邮箱验证码
|
||||
*
|
||||
* @param pkMember
|
||||
* @param pkSettleCountry
|
||||
* @param email
|
||||
* @param eSmsTemplate
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean verificationEmailSms(Long pkMember, Integer pkSettleCountry, String email, ESmsTemplate eSmsTemplate) {
|
||||
// 生成4位验证码
|
||||
String code = VerificationCodeUtil.createCode();
|
||||
R<Boolean> send = mailServiceApi.send(MailServiceDTO.builder()
|
||||
.mail(email).content(SloganUtil.passwordRecovery(code)).title(SloganUtil.passwordRecoveryTitle())
|
||||
.build()
|
||||
);
|
||||
if (send.isSuccess()) {
|
||||
// 返回成功,验证码放入缓存
|
||||
redisService.setCacheObject(eSmsTemplate.getCache() + email, code, SmsConstants.FAILURE_TIME, TimeUnit.MINUTES);
|
||||
return true;
|
||||
}
|
||||
log.error("发送短信失败:{}", send.getMsg());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,150 +0,0 @@
|
|||
package com.hzs.common.core.enums;
|
||||
|
||||
import com.hzs.common.core.constant.EnumsPrefixConstants;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 列表显示隐藏控制枚举
|
||||
*
|
||||
* @author: hzs
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum ERealTheLable {
|
||||
|
||||
/**
|
||||
* 会员编号
|
||||
*/
|
||||
TITEL_1(1, "会员编号", "memberCode","true", EnumsPrefixConstants.THELABLE + "1"),
|
||||
/**
|
||||
* 会员姓名
|
||||
*/
|
||||
TITEL_2(2, "会员姓名", "memberName","true", EnumsPrefixConstants.THELABLE + "2"),
|
||||
/**
|
||||
* 联系方式
|
||||
*/
|
||||
TITEL_3(3, "联系方式", "phone","true", EnumsPrefixConstants.THELABLE + "3"),
|
||||
/**
|
||||
* 注册等级
|
||||
*/
|
||||
TITEL_4(4, "注册等级", "registerName", "false",EnumsPrefixConstants.THELABLE + "4"),
|
||||
/**
|
||||
* 结算等级
|
||||
*/
|
||||
TITEL_5(5, "结算等级", "settleName", "false",EnumsPrefixConstants.THELABLE + "5"),
|
||||
/**
|
||||
* 真实奖衔
|
||||
*/
|
||||
TITEL_6(6, "真实奖衔", "pkAwardsVal", "true",EnumsPrefixConstants.THELABLE + "6"),
|
||||
|
||||
/**
|
||||
* 性别
|
||||
*/
|
||||
TITEL_7(7, "性别", "sexVal", "false",EnumsPrefixConstants.THELABLE + "7"),
|
||||
/**
|
||||
* 出生日期
|
||||
*/
|
||||
TITEL_8(8, "出生日期", "birthDate", "false",EnumsPrefixConstants.THELABLE + "8"),
|
||||
/**
|
||||
* 证件类型
|
||||
*/
|
||||
TITEL_9(9, "证件类型", "cardTypeVal", "false",EnumsPrefixConstants.THELABLE + "9"),
|
||||
/**
|
||||
* 证件号码
|
||||
*/
|
||||
TITEL_10(10, "证件号码", "idCard", "false",EnumsPrefixConstants.THELABLE + "10"),
|
||||
/**
|
||||
* 证件(正面)
|
||||
*/
|
||||
TITEL_11(11, "证件(正面)", "idCardJust", "false",EnumsPrefixConstants.THELABLE + "11"),
|
||||
/**
|
||||
* 证件(反面)
|
||||
*/
|
||||
TITEL_12(12, "证件(反面)", "idCardBack", "false",EnumsPrefixConstants.THELABLE + "12"),
|
||||
/**
|
||||
* 省
|
||||
*/
|
||||
TITEL_13(13, "省", "giftProvince", "false",EnumsPrefixConstants.THELABLE + "13"),
|
||||
/**
|
||||
* 市
|
||||
*/
|
||||
TITEL_14(14, "市", "giftCity", "false",EnumsPrefixConstants.THELABLE + "14"),
|
||||
/**
|
||||
* 区/县
|
||||
*/
|
||||
TITEL_15(15, "区/县", "giftCounty", "false",EnumsPrefixConstants.THELABLE + "15"),
|
||||
/**
|
||||
* 详细地址
|
||||
*/
|
||||
TITEL_16(16, "详细地址", "giftAddress", "false",EnumsPrefixConstants.THELABLE + "16"),
|
||||
/**
|
||||
* 银行名称
|
||||
*/
|
||||
TITEL_17(17, "银行名称", "bankName", "false",EnumsPrefixConstants.THELABLE + "17"),
|
||||
/**
|
||||
* 支行名称
|
||||
*/
|
||||
TITEL_18(18, "支行名称", "subBankName", "false",EnumsPrefixConstants.THELABLE + "18"),
|
||||
/**
|
||||
* 开户姓名
|
||||
*/
|
||||
TITEL_19(19, "开户姓名", "accountName", "false",EnumsPrefixConstants.THELABLE + "19"),
|
||||
/**
|
||||
* 预留电话
|
||||
*/
|
||||
TITEL_20(20, "预留电话", "reservePhone", "false",EnumsPrefixConstants.THELABLE + "20"),
|
||||
/**
|
||||
* 银行卡号
|
||||
*/
|
||||
TITEL_21(21, "银行卡号", "cardNumber", "false",EnumsPrefixConstants.THELABLE + "21"),
|
||||
/**
|
||||
* 微信
|
||||
*/
|
||||
TITEL_22(22, "微信", "wechat", "false",EnumsPrefixConstants.THELABLE + "22"),
|
||||
/**
|
||||
* 邮箱地址
|
||||
*/
|
||||
TITEL_23(23, "邮箱地址", "email", "false",EnumsPrefixConstants.THELABLE + "23"),
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
TITEL_24(24, "创建时间", "creationTime", "true",EnumsPrefixConstants.THELABLE + "24"),
|
||||
/**
|
||||
* 支付时间
|
||||
*/
|
||||
TITEL_25(25, "支付时间", "payTime", "true",EnumsPrefixConstants.THELABLE + "25"),
|
||||
/**
|
||||
* 修改直推次数
|
||||
*/
|
||||
TITEL_26(26, "修改直推次数", "editNumber", "true",EnumsPrefixConstants.THELABLE + "26"),
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* key键
|
||||
*/
|
||||
private final int keyId;
|
||||
/**
|
||||
* 表头名称
|
||||
*/
|
||||
private final String titel;
|
||||
/**
|
||||
* 对应字段
|
||||
*/
|
||||
private final String prop;
|
||||
/**
|
||||
* 初始化显示隐藏
|
||||
*/
|
||||
private final String show;
|
||||
/**
|
||||
* 国际化翻译key值
|
||||
*/
|
||||
private final String key;
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package com.hzs.common.core.utils;/**
|
||||
* @Description:
|
||||
* @Author: yuhui
|
||||
* @Time: 2023/3/30 17:14
|
||||
* @Classname: SloganUtil
|
||||
* @PackageName: com.hzs.common.core.utils
|
||||
*/
|
||||
|
||||
/**
|
||||
*@BelongsProject: hzs_cloud
|
||||
*@BelongsPackage: com.hzs.common.core.utils
|
||||
*@Author: yh
|
||||
*@CreateTime: 2023-03-30 17:14
|
||||
*@Description: TODO
|
||||
*@Version: 1.0
|
||||
*/
|
||||
public class SloganUtil {
|
||||
|
||||
/**
|
||||
* 注册成功 发送欢迎邮件标语
|
||||
* @param nickName 用户名称
|
||||
* @param userName 用户账号
|
||||
* @param password 用户密码
|
||||
* @return
|
||||
*/
|
||||
public static String registerSuccessSlogan(String nickName,String userName,String password){
|
||||
String slogan = "Welcome "+nickName+",\n" +
|
||||
"We would like to welcome you to HZS Biotech!\n" +
|
||||
"\n" +
|
||||
"Your Account Information\n" +
|
||||
"This is your account login information for member management system.\n" +
|
||||
"Login ID : ("+userName+")\n" +
|
||||
"Password :("+password+")\n" +
|
||||
"For your account safety purpose, please change your login password immediately once you have logged into your member management system.\n" +
|
||||
"Thank you for choosing HZS Biotech as your business partner.";
|
||||
return slogan;
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码找回
|
||||
* @return
|
||||
*/
|
||||
public static String passwordRecovery(String code){
|
||||
String slogan = "Verify your email address\n" +
|
||||
"To continue setting up your HZS account, please verify that this is your email address.\n" +
|
||||
"YOUR EMAIL Verification Code:"+code+"\n" +
|
||||
"This link will expire in 5 days. If you did not make this request, please disregard this email. For help, contact us through our Help center.";
|
||||
return slogan;
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码找回 标题
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public static String passwordRecoveryTitle(){
|
||||
String slogan = "[HZS]--Email Authentication";
|
||||
return slogan;
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
package com.hzs.common.domain.third.email;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
|
||||
import com.hzs.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 邮件信息
|
||||
* </p>
|
||||
*
|
||||
* @author hzs
|
||||
* @since 2022-08-08
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("T_EMAIL")
|
||||
@KeySequence("T_EMAIL_SEQ")
|
||||
public class TEmail extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId("PK_ID")
|
||||
private Long pkId;
|
||||
|
||||
/**
|
||||
* 发送方
|
||||
*/
|
||||
@TableField("SENDER")
|
||||
private String sender;
|
||||
|
||||
/**
|
||||
* 接收方
|
||||
*/
|
||||
@TableField("RECEIVER")
|
||||
private String receiver;
|
||||
|
||||
/**
|
||||
* 发送主题
|
||||
*/
|
||||
@TableField("SUBJECT")
|
||||
private String subject;
|
||||
|
||||
/**
|
||||
* 接收主题
|
||||
*/
|
||||
@TableField("CONTENT")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 邮件发送类型 (0-欢迎邮件) 对应EmailType枚举
|
||||
*/
|
||||
@TableField("EMAIL_TYPE")
|
||||
private Integer emailType;
|
||||
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package com.hzs.third.email.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 邮件配置
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "spring.mail")
|
||||
@Component
|
||||
public class EmailConfig {
|
||||
|
||||
/**
|
||||
* 发送方邮件
|
||||
*/
|
||||
private String from;
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package com.hzs.third.email.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.hzs.common.domain.third.email.TEmail;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 邮件信息 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author hzs
|
||||
* @since 2022-08-08
|
||||
*/
|
||||
public interface TEmailMapper extends BaseMapper<TEmail> {
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package com.hzs.third.email.provider;
|
||||
|
||||
import com.hzs.common.core.domain.R;
|
||||
import com.hzs.common.core.enums.EMailType;
|
||||
import com.hzs.third.email.IEmailServiceApi;
|
||||
import com.hzs.third.email.service.ITEmailService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 邮件dubbo服务
|
||||
*/
|
||||
@Slf4j
|
||||
@DubboService
|
||||
public class EmailProvider implements IEmailServiceApi {
|
||||
|
||||
@Autowired
|
||||
private ITEmailService itEmailService;
|
||||
|
||||
@Override
|
||||
public R<?> sendMail(List<String> recipientList, String title, String content, EMailType eMailType) {
|
||||
try {
|
||||
// if (itEmailService.sendMail(recipientList, title, content, true, eMailType)) {
|
||||
return R.ok();
|
||||
// }
|
||||
} catch (Exception e) {
|
||||
log.error("邮件发送异常,recipientList: {}, title: {}", recipientList, title, e);
|
||||
}
|
||||
return R.fail("邮件发送失败");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package com.hzs.third.email.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.hzs.common.core.enums.EMailType;
|
||||
import com.hzs.common.domain.third.email.TEmail;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 邮件服务
|
||||
*/
|
||||
public interface ITEmailService extends IService<TEmail> {
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
*
|
||||
* @param recipientList 接收账号列表
|
||||
* @param title 邮件标题
|
||||
* @param content 邮件内容
|
||||
* @param isRecordLog 是否记录日志 true 记录 false 不记录
|
||||
* @param emailType 邮件类型 EmailType 枚举
|
||||
* @return
|
||||
*/
|
||||
Boolean sendMail(List<String> recipientList, String title, String content, Boolean isRecordLog, EMailType emailType);
|
||||
|
||||
/**
|
||||
* 发送带附件的邮件信息
|
||||
*
|
||||
* @param to 接收方
|
||||
* @param subject 邮件主题
|
||||
* @param content 邮件内容
|
||||
* @param files 多个附件集合
|
||||
* @return
|
||||
*/
|
||||
Boolean sendMessageCarryFiles(String to, String subject, String content, File[] files);
|
||||
|
||||
/**
|
||||
* 发送带附件的邮件信息
|
||||
*
|
||||
* @param to 接收方
|
||||
* @param subject 邮件主题
|
||||
* @param content 邮件内容(发送内容)
|
||||
* @param file 单个文件
|
||||
* @return
|
||||
*/
|
||||
Boolean sendMessageCarryFile(String to, String subject, String content, File file);
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
package com.hzs.third.email.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.hzs.common.core.constant.MagicNumberConstants;
|
||||
import com.hzs.common.core.enums.EMailType;
|
||||
import com.hzs.common.domain.third.email.TEmail;
|
||||
import com.hzs.third.email.config.EmailConfig;
|
||||
import com.hzs.third.email.service.ITEmailService;
|
||||
import com.hzs.third.email.mapper.TEmailMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 邮件服务
|
||||
*/
|
||||
@Service
|
||||
public class TEmailServiceImpl extends ServiceImpl<TEmailMapper, TEmail> implements ITEmailService {
|
||||
|
||||
@Autowired
|
||||
private EmailConfig emailConfig;
|
||||
@Autowired
|
||||
private JavaMailSender mailSender;
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
*
|
||||
* @param recipientList 接收账号列表
|
||||
* @param title 邮件标题
|
||||
* @param content 邮件内容
|
||||
* @param isRecordLog 是否记录日志 true 记录 false 不记录
|
||||
* @param emailType 邮件类型 EmailType 枚举
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean sendMail(List<String> recipientList, String title, String content, Boolean isRecordLog, EMailType emailType) {
|
||||
String from = emailConfig.getFrom();
|
||||
try {
|
||||
// 创建一个邮件对象
|
||||
SimpleMailMessage msg = new SimpleMailMessage();
|
||||
msg.setFrom(from); // 设置发送发
|
||||
msg.setTo(recipientList.toArray(new String[0])); // 设置接收方
|
||||
msg.setSubject(title); // 设置邮件主题
|
||||
msg.setText(content); // 设置邮件内容
|
||||
// 发送邮件
|
||||
mailSender.send(msg);
|
||||
|
||||
if (null != isRecordLog && isRecordLog) {
|
||||
// 入库邮件列表
|
||||
List<TEmail> emailList = new ArrayList<>();
|
||||
// 记录邮箱日志
|
||||
for (String recipient : recipientList) {
|
||||
TEmail tEmail = new TEmail();
|
||||
tEmail.setSender(from);
|
||||
tEmail.setReceiver(recipient);
|
||||
tEmail.setSubject(title);
|
||||
tEmail.setContent(content);
|
||||
// 目前没有点对点邮件,所有创建人都由系统创建
|
||||
tEmail.setPkCreator(MagicNumberConstants.PK_ADMIN);
|
||||
tEmail.setCreationTime(new Date());
|
||||
tEmail.setEmailType(emailType.getValue());
|
||||
emailList.add(tEmail);
|
||||
}
|
||||
this.saveBatch(emailList);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean sendMessageCarryFiles(String to, String subject, String content, File[] files) {
|
||||
MimeMessage mimeMessage = mailSender.createMimeMessage();
|
||||
String from = emailConfig.getFrom();
|
||||
try {
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(from); // 设置发送发
|
||||
helper.setTo(to); // 设置接收方
|
||||
helper.setSubject(subject); // 设置邮件主题
|
||||
helper.setText(content); // 设置邮件内容
|
||||
if (files != null && files.length > 0) { // 添加附件(多个)
|
||||
for (File file : files) {
|
||||
helper.addAttachment(file.getName(), file);
|
||||
}
|
||||
}
|
||||
// 发送邮件
|
||||
mailSender.send(mimeMessage);
|
||||
return true;
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean sendMessageCarryFile(String to, String subject, String content, File file) {
|
||||
MimeMessage mimeMessage = mailSender.createMimeMessage();
|
||||
String from = emailConfig.getFrom();
|
||||
try {
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(from); // 设置发送发
|
||||
helper.setTo(to); // 设置接收方
|
||||
helper.setSubject(subject); // 设置邮件主题
|
||||
helper.setText(content); // 设置邮件内容
|
||||
helper.addAttachment(file.getName(), file); // 单个附件
|
||||
// 发送邮件
|
||||
mailSender.send(mimeMessage);
|
||||
return true;
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package com.hzs.third.sms.provider;
|
||||
|
||||
import com.hzs.common.core.domain.R;
|
||||
import com.hzs.third.sms.IMailServiceApi;
|
||||
import com.hzs.third.sms.dto.MailServiceDTO;
|
||||
import com.hzs.third.sms.dto.SmsServiceDTO;
|
||||
import com.hzs.third.sms.service.IMailService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
*@BelongsProject: hzs_cloud
|
||||
*@BelongsPackage: com.hzs.third.sms.provider
|
||||
*@Author: yh
|
||||
*@CreateTime: 2023-03-30 17:05
|
||||
*@Description: TODO
|
||||
*@Version: 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@DubboService
|
||||
public class MailServiceProvider implements IMailServiceApi {
|
||||
|
||||
@Autowired
|
||||
private IMailService mailService;
|
||||
|
||||
@Override
|
||||
public R<Boolean> send(MailServiceDTO param) {
|
||||
return R.ok(mailService.sendMail(param.getMail(),param.getTitle(),param.getContent()));
|
||||
}
|
||||
}
|
|
@ -37,28 +37,6 @@ spring:
|
|||
allow-bean-definition-overriding: true
|
||||
## true 表示控制台不会打印循环依赖异常
|
||||
allow-circular-references: true
|
||||
# 邮件配置
|
||||
mail:
|
||||
host: smtp.qiye.aliyun.com # 配置 smtp 服务器地址
|
||||
port: 465 # smtp 服务器的端口
|
||||
username: xitong@hzs413.com # 配置邮箱用户名(你的邮箱地址)
|
||||
password: hzsXx5211314! # 配置申请到的授权码
|
||||
protocol: smtps # 通过加密端口发送邮件进行配置
|
||||
default-encoding: UTF-8 # 配置邮件编码
|
||||
properties:
|
||||
mail:
|
||||
smtp:
|
||||
auth: true
|
||||
ssl:
|
||||
socketFactory:
|
||||
class: com.sun.mail.util.MailSSLSocketFactory
|
||||
fallback: false
|
||||
starttls:
|
||||
enable: true
|
||||
required: true
|
||||
socketFactoryClass: javax.net.ssl.SSLSocketFactory # 配饰 SSL 加密工厂
|
||||
debug: true
|
||||
from: xitong@hzs413.com # 发送方邮件,陪在yml中可方便更改
|
||||
|
||||
dubbo:
|
||||
registry:
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.hzs.third.email.mapper.TEmailMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.hzs.common.domain.third.email.TEmail">
|
||||
<id column="PK_ID" property="pkId" />
|
||||
<result column="SENDER" property="sender" />
|
||||
<result column="RECEIVER" property="receiver" />
|
||||
<result column="SUBJECT" property="subject" />
|
||||
<result column="CONTENT" property="content" />
|
||||
<result column="PK_CREATOR" property="pkCreator" />
|
||||
<result column="CREATION_TIME" property="creationTime" />
|
||||
<result column="PK_MODIFIED" property="pkModified" />
|
||||
<result column="MODIFIED_TIME" property="modifiedTime" />
|
||||
<result column="EMAIL_TYPE" property="emailType" />
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue