7 Commits

5 changed files with 141 additions and 85 deletions

View File

@@ -1030,15 +1030,25 @@ public class SendEmailUtil {
private final static Long CN_2025_618 = 141425L;
private final static Long EN_2025_618 = 141424L;
private final static Long CN_GLOBAL_AWARDS = 166716L;
private final static Long EN_GLOBAL_AWARDS = 166715L;
private final static Long GLOBAL_AWARDS_2 = 173919L;
// 复用 SesClient避免每次发送都创建新连接
private static SesClient getSesClient() {
Credential cred = new Credential(SECRET_ID, SECRET_KEy);
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("ses.tencentcloudapi.com");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
return new SesClient(cred, "ap-hongkong", clientProfile);
}
public static void send618PromotionEmailTemp(String receiver, String language){
SesClient client = null;
try {
// 实例化一个认证对象
Credential cred = new Credential(SECRET_ID, SECRET_KEy);
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("ses.tencentcloudapi.com");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
SesClient client = new SesClient(cred, "ap-hongkong", clientProfile);
client = getSesClient();
SendEmailRequest req = new SendEmailRequest();
req.setFromEmailAddress(CODE_CREATE_SEND_ADDRESS);
req.setDestination(new String[]{receiver});
@@ -1046,20 +1056,15 @@ public class SendEmailUtil {
// 根据邮件类型设置不同的主题和模板
String subject = "";
Template template = new Template();
// if (type == 1) {
// subject = "Upcoming System Upgrade for AiDA 3.0";
// template.setTemplateID(UPGRADE_NOTIFICATION_ID);
// }else {
// subject = "即将到来的AiDA 3.0系统升级";
// template.setTemplateID(UPGRADE_NOTIFICATION_ID_CHINESE);
// }
if (language.equals("ENGLISH")) {
subject = "Welcome back Subscribe AiDA with the discount code to enjoy 50% OFF!";
template.setTemplateID(EN_2025_618);
subject = "AiDA Global Design Awards 2026 | The Journey Starts Now ! \nAiDA 全球设计大奖 2026 | 从现在开始你的创作之旅 !";
template.setTemplateID(GLOBAL_AWARDS_2);
/*if (language.equals("ENGLISH")) {
subject = "From Idea to Wow. \uD83D\uDD25 | AiDA Demo & Global Awards";
template.setTemplateID(EN_GLOBAL_AWARDS);
}else {
subject = "设计时速狂飙AiDA 618半价让灵感永不限流";
template.setTemplateID(CN_2025_618);
}
subject = "灵感开挂,创作起飞 \uD83D\uDD25 | AiDA Demo & 全球设计大奖";
template.setTemplateID(CN_GLOBAL_AWARDS);
}*/
req.setSubject(subject);
req.setTemplate(template);
@@ -1069,9 +1074,7 @@ public class SendEmailUtil {
log.info("邮件发送成功,收件人地址:{}", receiver);
log.info("短信发送结果res###{}", SendEmailResponse.toJsonString(resp));
} catch (TencentCloudSDKException e) {
log.info(receiver);
log.error("邮件发送失败###{},收件人地址:{}", e.toString(), receiver);
log.error("邮件发送失败,收件人地址:{},错误信息:{}", receiver, e.toString());
}
}

View File

@@ -20,72 +20,92 @@ public class SendRequestUtil {
@Value("${FREEPIK_API_KEY}")
private String FREEPIK_API_KEY;
public String sendAliYunPostAsync(String apiUrl, String requestBody){
// 发送POST请求 todo 异常处理
HttpResponse execute = HttpRequest.post(apiUrl)
public String sendAliYunPostAsync(String apiUrl, String requestBody) {
// 发送POST请求
try (HttpResponse execute = HttpRequest.post(apiUrl)
.header(Header.AUTHORIZATION, "Bearer " + ALIYUN_API_KEY)
.header("X-DashScope-Async", "enable")
.header(Header.CONTENT_TYPE, "application/json")
.body(requestBody)
.timeout(20000) // 设置超时时间20秒
.execute();
int status = execute.getStatus();
if (status == 200){
String body = execute.body();
JSONObject bodyJson = JSONUtil.parseObj(body);
return body;
.execute()) {
int status = execute.getStatus();
if (status == 200) {
String body = execute.body();
JSONObject bodyJson = JSONUtil.parseObj(body);
return body;
}
log.warn("请求失败,状态码为:{},响应内容:{}", status, execute.body());
} catch (Exception e) {
log.error("请求阿里云API时发生异常URL{},请求体:{},异常信息:{}",
apiUrl, requestBody, e.getMessage(), e);
}
log.warn("请求失败,状态码为 {}", status);
return null;
}
public String sendAliYunPost(String apiUrl, String requestBody){
// 发送POST请求 todo 异常处理
HttpResponse execute = HttpRequest.post(apiUrl)
public String sendAliYunPost(String apiUrl, String requestBody) {
// 发送POST请求
try (HttpResponse execute = HttpRequest.post(apiUrl)
.header(Header.AUTHORIZATION, "Bearer " + ALIYUN_API_KEY)
.header(Header.CONTENT_TYPE, "application/json")
.body(requestBody)
.timeout(20000) // 设置超时时间20秒
.execute();
int status = execute.getStatus();
if (status == 200){
String body = execute.body();
JSONObject bodyJson = JSONUtil.parseObj(body);
return body;
.execute()) {
int status = execute.getStatus();
if (status == 200) {
String body = execute.body();
JSONObject bodyJson = JSONUtil.parseObj(body);
return body;
}
log.warn("请求失败,状态码为:{},响应内容:{}", status, execute.body());
} catch (Exception e) {
log.error("请求阿里云API时发生异常URL{},请求体:{},异常信息:{}",
apiUrl, requestBody, e.getMessage(), e);
}
log.warn("请求失败,状态码为 {}", status);
return null;
}
public static final String FREE_PIK = "https://api.freepik.com/v1/ai/beta/text-to-image/reimagine-flux";
public String sendFreepikPost( String requestBody){
// 发送POST请求 todo 异常处理
HttpResponse execute = HttpRequest.post(FREE_PIK)
public String sendFreepikPost(String requestBody) {
// 发送POST请求
try (HttpResponse execute = HttpRequest.post(FREE_PIK)
.header(Header.CONTENT_TYPE, "application/json")
.header("x-freepik-api-key", FREEPIK_API_KEY)
.body(requestBody)
.timeout(20000) // 设置超时时间20秒
.execute();
int status = execute.getStatus();
if (status == 200){
return execute.body();
.execute()) {
int status = execute.getStatus();
if (status == 200) {
return execute.body();
}
log.warn("请求失败,状态码为:{},响应内容:{}", status, execute.body());
} catch (Exception e) {
log.error("请求Freepik API时发生异常请求体{},异常信息:{}",
requestBody, e.getMessage(), e);
}
log.warn("请求失败,状态码为 {}", status);
return null;
}
public String sendAliYunGet(String fullUrl){
// 发送GET请求 todo 异常处理
HttpResponse httpResponse = HttpRequest.get(fullUrl)
public String sendAliYunGet(String fullUrl) {
// 发送GET请求
try (HttpResponse httpResponse = HttpRequest.get(fullUrl)
.header(Header.AUTHORIZATION, "Bearer " + ALIYUN_API_KEY)
.timeout(20000) // 设置超时时间20秒
.execute();
int status = httpResponse.getStatus();
if (status == 200){
return httpResponse.body();
}else {
return null;
.execute()) {
int status = httpResponse.getStatus();
if (status == 200) {
return httpResponse.body();
}
log.warn("请求失败,状态码为:{},响应内容:{}", status, httpResponse.body());
} catch (Exception e) {
log.error("请求阿里云API时发生异常URL{},异常信息:{}",
fullUrl, e.getMessage(), e);
}
return null;
}
/*public String sendFluxPost(String url, String requestBodyStr){

View File

@@ -380,12 +380,12 @@ public class AccountController {
return Response.success(accountService.subAccountImport(file));
}
/*@GetMapping("/send618Email")
@GetMapping("/send618Email")
@Operation(summary = "618邮件发送")
public Response<String> send618PromotionEmailTemp() {
accountService.send618PromotionEmailTemp();
return Response.success("success");
}*/
}
/*@GetMapping("/refreshCreditsMonthly")
@Operation(summary = "刷新子账号积分")

View File

@@ -239,7 +239,7 @@ public interface AccountService extends IService<Account> {
Set<String> organizationNameSearch(String type, String name);
/*void send618PromotionEmailTemp();*/
void send618PromotionEmailTemp();
void checkEduAdminExpireStatus();

View File

@@ -3670,33 +3670,66 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
return new HashSet<>();
}
/* @Override
@Override
public void send618PromotionEmailTemp() {
QueryWrapper<TrialOrder> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("is_deleted", 0);
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
List<TrialOrder> trialOrders = trialOrderMapper.selectList(queryWrapper);
queryWrapper.lambda()
.isNotNull(Account::getUserEmail)
.in(Account::getUserEmail, "xupei3360@163.com", "kimwong@code-create.com.hk", "kaicpang.pang@connect.polyu.hk", "chelseayu@code-create.com.hk")
.apply("LENGTH(TRIM(user_email)) > 0");
// List<Account> accountList = accountMapper.selectList(queryWrapper);
System.out.println(trialOrders);
int total = trialOrders.size();
log.info("试用用户总量:{}", total);
int current = 1;
for (TrialOrder trialOrder : trialOrders) {
log.info("邮件发送进度 {}/{}", current, total);
try {
if (!StringUtil.isNullOrEmpty(trialOrder.getCountry()) && trialOrder.getCountry().equals("China")) {
SendEmailUtil.send618PromotionEmailTemp(trialOrder.getEmail(), "CHINESE_SIMPLIFIED");
} else {
// 英文
SendEmailUtil.send618PromotionEmailTemp(trialOrder.getEmail(), "ENGLISH");
}
}catch (Exception e) {
log.info(e.getMessage());
List<Account> accounts = baseMapper.selectList(queryWrapper);
// 按邮箱去重,保留每个邮箱的第一条记录
Map<String, Account> emailToAccountMap = new LinkedHashMap<>();
for (Account account : accounts) {
String email = account.getUserEmail();
if (!StringUtil.isNullOrEmpty(email)) {
email = email.trim().toLowerCase();
// 保留第一次出现的记录
emailToAccountMap.putIfAbsent(email, account);
}
current ++;
}
}*/
List<String> uniqueEmails = new ArrayList<>(emailToAccountMap.keySet());
int total = uniqueEmails.size();
log.info("AiDA用户去重后邮件发送总量{}", total);
// 控制发送速率每发送20封后等待1秒控制QPS在20以内
int batchSize = 20;
long sleepMillis = 1000;
int successCount = 0;
int failCount = 0;
for (int i = 0; i < uniqueEmails.size(); i++) {
String email = uniqueEmails.get(i);
log.info("邮件发送进度 {}/{}", i + 1, total);
try {
// 统一发送英文版本
// log.info("邮件地址 {}", email);
SendEmailUtil.send618PromotionEmailTemp(email, "ENGLISH");
successCount++;
} catch (Exception e) {
failCount++;
log.error("邮件发送失败,收件人:{},错误信息:{}", email, e.getMessage());
}
// 控制发送速率,每发送 batchSize 封后等待
if ((i + 1) % batchSize == 0 && (i + 1) < uniqueEmails.size()) {
try {
Thread.sleep(sleepMillis);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.warn("邮件发送被中断");
break;
}
}
}
log.info("邮件发送完成,成功:{},失败:{}", successCount, failCount);
}
@Override
public void checkEduAdminExpireStatus() {