TASK:十月优惠邮件发送接口;

This commit is contained in:
shahaibo
2024-10-03 12:14:30 +08:00
parent 28e67db78d
commit 8445c23984
3 changed files with 58 additions and 0 deletions

View File

@@ -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");
}
}
}

View File

@@ -254,5 +254,12 @@ public class AccountController {
return Response.success("success");
}
@PostMapping("halfPricePromotion")
@ApiOperation(value = "十月半价活动")
public Response<Boolean> halfPricePromotion() {
accountService.halfPricePromotion();
return Response.success(true);
}
}

View File

@@ -179,4 +179,6 @@ public interface AccountService extends IService<Account> {
void activateNewEmail(String token);
String updateNoLoginRequiredNew(NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request);
void halfPricePromotion();
}