邮箱-接入aws sec
This commit is contained in:
@@ -76,6 +76,12 @@
|
||||
<artifactId>sa-token-dao-redis-jackson</artifactId>
|
||||
<version>${sa-token.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>sesv2</artifactId>
|
||||
<version>2.30.38</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -31,6 +31,7 @@ import com.accompany.business.service.room.RoomSendRankingService;
|
||||
import com.accompany.business.service.room.RoomService;
|
||||
import com.accompany.business.service.user.UsersService;
|
||||
import com.accompany.business.vo.RoomVo;
|
||||
import com.accompany.common.constant.AppEnum;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.CommonUtil;
|
||||
@@ -46,6 +47,7 @@ import com.accompany.core.service.account.AccountService;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.accompany.core.service.region.RegionService;
|
||||
import com.accompany.core.vo.UserLevelVo;
|
||||
import com.accompany.email.config.AwsSesConfig;
|
||||
import com.accompany.payment.apple.ApplePublisher;
|
||||
import com.accompany.payment.iospay.JWTTranscationInfoPayload;
|
||||
import com.accompany.payment.model.ChargeRecord;
|
||||
@@ -56,7 +58,6 @@ import com.accompany.sharding.model.GiftSendRecord;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -64,9 +65,24 @@ import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.AwsCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
|
||||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.sesv2.model.Body;
|
||||
import software.amazon.awssdk.services.sesv2.model.Content;
|
||||
import software.amazon.awssdk.services.sesv2.model.Destination;
|
||||
import software.amazon.awssdk.services.sesv2.model.EmailContent;
|
||||
import software.amazon.awssdk.services.sesv2.model.Message;
|
||||
import software.amazon.awssdk.services.sesv2.model.SendEmailRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.SesV2Exception;
|
||||
import software.amazon.awssdk.services.sesv2.SesV2Client;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
@@ -729,4 +745,81 @@ public class MyApiService {
|
||||
weekGuildStatMapper.delete(null);
|
||||
weekGuildStatMapper.insert(lastWeekGuildStatList);
|
||||
}
|
||||
|
||||
public void testMail() {
|
||||
SesV2Client client = SpringContextHolder.getBean(SesV2Client.class);
|
||||
|
||||
String appName = AppEnum.getCurApp().getValue();
|
||||
String logoUrl = "https://" + AppEnum.getCurApp().getResourceDomain() + "/" + appName + ".png";
|
||||
|
||||
String sender = "Verification Code <no-reply@email.molistar.xyz>";
|
||||
String recipient = "842328916@qq.com";
|
||||
String subject = String.format("%s verification code", appName);
|
||||
|
||||
// The HTML body of the email.
|
||||
String bodyHTML =
|
||||
String.format(
|
||||
"<html>\n" +
|
||||
"<body style=\"font-family:Arial,sans-serif;color:#333;max-width:600px;margin:0 auto;padding:20px\">\n" +
|
||||
" <img src=\"%s\" width=\"100\" style=\"display:block;margin:20px auto\">\n" +
|
||||
" <h2 style=\"color:#007bff;text-align:center\">%s verification code</h2>\n" +
|
||||
" <div style=\"background:#f1f1f1;text-align:center;padding:20px;font-size:32px;font-weight:bold;margin:20px 0\">\n" +
|
||||
" **123456**\n" +
|
||||
" </div>\n" +
|
||||
" <p style=\"text-align:center;margin:10px 0\">Expires in: <strong style=\"color:#e74c3c\">10 minutes</strong></p>\n" +
|
||||
"</body>\n" +
|
||||
"</html>", logoUrl, appName);
|
||||
|
||||
try {
|
||||
send(client, sender, recipient, subject, bodyHTML);
|
||||
client.close();
|
||||
System.out.println("Done");
|
||||
|
||||
} catch (MessagingException e) {
|
||||
e.getStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void send(SesV2Client client, String sender, String recipient, String subject, String bodyHTML){
|
||||
Destination destination = Destination.builder()
|
||||
.toAddresses(recipient)
|
||||
.build();
|
||||
|
||||
Content content = Content.builder()
|
||||
.data(bodyHTML)
|
||||
.build();
|
||||
|
||||
Content sub = Content.builder()
|
||||
.data(subject)
|
||||
.build();
|
||||
|
||||
Body body = Body.builder()
|
||||
.html(content)
|
||||
.build();
|
||||
|
||||
Message msg = Message.builder()
|
||||
.subject(sub)
|
||||
.body(body)
|
||||
.build();
|
||||
|
||||
EmailContent emailContent = EmailContent.builder()
|
||||
.simple(msg)
|
||||
.build();
|
||||
|
||||
SendEmailRequest emailRequest = SendEmailRequest.builder()
|
||||
.destination(destination)
|
||||
.content(emailContent)
|
||||
.fromEmailAddress(sender)
|
||||
.build();
|
||||
|
||||
try {
|
||||
System.out.println("Attempting to send an email through Amazon SES "
|
||||
+ "using the AWS SDK for Java...");
|
||||
client.sendEmail(emailRequest);
|
||||
System.out.println("email was sent");
|
||||
|
||||
} catch (SesV2Exception e) {
|
||||
System.err.println(e.awsErrorDetails().errorMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -263,4 +263,13 @@ public class MyApiController {
|
||||
myApiService.refreshWeekGuildStat();
|
||||
return BusiResult.success();
|
||||
}
|
||||
|
||||
@GetMapping("/testMail")
|
||||
public BusiResult<Void> testMail(Long roomId) {
|
||||
if (null == roomId){
|
||||
throw new ServiceException(BusiStatus.PARAMERROR);
|
||||
}
|
||||
myApiService.testMail();
|
||||
return BusiResult.success();
|
||||
}
|
||||
}
|
||||
|
@@ -62,6 +62,12 @@ public class AccountBlockCheckService {
|
||||
return checkBlocked(phone, BlockTypeEnum.BLOCK_PHONE);
|
||||
}
|
||||
|
||||
public boolean checkBlockedEmail(String email){
|
||||
if (!StringUtils.hasText(email)){
|
||||
return false;
|
||||
}
|
||||
return checkBlocked(email, BlockTypeEnum.BLOCK_PHONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备是否被封禁
|
||||
|
@@ -0,0 +1,40 @@
|
||||
package com.accompany.common.constant;
|
||||
|
||||
/**
|
||||
* Created by PaperCut on 2018/7/23.
|
||||
*/
|
||||
public class EmailConstant {
|
||||
|
||||
public static final int EXPIRE_MINUTE = 3;
|
||||
|
||||
/**
|
||||
* 短信过期时间60秒
|
||||
*/
|
||||
public static final int EXPIRE_SECONDS = 60;
|
||||
|
||||
/**
|
||||
* 短信发送间隔时间,1分钟只能发1条
|
||||
*/
|
||||
public static final int SEND_INTERVAL_SECONDS = 60;
|
||||
|
||||
/**
|
||||
* 验证码短信类型
|
||||
*/
|
||||
public static class EmailType {
|
||||
|
||||
public static final Byte REGISTER = 1;//注册
|
||||
public static final Byte LOGIN = 2; //登录
|
||||
public static final Byte RESET_LOGIN_PASSWORD = 3;//忘记登录密码
|
||||
public static final Byte BINDING_PHONE = 4; //绑定手机
|
||||
public static final Byte BINDING_ALIPAY = 5; //绑定支付宝
|
||||
public static final Byte RESET_PAY_PASSWORD = 6; //重置支付密码
|
||||
public static final Byte UNBINDING_PHONE = 7; //更换绑定手机号码
|
||||
public static final Byte CERTIFICATION = 8; //实名认证
|
||||
public static final Byte H5_BINDING_ALIPAY = 9; //h5绑定支付宝
|
||||
public static final Byte SUPER_ADMIN_LOGIN = 10; //超管登录
|
||||
public static final Byte BINDING_BANK_CARD = 11; //绑定提现银行卡
|
||||
public static final Byte H5_BINDING_BANK_CARD = 12; //h5 绑定提现银行卡
|
||||
public static final Byte AUTH_CODE = 13; // 获取手机授权码
|
||||
}
|
||||
|
||||
}
|
@@ -1430,6 +1430,9 @@ public enum RedisKey {
|
||||
user_visitor_count,
|
||||
|
||||
user_visitor,
|
||||
|
||||
email_code,
|
||||
email_send_interval,
|
||||
;
|
||||
|
||||
public String getKey() {
|
||||
|
@@ -19,6 +19,7 @@ public enum BlockTypeEnum {
|
||||
BLOCK_DEVICE(3,"封禁设备","用户设备异常,请联系官方客服"),
|
||||
BLOCK_IP(4,"封禁IP","用户IP异常,请联系官方客服"),
|
||||
BLOCK_MUTE(5,"禁言",""),
|
||||
BLOCK_EMAIL(2, "封禁邮箱号","用户邮箱号异常,请联系官方客服"),
|
||||
;
|
||||
|
||||
BlockTypeEnum(int value, String desc, String blockDesc){
|
||||
|
23
accompany-base/accompany-email/accompany-email-sdk/pom.xml
Normal file
23
accompany-base/accompany-email/accompany-email-sdk/pom.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.accompany</groupId>
|
||||
<artifactId>accompany-email</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>accompany-email-sdk</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.accompany</groupId>
|
||||
<artifactId>accompany-core</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,18 @@
|
||||
package com.accompany.email.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@RefreshScope
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "aws.ses")
|
||||
public class AwsSesConfig {
|
||||
|
||||
private String accessKeyId;
|
||||
private String secretAccessKey;
|
||||
private String region;
|
||||
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.accompany.email.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@RefreshScope
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "email")
|
||||
public class EmailConfig {
|
||||
|
||||
private String appName;
|
||||
private String logoUrl;
|
||||
private String sender;
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package com.accompany.email.enums;
|
||||
|
||||
/**
|
||||
* @author: liaozetao
|
||||
* @date: 2023/8/14 15:14
|
||||
* @description:
|
||||
*/
|
||||
public enum SesTypeEnum {
|
||||
|
||||
AWS,
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
package com.accompany.email.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author yangming
|
||||
* @since 2020-04-13
|
||||
* 短信记录表
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("email_record")
|
||||
public class EmailRecord implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String email;
|
||||
|
||||
private String deviceId;
|
||||
|
||||
private String os;
|
||||
|
||||
private String channel;
|
||||
|
||||
private String appVersion;
|
||||
|
||||
private String model;
|
||||
|
||||
private String code;
|
||||
|
||||
private Integer sesType;
|
||||
|
||||
private String ip;
|
||||
|
||||
private String resCode;
|
||||
|
||||
private String resMsg;
|
||||
|
||||
private Date createTime;
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.accompany</groupId>
|
||||
<artifactId>accompany-email</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>accompany-email-service</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.accompany</groupId>
|
||||
<artifactId>accompany-email-sdk</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/sesv2 -->
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>sesv2</artifactId>
|
||||
<version>2.30.37</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,30 @@
|
||||
package com.accompany.email.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.sesv2.SesV2Client;
|
||||
|
||||
@Configuration
|
||||
public class AwsSecClientConfig {
|
||||
|
||||
@Autowired
|
||||
private AwsSesConfig config;
|
||||
|
||||
@Bean
|
||||
public SesV2Client awsSecClient() {
|
||||
AwsCredentialsProviderChain awsCredentialsProviderChain = AwsCredentialsProviderChain
|
||||
.builder()
|
||||
.addCredentialsProvider(() -> AwsBasicCredentials.create(config.getAccessKeyId(), config.getSecretAccessKey())).build();
|
||||
|
||||
Region region = Region.of(config.getRegion());
|
||||
return SesV2Client.builder()
|
||||
.region(region)
|
||||
.credentialsProvider(awsCredentialsProviderChain)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package com.accompany.email.mapper;
|
||||
|
||||
import com.accompany.email.model.EmailRecord;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author yangming
|
||||
* @since 2020-04-13
|
||||
*/
|
||||
public interface EmailRecordMapper extends BaseMapper<EmailRecord> {
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package com.accompany.email.service;
|
||||
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.email.mapper.EmailRecordMapper;
|
||||
import com.accompany.email.model.EmailRecord;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
public class EmailRecordService extends ServiceImpl<EmailRecordMapper, EmailRecord> {
|
||||
|
||||
/**
|
||||
* 插入记录
|
||||
* @param email
|
||||
* @param deviceInfo
|
||||
* @param ip
|
||||
* @param code
|
||||
* @param type
|
||||
*/
|
||||
public void saveRecord(String email, DeviceInfo deviceInfo, String ip, String code, Integer type,
|
||||
String resCode, String resMsg) {
|
||||
EmailRecord record = new EmailRecord();
|
||||
record.setEmail(email);
|
||||
if (deviceInfo != null){
|
||||
record.setDeviceId(deviceInfo.getDeviceId());
|
||||
record.setOs(deviceInfo.getOs());
|
||||
record.setModel(deviceInfo.getModel());
|
||||
record.setChannel(deviceInfo.getChannel());
|
||||
}
|
||||
record.setCreateTime(new Date());
|
||||
record.setIp(ip);
|
||||
record.setCode(code);
|
||||
record.setSesType(type);
|
||||
record.setResCode(resCode);
|
||||
record.setResMsg(resMsg);
|
||||
save(record);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,96 @@
|
||||
package com.accompany.email.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.accompany.common.constant.EmailConstant;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.RandomUtil;
|
||||
import com.accompany.common.utils.StringUtils;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.core.service.base.BaseService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.redisson.api.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
/**
|
||||
* @author yanhaoyu
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EmailService extends BaseService {
|
||||
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
@Autowired
|
||||
private EmailRecordService emailRecordService;
|
||||
|
||||
public void sendEmailCode(String emailAddress, Integer type, DeviceInfo deviceInfo, String ip, String code, boolean needRateLimit) {
|
||||
//todo 校验邮箱
|
||||
|
||||
if (StringUtils.isBlank(code)) {
|
||||
code = String.format("%d", RandomUtil.getFiveRandomNumber());
|
||||
}
|
||||
|
||||
String intervalKey = RedisKey.email_send_interval.getKey(emailAddress, type.toString());
|
||||
RBucket<String> intervalBucket = redissonClient.getBucket(intervalKey);
|
||||
if (intervalBucket.isExists()) {
|
||||
throw new ServiceException(BusiStatus.SMS_NOT_EXPIRED);
|
||||
}
|
||||
|
||||
RRateLimiter rateLimiter = null;
|
||||
if (needRateLimit){
|
||||
String ipKey = RedisKey.email_send_interval.getKey(ip);
|
||||
rateLimiter = redissonClient.getRateLimiter(ipKey);
|
||||
if (!rateLimiter.isExists()) {
|
||||
rateLimiter.trySetRate(RateType.OVERALL, 5, 1, RateIntervalUnit.DAYS);
|
||||
}
|
||||
|
||||
if (!rateLimiter.tryAcquire()){
|
||||
log.error("[email rateLimiter] {} {} 被限流了", ip, type);
|
||||
throw new ServiceException(BusiStatus.SMS_IP_TO_OFTEN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//新增短信记录
|
||||
emailRecordService.saveRecord(emailAddress, deviceInfo, ip, code, type, null, null);
|
||||
//todo 响应编码校验
|
||||
|
||||
// 写入短信发送频率
|
||||
intervalBucket.set(StrUtil.EMPTY, EmailConstant.SEND_INTERVAL_SECONDS, TimeUnit.SECONDS);
|
||||
|
||||
// 写入缓存
|
||||
String codeKey = RedisKey.email_code.getKey(emailAddress);
|
||||
RBucket<String> codeBucket = redissonClient.getBucket(codeKey);
|
||||
codeBucket.set(code, EmailConstant.EXPIRE_SECONDS, TimeUnit.SECONDS);
|
||||
|
||||
if (null != rateLimiter){
|
||||
rateLimiter.expire(1, TimeUnit.DAYS);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean verifyEmailCode(String emailAddress, String code) {
|
||||
logger.info("verifyEmailCode emailAddress : {}, code : {}", emailAddress, code);
|
||||
|
||||
Assert.notNull(emailAddress, "mobile is null");
|
||||
Assert.notNull(code, "code is null");
|
||||
|
||||
// 写入缓存
|
||||
String codeKey = RedisKey.email_code.getKey(emailAddress);
|
||||
RBucket<String> codeBucket = redissonClient.getBucket(codeKey);
|
||||
String codeCache = codeBucket.get();
|
||||
|
||||
logger.info("verifySmsCode codeKey : {}, codeCache : {} code : {}", codeKey, codeCache, code);
|
||||
if (StringUtils.equalsIgnoreCase(codeCache, code)) {
|
||||
return codeBucket.delete();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
19
accompany-base/accompany-email/pom.xml
Normal file
19
accompany-base/accompany-email/pom.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.accompany</groupId>
|
||||
<artifactId>accompany-base</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>accompany-email</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>accompany-email-sdk</module>
|
||||
<module>accompany-email-service</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
@@ -1,5 +1,8 @@
|
||||
package com.accompany.sms.strategy;
|
||||
|
||||
import com.accompany.sms.strategy.SmsContext;
|
||||
import com.accompany.sms.strategy.SmsResponse;
|
||||
|
||||
/**
|
||||
* @author: liaozetao
|
||||
* @date: 2023/8/14 14:59
|
||||
|
@@ -19,6 +19,7 @@
|
||||
<module>accompany-payment</module>
|
||||
<module>accompany-sharding</module>
|
||||
<module>accompany-sms</module>
|
||||
<module>accompany-email</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
@@ -33,6 +33,11 @@
|
||||
<artifactId>accompany-sms-sdk</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.accompany</groupId>
|
||||
<artifactId>accompany-email-sdk</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.accompany</groupId>
|
||||
<artifactId>accompany-business-world-sdk</artifactId>
|
||||
|
@@ -28,6 +28,11 @@
|
||||
<artifactId>accompany-sms-service</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.accompany</groupId>
|
||||
<artifactId>accompany-email-service</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.accompany</groupId>
|
||||
<artifactId>accompany-payment-service</artifactId>
|
||||
|
@@ -65,7 +65,6 @@ import com.accompany.core.service.common.JedisService;
|
||||
import com.accompany.core.service.partition.PartitionInfoService;
|
||||
import com.accompany.core.service.phone.PhoneAuthApplyRecordService;
|
||||
import com.accompany.core.service.region.RegionInfoService;
|
||||
import com.accompany.core.service.region.RegionNetworkSearchService;
|
||||
import com.accompany.core.service.region.RegionService;
|
||||
import com.accompany.core.service.user.UserCancelRecordService;
|
||||
import com.accompany.core.service.user.UsersBaseService;
|
||||
|
@@ -0,0 +1,90 @@
|
||||
package com.accompany.business.controller;
|
||||
|
||||
import com.accompany.business.common.BaseController;
|
||||
import com.accompany.common.constant.SmsTypeEnum;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.IPUtils;
|
||||
import com.accompany.core.enumeration.PartitionEnum;
|
||||
import com.accompany.core.service.account.AccountBlockCheckService;
|
||||
import com.accompany.core.util.I18NMessageSourceUtil;
|
||||
import com.accompany.email.service.EmailService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.accompany.core.enumeration.I18nAlertEnum.ACCOUNT_LOGIN_BLOCK_MSG;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/email")
|
||||
public class EmailController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private EmailService emailService;
|
||||
@Autowired
|
||||
private AccountBlockCheckService accountBlockCheckService;
|
||||
|
||||
private final static List<Integer> USE_PHONE_IN_PARAM_TYPES = Arrays.asList(SmsTypeEnum.REGISTER.value, SmsTypeEnum.LOGIN.value, SmsTypeEnum.SUPER_ADMIN_LOGIN.value,
|
||||
SmsTypeEnum.RESET_PASSWORD_FOR_NO_LOGIN.value, SmsTypeEnum.BINDING_PHONE.value);
|
||||
|
||||
@ApiOperation("发送邮箱验证码")
|
||||
@PostMapping(value = "getCode")
|
||||
public BusiResult<Void> getCode(String emailAddress, Integer type, HttpServletRequest request) {
|
||||
emailAddress = decryptSensitiveInfo(request, emailAddress);
|
||||
|
||||
String ip = IPUtils.getRealIpAddress(request);
|
||||
DeviceInfo deviceInfo = getDeviceInfo(request);
|
||||
Long uid = getUid(request);
|
||||
log.info("sendEmailCode, emailAddress:{}, type:{}, uid:{}", emailAddress, type, uid);
|
||||
|
||||
/*if(uid != null && !USE_PHONE_IN_PARAM_TYPES.contains(type.intValue())){
|
||||
log.info("需要通过uid获取用户已绑定的手机号");
|
||||
Users users = usersBaseService.getUsersByUid(uid);
|
||||
String userMobile = users == null ? mobile : users.getPhone();
|
||||
String userAreaCode = users == null ? phoneAreaCode : users.getPhoneAreaCode();
|
||||
// 如果headers里面有pub_uid,查询用户的手机号发送验证码
|
||||
if (CommonUtil.checkPhoneFormat(userAreaCode,userMobile)) {
|
||||
mobile = userMobile;
|
||||
phoneAreaCode = userAreaCode;
|
||||
}
|
||||
}*/
|
||||
log.info("sendEmailCode, email:{}, type:{}, uid:{}", emailAddress, type, uid);
|
||||
|
||||
//检查账号、设备号、号段是否封禁
|
||||
if (accountBlockCheckService.checkBlockedDevice(deviceInfo.getDeviceId())) {
|
||||
return new BusiResult<>(BusiStatus.ACCOUNT_BLOCK_ERROR, I18NMessageSourceUtil.getMessage(ACCOUNT_LOGIN_BLOCK_MSG, new Object[]{deviceInfo.getDeviceId()}, PartitionEnum.ENGLISH.getId()));
|
||||
}
|
||||
if (accountBlockCheckService.checkBlockedIp(ip)) {
|
||||
return new BusiResult<>(BusiStatus.ACCOUNT_BLOCK_ERROR, I18NMessageSourceUtil.getMessage(ACCOUNT_LOGIN_BLOCK_MSG, new Object[]{ip}, PartitionEnum.ENGLISH.getId()));
|
||||
}
|
||||
if (accountBlockCheckService.checkBlockedEmail(emailAddress)) {
|
||||
return new BusiResult<>(BusiStatus.ACCOUNT_BLOCK_ERROR, I18NMessageSourceUtil.getMessage(ACCOUNT_LOGIN_BLOCK_MSG, new Object[]{emailAddress}, PartitionEnum.ENGLISH.getId()));
|
||||
}
|
||||
|
||||
emailService.sendEmailCode(emailAddress, type, deviceInfo, ip, null, true);
|
||||
|
||||
return new BusiResult<>(BusiStatus.SMS_SEND_SUCCESS);
|
||||
}
|
||||
|
||||
@ApiParam("校验邮箱验证码")
|
||||
@PostMapping(value = "/verify")
|
||||
public BusiResult<Void> verify(String emailAddress, String code, HttpServletRequest request) {
|
||||
emailAddress = decryptSensitiveInfo(request, emailAddress);
|
||||
|
||||
boolean verify = emailService.verifyEmailCode(emailAddress, code);
|
||||
if (!verify) {
|
||||
return BusiResult.fail(BusiStatus.SMS_VERIFY_CODE_ERROR);
|
||||
}
|
||||
return BusiResult.success();
|
||||
}
|
||||
}
|
@@ -87,6 +87,7 @@
|
||||
<sa-token.version>1.34.0</sa-token.version>
|
||||
<pinyin4j.version>2.5.1</pinyin4j.version>
|
||||
<cloudauth20190307.version>1.0.1</cloudauth20190307.version>
|
||||
<aws.version>2.30.37</aws.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@@ -143,12 +144,6 @@
|
||||
<version>${hippo4j-config-spring-boot-starter.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson-spring-data-20</artifactId>
|
||||
<version>${redisson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
@@ -269,12 +264,6 @@
|
||||
<version>${commons-math.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sf.dozer</groupId>
|
||||
<artifactId>dozer</artifactId>
|
||||
<version>${dozer.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.jchardet</groupId>
|
||||
<artifactId>jchardet</artifactId>
|
||||
|
Reference in New Issue
Block a user