diff --git a/src/main/java/com/ai/da/common/utils/SendEmailUtil.java b/src/main/java/com/ai/da/common/utils/SendEmailUtil.java index 67ec92e5..358319a5 100644 --- a/src/main/java/com/ai/da/common/utils/SendEmailUtil.java +++ b/src/main/java/com/ai/da/common/utils/SendEmailUtil.java @@ -718,4 +718,53 @@ public class SendEmailUtil { throw new BusinessException("failed.to.send.mail"); } } + + private final static Long HALFPRICEPROMOTION_CN_ID = 128556L; + private final static Long HALFPRICEPROMOTION_EN_ID = 128557L; + public static void halfPricePromotion(Account account, String senderAddress, int type) { + 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); + SendEmailRequest req = new SendEmailRequest(); + if (StringUtils.isEmpty(senderAddress)) { + senderAddress = CODE_CREATE_SEND_ADDRESS; + } + req.setFromEmailAddress(senderAddress); + req.setDestination(new String[]{account.getUserEmail()}); + + // 根据邮件类型设置不同的主题和模板 + 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 (type == 1) { + subject = "AiDA Limited Time Offer"; + template.setTemplateID(HALFPRICEPROMOTION_EN_ID); + }else { + subject = "AiDA国庆优惠活动"; + template.setTemplateID(HALFPRICEPROMOTION_CN_ID); + } + template.setTemplateData(buildAccountData(account)); + + req.setSubject(subject); + req.setTemplate(template); + + // 发送邮件 + SendEmailResponse resp = client.SendEmail(req); + log.info("短信发送结果res###{}", SendEmailResponse.toJsonString(resp)); + } catch (TencentCloudSDKException e) { + log.info("邮件发送失败###{}", e.toString()); + throw new BusinessException("failed.to.send.mail"); + } + } } diff --git a/src/main/java/com/ai/da/controller/AccountController.java b/src/main/java/com/ai/da/controller/AccountController.java index 60fb806c..c73fcdaa 100644 --- a/src/main/java/com/ai/da/controller/AccountController.java +++ b/src/main/java/com/ai/da/controller/AccountController.java @@ -254,5 +254,12 @@ public class AccountController { return Response.success("success"); } + @PostMapping("halfPricePromotion") + @ApiOperation(value = "十月半价活动") + public Response halfPricePromotion() { + accountService.halfPricePromotion(); + return Response.success(true); + } + } diff --git a/src/main/java/com/ai/da/service/AccountService.java b/src/main/java/com/ai/da/service/AccountService.java index 8aca8e2a..5db57bc8 100644 --- a/src/main/java/com/ai/da/service/AccountService.java +++ b/src/main/java/com/ai/da/service/AccountService.java @@ -179,4 +179,6 @@ public interface AccountService extends IService { void activateNewEmail(String token); String updateNoLoginRequiredNew(NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request); + + void halfPricePromotion(); }