| | |
| | | .build(); |
| | | |
| | | private static final String API_URL = "https://apiv2.aoksend.com/index/api/send_email"; |
| | | private static final String APP_KEY = "7c653bf4e8398f676de6182a5ac100ed"; // 从环境变量或配置文件中获取 |
| | | private static final String TEMPLATE_ID = "E_139512804023"; //模板 |
| | | private static final String APP_KEY = "5573452ba45eb7743b970c1b66fcd6a2"; |
| | | private static final String TEMPLATE_ID_REGISTER = "E_143737413621"; |
| | | private static final String TEMPLATE_ID_RECHARGE = "E_143738794901"; |
| | | private static final String TEMPLATE_ID_WITHDRAW = "E_143732815203"; |
| | | @Override |
| | | public void send(EmailMessage emailMessage) { |
| | | // 验证邮件信息数据的有效性 |
| | |
| | | logger.info("----- 开始发送邮件 -----"); |
| | | logger.info("发送邮件到: " + emailMessage.getTomail() + ", 来自: " + emailMessage.getContent()); |
| | | |
| | | String templateId = resolveTemplateId(emailMessage); |
| | | String codeValue = emailMessage.getContent(); |
| | | if (codeValue == null) { |
| | | codeValue = ""; |
| | | } |
| | | |
| | | // 使用 URL 构建器构建带有查询参数的 URL |
| | | HttpUrl.Builder urlBuilder = HttpUrl.parse(API_URL).newBuilder(); |
| | | urlBuilder.addQueryParameter("app_key", APP_KEY); |
| | | urlBuilder.addQueryParameter("template_id", TEMPLATE_ID); |
| | | urlBuilder.addQueryParameter("template_id", templateId); |
| | | urlBuilder.addQueryParameter("to", emailMessage.getTomail()); |
| | | |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | Map<String, String> dataMap = new HashMap<>(); |
| | | dataMap.put("code", emailMessage.getContent()); |
| | | dataMap.put("code", codeValue); |
| | | |
| | | String json = objectMapper.writeValueAsString(dataMap); |
| | | urlBuilder.addQueryParameter("data", json); |
| | |
| | | } catch (Exception e) { |
| | | logger.error("邮件发送失败【Exception】", e); |
| | | } |
| | | } |
| | | |
| | | private String resolveTemplateId(EmailMessage emailMessage) { |
| | | String subject = emailMessage == null || emailMessage.getSubject() == null |
| | | ? "" |
| | | : emailMessage.getSubject().toLowerCase(); |
| | | if (subject.contains("deposit") || subject.contains("recharge") || subject.contains("充值")) { |
| | | return TEMPLATE_ID_RECHARGE; |
| | | } |
| | | if (subject.contains("withdraw") || subject.contains("提现")) { |
| | | return TEMPLATE_ID_WITHDRAW; |
| | | } |
| | | return TEMPLATE_ID_REGISTER; |
| | | } |
| | | |
| | | /** |
| | |
| | | // 使用 URL 构建器构建带有查询参数的 URL |
| | | HttpUrl.Builder urlBuilder = HttpUrl.parse(API_URL).newBuilder(); |
| | | urlBuilder.addQueryParameter("app_key", APP_KEY); |
| | | urlBuilder.addQueryParameter("template_id", TEMPLATE_ID); |
| | | urlBuilder.addQueryParameter("template_id", TEMPLATE_ID_REGISTER); |
| | | urlBuilder.addQueryParameter("to", emailMessage.getTomail()); |
| | | |
| | | // 将邮件内容以 JSON 形式传递 |