From 8f31ee92f62021540480f83f029e67cf6a75fc3a Mon Sep 17 00:00:00 2001 From: 3y Date: Wed, 24 Aug 2022 20:30:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E4=BF=A1=E6=81=AF=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/SendAccountConstant.java | 1 - .../austin/common/enums/SmsSupplier.java | 37 +++++++++ .../RefreshDingDingAccessTokenHandler.java | 19 +++-- .../RefreshGeTuiAccessTokenHandler.java | 25 +++--- .../austin/handler/domain/sms/SmsParam.java | 6 ++ .../handler/handler/impl/SmsHandler.java | 2 + .../handler/receipt/MessageReceipt.java | 28 +------ ...entSmsReceipt.java => SmsPullReceipt.java} | 78 ++++++++++++------- .../handler/receipt/YunPianSmsReceipt.java | 25 ------ .../handler/script/impl/TencentSmsScript.java | 2 +- .../handler/script/impl/YunPianSmsScript.java | 2 +- .../austin/support/utils/AccountUtils.java | 32 +++++++- .../src/main/resources/application.properties | 70 +++++++++-------- austin-web/src/main/resources/logback.xml | 2 +- 14 files changed, 192 insertions(+), 137 deletions(-) create mode 100644 austin-common/src/main/java/com/java3y/austin/common/enums/SmsSupplier.java rename austin-handler/src/main/java/com/java3y/austin/handler/receipt/{TencentSmsReceipt.java => SmsPullReceipt.java} (53%) delete mode 100644 austin-handler/src/main/java/com/java3y/austin/handler/receipt/YunPianSmsReceipt.java diff --git a/austin-common/src/main/java/com/java3y/austin/common/constant/SendAccountConstant.java b/austin-common/src/main/java/com/java3y/austin/common/constant/SendAccountConstant.java index baedd24..3f90cc2 100644 --- a/austin-common/src/main/java/com/java3y/austin/common/constant/SendAccountConstant.java +++ b/austin-common/src/main/java/com/java3y/austin/common/constant/SendAccountConstant.java @@ -88,7 +88,6 @@ public class SendAccountConstant { /** * 短信账号code */ - public static final Integer TENCENT_SMS_CODE = 10; public static final Integer YUN_PIAN_SMS_CODE = 20; diff --git a/austin-common/src/main/java/com/java3y/austin/common/enums/SmsSupplier.java b/austin-common/src/main/java/com/java3y/austin/common/enums/SmsSupplier.java new file mode 100644 index 0000000..818acba --- /dev/null +++ b/austin-common/src/main/java/com/java3y/austin/common/enums/SmsSupplier.java @@ -0,0 +1,37 @@ +package com.java3y.austin.common.enums; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.ToString; + +/** + * 短信渠道商 + * @author 3y + */ +@Getter +@ToString +@AllArgsConstructor +public enum SmsSupplier { + + + TENCENT(10,"腾讯渠道商"), + YUN_PAIN(20,"云片渠道商"); + private Integer code; + private String description; + + + /** + * 根据状态获取描述信息 + * @param code + * @return + */ + public static String getDescriptionByStatus(Integer code) { + for (SmsStatus value : SmsStatus.values()) { + if (value.getCode().equals(code)) { + return value.getDescription(); + } + } + return ""; + } +} diff --git a/austin-cron/src/main/java/com/java3y/austin/cron/handler/RefreshDingDingAccessTokenHandler.java b/austin-cron/src/main/java/com/java3y/austin/cron/handler/RefreshDingDingAccessTokenHandler.java index 25f378e..5bb1478 100644 --- a/austin-cron/src/main/java/com/java3y/austin/cron/handler/RefreshDingDingAccessTokenHandler.java +++ b/austin-cron/src/main/java/com/java3y/austin/cron/handler/RefreshDingDingAccessTokenHandler.java @@ -1,6 +1,7 @@ package com.java3y.austin.cron.handler; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import com.dingtalk.api.DefaultDingTalkClient; import com.dingtalk.api.DingTalkClient; import com.dingtalk.api.request.OapiGettokenRequest; @@ -9,7 +10,10 @@ import com.google.common.base.Throwables; import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.common.constant.SendAccountConstant; import com.java3y.austin.common.dto.account.DingDingWorkNoticeAccount; +import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.support.config.SupportThreadPoolConfig; +import com.java3y.austin.support.dao.ChannelAccountDao; +import com.java3y.austin.support.domain.ChannelAccount; import com.java3y.austin.support.utils.AccountUtils; import com.xxl.job.core.handler.annotation.XxlJob; import lombok.extern.slf4j.Slf4j; @@ -17,6 +21,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; +import java.util.List; + /** * 刷新钉钉的access_token @@ -36,7 +42,8 @@ public class RefreshDingDingAccessTokenHandler { private StringRedisTemplate redisTemplate; @Autowired - private AccountUtils accountUtils; + private ChannelAccountDao channelAccountDao; + /** * 每小时请求一次接口刷新(以防失效) @@ -45,14 +52,12 @@ public class RefreshDingDingAccessTokenHandler { public void execute() { log.info("refreshAccessTokenJob#execute!"); SupportThreadPoolConfig.getPendingSingleThreadPool().execute(() -> { - for (int index = SendAccountConstant.START; true; index = index + SendAccountConstant.STEP) { - DingDingWorkNoticeAccount account = accountUtils.getAccount(index, SendAccountConstant.DING_DING_WORK_NOTICE_ACCOUNT_KEY, SendAccountConstant.DING_DING_WORK_NOTICE_PREFIX, DingDingWorkNoticeAccount.class); - if (account == null) { - break; - } + List accountList = channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(AustinConstant.FALSE, ChannelType.DING_DING_WORK_NOTICE.getCode()); + for (ChannelAccount channelAccount : accountList) { + DingDingWorkNoticeAccount account = JSON.parseObject(channelAccount.getAccountConfig(), DingDingWorkNoticeAccount.class); String accessToken = getAccessToken(account); if (StrUtil.isNotBlank(accessToken)) { - redisTemplate.opsForValue().set(SendAccountConstant.DING_DING_ACCESS_TOKEN_PREFIX + index, accessToken); + redisTemplate.opsForValue().set(SendAccountConstant.DING_DING_ACCESS_TOKEN_PREFIX + channelAccount.getId(), accessToken); } } }); diff --git a/austin-cron/src/main/java/com/java3y/austin/cron/handler/RefreshGeTuiAccessTokenHandler.java b/austin-cron/src/main/java/com/java3y/austin/cron/handler/RefreshGeTuiAccessTokenHandler.java index b000df9..a978e52 100644 --- a/austin-cron/src/main/java/com/java3y/austin/cron/handler/RefreshGeTuiAccessTokenHandler.java +++ b/austin-cron/src/main/java/com/java3y/austin/cron/handler/RefreshGeTuiAccessTokenHandler.java @@ -7,11 +7,15 @@ import cn.hutool.http.Header; import cn.hutool.http.HttpRequest; import com.alibaba.fastjson.JSON; import com.google.common.base.Throwables; +import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.common.constant.SendAccountConstant; import com.java3y.austin.common.dto.account.GeTuiAccount; -import com.java3y.austin.cron.dto.getui.QueryTokenParamDTO; +import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.cron.dto.getui.GeTuiTokenResultDTO; +import com.java3y.austin.cron.dto.getui.QueryTokenParamDTO; import com.java3y.austin.support.config.SupportThreadPoolConfig; +import com.java3y.austin.support.dao.ChannelAccountDao; +import com.java3y.austin.support.domain.ChannelAccount; import com.java3y.austin.support.utils.AccountUtils; import com.xxl.job.core.handler.annotation.XxlJob; import lombok.extern.slf4j.Slf4j; @@ -19,6 +23,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; +import java.util.List; + /** * 刷新个推的token @@ -35,7 +41,8 @@ public class RefreshGeTuiAccessTokenHandler { private StringRedisTemplate redisTemplate; @Autowired - private AccountUtils accountUtils; + private ChannelAccountDao channelAccountDao; + /** * 每小时请求一次接口刷新(以防失效) @@ -44,14 +51,14 @@ public class RefreshGeTuiAccessTokenHandler { public void execute() { log.info("refreshGeTuiAccessTokenJob#execute!"); SupportThreadPoolConfig.getPendingSingleThreadPool().execute(() -> { + List accountList = channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(AustinConstant.FALSE, ChannelType.PUSH.getCode()); for (int index = SendAccountConstant.START; true; index = index + SendAccountConstant.STEP) { - GeTuiAccount account = accountUtils.getAccount(index, SendAccountConstant.GE_TUI_ACCOUNT_KEY, SendAccountConstant.GE_TUI_ACCOUNT_PREFIX, GeTuiAccount.class); - if (account == null) { - break; - } - String accessToken = getAccessToken(account); - if (StrUtil.isNotBlank(accessToken)) { - redisTemplate.opsForValue().set(SendAccountConstant.GE_TUI_ACCESS_TOKEN_PREFIX + index, accessToken); + for (ChannelAccount channelAccount : accountList) { + GeTuiAccount account = JSON.parseObject(channelAccount.getAccountConfig(), GeTuiAccount.class); + String accessToken = getAccessToken(account); + if (StrUtil.isNotBlank(accessToken)) { + redisTemplate.opsForValue().set(SendAccountConstant.GE_TUI_ACCESS_TOKEN_PREFIX + index, accessToken); + } } } }); diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/domain/sms/SmsParam.java b/austin-handler/src/main/java/com/java3y/austin/handler/domain/sms/SmsParam.java index 74eee4f..96a5881 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/domain/sms/SmsParam.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/domain/sms/SmsParam.java @@ -24,6 +24,12 @@ public class SmsParam { */ private Set phones; + /** + * 发送渠道账号的Id + */ + private Integer sendAccountId; + + /** * 发送文案 */ diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java index d8cd98f..4db4632 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java @@ -56,7 +56,9 @@ public class SmsHandler extends BaseHandler implements Handler { .phones(taskInfo.getReceiver()) .content(getSmsContent(taskInfo)) .messageTemplateId(taskInfo.getMessageTemplateId()) + .sendAccountId(taskInfo.getSendAccount()) .build(); + try { /** * 1、动态配置做流量负载 diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/receipt/MessageReceipt.java b/austin-handler/src/main/java/com/java3y/austin/handler/receipt/MessageReceipt.java index 00f955f..1ad7ce3 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/receipt/MessageReceipt.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/receipt/MessageReceipt.java @@ -1,31 +1,15 @@ package com.java3y.austin.handler.receipt; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.date.DatePattern; -import cn.hutool.core.date.DateUtil; -import com.alibaba.fastjson.JSON; -import com.google.common.base.Throwables; -import com.java3y.austin.common.constant.SendAccountConstant; -import com.java3y.austin.common.dto.account.TencentSmsAccount; -import com.java3y.austin.common.enums.SmsStatus; import com.java3y.austin.support.config.SupportThreadPoolConfig; -import com.java3y.austin.support.domain.SmsRecord; -import com.tencentcloudapi.sms.v20210111.SmsClient; -import com.tencentcloudapi.sms.v20210111.models.PullSmsSendStatus; -import com.tencentcloudapi.sms.v20210111.models.PullSmsSendStatusRequest; -import com.tencentcloudapi.sms.v20210111.models.PullSmsSendStatusResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; /** - * 拉取短信回执信息 + * 拉取回执信息 * * @author 3y */ @@ -34,22 +18,18 @@ import java.util.List; public class MessageReceipt { @Autowired - private TencentSmsReceipt tencentSmsReceipt; - - @Autowired - private YunPianSmsReceipt yunPianSmsReceipt; + private SmsPullReceipt smsPullReceipt; @PostConstruct private void init() { SupportThreadPoolConfig.getPendingSingleThreadPool().execute(() -> { while (true) { - // TODO 回执这里自行打开(免得报错) -// tencentSmsReceipt.pull(); -// yunPianSmsReceipt.pull(); + // smsPullReceipt.pull(); try { Thread.sleep(200); } catch (InterruptedException e) { + e.printStackTrace(); } } }); diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/receipt/TencentSmsReceipt.java b/austin-handler/src/main/java/com/java3y/austin/handler/receipt/SmsPullReceipt.java similarity index 53% rename from austin-handler/src/main/java/com/java3y/austin/handler/receipt/TencentSmsReceipt.java rename to austin-handler/src/main/java/com/java3y/austin/handler/receipt/SmsPullReceipt.java index 704422e..bb7dd2c 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/receipt/TencentSmsReceipt.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/receipt/SmsPullReceipt.java @@ -5,64 +5,95 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSON; import com.google.common.base.Throwables; -import com.java3y.austin.common.constant.SendAccountConstant; +import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.common.dto.account.TencentSmsAccount; +import com.java3y.austin.common.dto.account.YunPianSmsAccount; +import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.common.enums.SmsStatus; -import com.java3y.austin.support.config.SupportThreadPoolConfig; +import com.java3y.austin.common.enums.SmsSupplier; +import com.java3y.austin.support.dao.ChannelAccountDao; import com.java3y.austin.support.dao.SmsRecordDao; +import com.java3y.austin.support.domain.ChannelAccount; import com.java3y.austin.support.domain.SmsRecord; -import com.java3y.austin.support.utils.AccountUtils; import com.tencentcloudapi.common.Credential; import com.tencentcloudapi.common.profile.ClientProfile; import com.tencentcloudapi.common.profile.HttpProfile; import com.tencentcloudapi.sms.v20210111.SmsClient; -import com.tencentcloudapi.sms.v20210111.models.*; +import com.tencentcloudapi.sms.v20210111.models.PullSmsSendStatus; +import com.tencentcloudapi.sms.v20210111.models.PullSmsSendStatusRequest; +import com.tencentcloudapi.sms.v20210111.models.PullSmsSendStatusResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; import java.util.ArrayList; import java.util.Date; import java.util.List; /** - * 拉取腾讯云短信回执信息 + * 拉取短信回执信息 * * @author 3y */ @Component @Slf4j -public class TencentSmsReceipt { - +public class SmsPullReceipt { @Autowired - private AccountUtils accountUtils; + private ChannelAccountDao channelAccountDao; @Autowired private SmsRecordDao smsRecordDao; - /** * 拉取消息并入库 + *

+ * eg accountList:[{"sms_10":{"url":"sms.tencentcloudapi.com","region":"ap-guangzhou","secretId":"234234","secretKey":"234324324","smsSdkAppId":"2343242","templateId":"234234","signName":"Java3y公众号","supplierId":10,"supplierName":"腾讯云"}},{"sms_20":{"url":"https://sms.yunpian.com/v2/sms/tpl_batch_send.json","apikey":"23423432","tpl_id":"23423432","supplierId":20,"supplierName":"云片"}}] */ public void pull() { + List channelAccountList = channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(AustinConstant.FALSE, ChannelType.SMS.getCode()); + for (ChannelAccount channelAccount : channelAccountList) { + Integer supplierId = JSON.parseObject(channelAccount.getAccountConfig()).getInteger("supplierId"); + if (SmsSupplier.TENCENT.getCode().equals(supplierId)) { + TencentSmsAccount tencentSmsAccount = JSON.parseObject(channelAccount.getAccountConfig(), TencentSmsAccount.class); + pullTencent(tencentSmsAccount); + } else if (SmsSupplier.YUN_PAIN.getCode().equals(supplierId)) { + YunPianSmsAccount yunPianSmsAccount = JSON.parseObject(channelAccount.getAccountConfig(), YunPianSmsAccount.class); + pullYunPain(yunPianSmsAccount); + } + } + } - // 获取腾讯云账号信息 - TencentSmsAccount account = accountUtils.getAccount(10, SendAccountConstant.SMS_ACCOUNT_KEY, SendAccountConstant.SMS_PREFIX, TencentSmsAccount.class); + /** + * 拉取腾讯的回执 + * + * @param account + */ + private void pullTencent(TencentSmsAccount account) { try { - SmsClient client = getSmsClient(account); + /** + * 初始化客户端 + */ + HttpProfile httpProfile = new HttpProfile(); + httpProfile.setEndpoint(account.getUrl()); + ClientProfile clientProfile = new ClientProfile(); + clientProfile.setHttpProfile(httpProfile); + SmsClient client = new SmsClient(new Credential(account.getSecretId(), account.getSecretKey()), account.getRegion(), clientProfile); - // 每次拉取10条 + /** + * 每次拉取10条 + */ PullSmsSendStatusRequest req = new PullSmsSendStatusRequest(); req.setLimit(10L); req.setSmsSdkAppId(account.getSmsSdkAppId()); + /** + * 拉取回执后入库 + */ PullSmsSendStatusResponse resp = client.PullSmsSendStatus(req); List smsRecordList = new ArrayList<>(); if (resp != null && resp.getPullSmsSendStatusSet() != null && resp.getPullSmsSendStatusSet().length > 0) { - log.debug("receipt sms:{}", JSON.toJSONString(resp.getPullSmsSendStatusSet())); for (PullSmsSendStatus pullSmsSendStatus : resp.getPullSmsSendStatusSet()) { SmsRecord smsRecord = SmsRecord.builder() .sendDate(Integer.valueOf(DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN))) @@ -89,20 +120,7 @@ public class TencentSmsReceipt { } } - /** - * 构造smsClient - * - * @param account - * @return - */ - private SmsClient getSmsClient(TencentSmsAccount account) { - Credential cred = new Credential(account.getSecretId(), account.getSecretKey()); - HttpProfile httpProfile = new HttpProfile(); - httpProfile.setEndpoint(account.getUrl()); - ClientProfile clientProfile = new ClientProfile(); - clientProfile.setHttpProfile(httpProfile); - return new SmsClient(cred, account.getRegion(), clientProfile); - } - + private void pullYunPain(YunPianSmsAccount yunPianSmsAccount) { + } } diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/receipt/YunPianSmsReceipt.java b/austin-handler/src/main/java/com/java3y/austin/handler/receipt/YunPianSmsReceipt.java deleted file mode 100644 index 1e6442d..0000000 --- a/austin-handler/src/main/java/com/java3y/austin/handler/receipt/YunPianSmsReceipt.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.java3y.austin.handler.receipt; - - -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - - - -/** - * 拉取云片网短信回执信息 - * - * @author 3y - */ -@Component -@Slf4j -public class YunPianSmsReceipt { - /** - * 拉取消息并入库 - */ - public void pull() { - - } - -} diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/TencentSmsScript.java b/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/TencentSmsScript.java index 3412560..8df4d12 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/TencentSmsScript.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/TencentSmsScript.java @@ -49,7 +49,7 @@ public class TencentSmsScript extends BaseSmsScript implements SmsScript { @Override public List send(SmsParam smsParam) { try { - TencentSmsAccount tencentSmsAccount = accountUtils.getAccount(SendAccountConstant.TENCENT_SMS_CODE, SendAccountConstant.SMS_ACCOUNT_KEY, SendAccountConstant.SMS_PREFIX, TencentSmsAccount.class); + TencentSmsAccount tencentSmsAccount = accountUtils.getAccount(smsParam.getSendAccountId(), SendAccountConstant.SMS_ACCOUNT_KEY, SendAccountConstant.SMS_PREFIX, TencentSmsAccount.class); SmsClient client = init(tencentSmsAccount); SendSmsRequest request = assembleReq(smsParam, tencentSmsAccount); SendSmsResponse response = client.SendSms(request); diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/YunPianSmsScript.java b/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/YunPianSmsScript.java index c4ac233..19f6f9e 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/YunPianSmsScript.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/script/impl/YunPianSmsScript.java @@ -39,7 +39,7 @@ public class YunPianSmsScript extends BaseSmsScript implements SmsScript { public List send(SmsParam smsParam) { try { - YunPianSmsAccount account = accountUtils.getAccount(SendAccountConstant.YUN_PIAN_SMS_CODE, SendAccountConstant.SMS_ACCOUNT_KEY, SendAccountConstant.SMS_PREFIX, YunPianSmsAccount.class); + YunPianSmsAccount account = accountUtils.getAccount(smsParam.getSendAccountId(), SendAccountConstant.SMS_ACCOUNT_KEY, SendAccountConstant.SMS_PREFIX, YunPianSmsAccount.class); Map params = assembleParam(smsParam, account); String result = HttpRequest.post(account.getUrl()) diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java index 7b82971..37ce656 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java +++ b/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java @@ -3,24 +3,33 @@ package com.java3y.austin.support.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.ctrip.framework.apollo.Config; -import com.ctrip.framework.apollo.spring.annotation.ApolloConfig; +import com.google.common.base.Throwables; import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.support.dao.ChannelAccountDao; +import com.java3y.austin.support.domain.ChannelAccount; import com.java3y.austin.support.service.ConfigService; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.Optional; + /** * 获取账号信息工具类 * * @author 3y */ @Component +@Slf4j public class AccountUtils { @Autowired private ConfigService config; + @Autowired + private ChannelAccountDao channelAccountDao; + + /** * (key:smsAccount)短信参数示例:[{"sms_10":{"url":"sms.tencentcloudapi.com","region":"ap-guangzhou","secretId":"AKIDhDxxxxxxxx1WljQq","secretKey":"B4hwww39yxxxrrrrgxyi","smsSdkAppId":"1423123125","templateId":"1182097","signName":"Java3y公众号","supplierId":10,"supplierName":"腾讯云"}},{"sms_20":{"url":"https://sms.yunpian.com/v2/sms/tpl_batch_send.json","apikey":"caffff8234234231b5cd7","tpl_id":"523333332","supplierId":20,"supplierName":"云片"}}] * (key:emailAccount)邮件参数示例:[{"email_10":{"host":"smtp.qq.com","port":465,"user":"23423423@qq.com","pass":"23423432432423423","from":"234@qq.com","starttlsEnable":true,"auth":true,"sslEnable":true}},{"email_20":{"host":"smtp.163.com","port":465,"user":"22222@163.com","pass":"23432423","from":"234324324234@163.com","starttlsEnable":false,"auth":true,"sslEnable":true}}] @@ -30,12 +39,27 @@ public class AccountUtils { * (key:officialAccount) 微信服务号模板消息参数示例:[{"official_10":{"appId":"wxecb4693d2eef1ea7","secret":"624asdfsa1640d769ba20120821","templateId":"JHUk6eE9T5Ts7asdfsadfiKNDQsk-Q","url":"http://weixin.qq.com/download","miniProgramId":"xiaochengxuappid12345","path":"index?foo=bar"}}] * (key:miniProgramAccount) 微信小程序订阅消息参数示例:[{"mini_program_10":{"appId":"wxecb4693d2eef1ea7","appSecret":"6240870f4d91701640d769ba20120821","templateId":"JHUk6eE9T5TasdfCrQsk-Q","grantType":"client_credential","miniProgramState":"trial","page":"index?foo=bar"}}] */ - public T getAccount(Integer sendAccount, String apolloKey, String prefix, Class clazz) { + public T getAccount(Integer sendAccountId, String apolloKey, String prefix, Class clazz) { + + /** + * 优先读数据库的,数据库没有才读配置 + */ + try { + Optional optionalChannelAccount = channelAccountDao.findById(Long.valueOf(sendAccountId)); + if (optionalChannelAccount.isPresent()) { + ChannelAccount channelAccount = optionalChannelAccount.get(); + return JSON.parseObject(channelAccount.getAccountConfig(), clazz); + } + } catch (Exception e) { + log.warn("AccountUtils#getAccount not found:{}", Throwables.getStackTraceAsString(e)); + } + + String accountValues = config.getProperty(apolloKey, AustinConstant.APOLLO_DEFAULT_VALUE_JSON_ARRAY); JSONArray jsonArray = JSON.parseArray(accountValues); for (int i = 0; i < jsonArray.size(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); - T object = jsonObject.getObject(prefix + sendAccount, clazz); + T object = jsonObject.getObject(prefix + sendAccountId, clazz); if (object != null) { return object; } diff --git a/austin-web/src/main/resources/application.properties b/austin-web/src/main/resources/application.properties index 2de4250..2b31cf3 100644 --- a/austin-web/src/main/resources/application.properties +++ b/austin-web/src/main/resources/application.properties @@ -40,18 +40,18 @@ austin.nacos.enabled=false # todo [grayLog] ip 【optional】 austin.grayLog.ip=austin.graylog -##################### system properties ##################### -server.shutdown=graceful - +# TODO if windows os and need upload file to send message ,replace path !【optional】 +austin.business.upload.crowd.path=/Users/3y/temp -##################### database properties ##################### +########################################## database start ########################################## # notice:mysql version 5.7x !!! spring.datasource.url=jdbc:mysql://${austin.database.ip}:${austin.database.port}/austin?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull spring.datasource.username=${austin.database.username} spring.datasource.password=${austin.database.password} spring.datasource.driver-class-name=com.mysql.jdbc.Driver +########################################## database end ########################################## -##################### kafka properties ##################### +########################################## kafka start ########################################## spring.kafka.bootstrap-servers=${austin.kafka.ip}:${austin.kafka.port} spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer @@ -61,55 +61,47 @@ spring.kafka.consumer.auto.offset.reset=earliest spring.kafka.consumer.auto-commit-interval=1000 spring.kafka.consumer.enable-auto-commit=true -##################### rocketmq properties ##################### +### +austin.business.topic.name=austinBusiness +austin.business.recall.topic.name=austinRecall +austin.business.recall.group.name=recallGroupId +austin.business.log.topic.name=austinTraceLog +### TODO kafka tag filter,if you need, replace tagIdValue ,eg:com.java3y.austin.yyy +austin.business.tagId.key=kafka_tag_id +austin.business.tagId.value=com.java3y.austin.3y +########################################## kafka end ########################################## + +########################################## rocketMq start ########################################## rocketmq.name-server=${austin.rocketmq.nameserver.ip}:${austin.rocketmq.nameserver.port} rocketmq.producer.group=unique-producer-group austin.rocketmq.biz.consumer.group=unique-biz-consumer-group austin.rocketmq.recall.consumer.group=unique-recall-consumer-group +########################################## rocketMq end ########################################## - -##################### Rabbit properties ##################### -#RabbitMq所在服务器IP +########################################## RabbitMq start ########################################## spring.rabbitmq.host=${austin.rabbitmq.ip} -#连接端口号 spring.rabbitmq.port=${austin.rabbitmq.port} - server.port=8080 spring.application.name=cl -#用户名 spring.rabbitmq.username=root -#用户密码 spring.rabbitmq.password=123456 -# 开启发送确认 spring.rabbitmq.publisher-confirm-type=correlated -# 开启发送失败退回 spring.rabbitmq.publisher-returns=true spring.rabbitmq.virtual-host=/ austin.rabbitmq.topic.name=austinRabbit austin.rabbitmq.exchange.name=austin.point +########################################## RabbitMq end ########################################## -##################### redis properties ##################### +########################################## redis start ########################################## spring.redis.host=${austin.redis.ip} spring.redis.port=${austin.redis.port} spring.redis.password=${austin.redis.password} +########################################## redis end ########################################## -##################### business properties ##################### -austin.business.topic.name=austinBusiness -austin.business.recall.topic.name=austinRecall -austin.business.recall.group.name=recallGroupId -austin.business.log.topic.name=austinTraceLog -austin.business.graylog.ip=${austin.grayLog.ip} - -# TODO kafka tag filter,if you need, replace tagIdValue ,eg:com.java3y.austin.yyy -austin.business.tagId.key=kafka_tag_id -austin.business.tagId.value=com.java3y.austin.3y - -# TODO if windows os and need upload file to send message ,replace path ! -austin.business.upload.crowd.path=/Users/3y/temp -##################### xxl properties ##################### +########################################## xxl start ########################################## xxl.job.admin.addresses=http://${austin.xxl.job.ip}:${austin.xxl.job.port}/xxl-job-admin xxl.job.admin.username=admin xxl.job.admin.password=123456 @@ -120,30 +112,40 @@ xxl.job.executor.port=6666 xxl.job.executor.logpath=logs/xxl xxl.job.executor.logretentiondays=30 xxl.job.accessToken= +########################################## xxl end ########################################## -##################### apollo ##################### +########################################## apollo start ########################################## app.id=austin apollo.bootstrap.enabled=${austin.apollo.enabled} apollo.bootstrap.namespaces=boss.austin,dynamic-tp-apollo-dtp.yml +########################################## apollo end ########################################## -##################### nacos ##################### +########################################## nacos start ########################################## austin.nacos.server= austin.nacos.dataId=austin austin.nacos.group=DEFAULT_GROUP austin.nacos.namespace=9537c674-f3a6-4203-b286-ef0c36bfacb2 nacos.config.enabled=${austin.nacos.enabled} +########################################## nacos end ########################################## -##################### httpUtils properties ##################### +########################################## httpUtils start ########################################## ok.http.connect-timeout=30 ok.http.keep-alive-duration=300 ok.http.max-idle-connections=200 ok.http.read-timeout=30 ok.http.write-timeout=30 +########################################## httpUtils end ########################################## -##################### monitor properties ##################### +########################################## monitor start ########################################## management.endpoint.health.show-details=always management.endpoint.metrics.enabled=true management.endpoint.prometheus.enabled=true management.endpoints.web.exposure.include=* management.metrics.export.prometheus.enabled=true management.health.rabbit.enabled=false +########################################## monitor end ########################################## + +########################################## system start ########################################## +server.shutdown=graceful +########################################## system end ########################################## + diff --git a/austin-web/src/main/resources/logback.xml b/austin-web/src/main/resources/logback.xml index 824f367..838e611 100644 --- a/austin-web/src/main/resources/logback.xml +++ b/austin-web/src/main/resources/logback.xml @@ -7,7 +7,7 @@ - +