diff --git a/README.md b/README.md index bf70fd4..ca4c95b 100644 --- a/README.md +++ b/README.md @@ -63,14 +63,14 @@ austin项目**核心流程**:`austin-api`接收到发送消息请求,直接 目前引用的中间件教程的安装姿势均基于`Centos 7.6`,austin项目**强依赖**`MySQL`/`Redis`/(**大概需要2G内存**),**弱依赖**`kafka`/`prometheus`/`graylog`/`flink`/`xxl-job`/`apollo`(**完全部署所有的服务,大概8G+内存**)。如果缺少相关的组件可戳:[安装相关组件教程](INSTALL.md)。 -> 实在想要`clone`项目后不用自己部署环境直接在本地启动`debug`,我这提供了[会员服务](https://mp.weixin.qq.com/s?__biz=MzI4Njg5MDA5NA==&mid=2247505577&idx=1&sn=5114f8f583755899c2946fbea0b22e4b&chksm=ebd497a8dca31ebe8f98344483a00c860863dfc3586e51eed95b25988151427fee8101311f4f&token=735778370&lang=zh_CN#rd),**直连**部署好的服务器 +> 实在想要`clone`项目后不用自己部署环境直接在本地启动`debug`,我这提供了[会员服务](https://mp.weixin.qq.com/s/4cOhNG5JBSvBkbSKTfw7eQ),**直连**部署好的服务器 **1**、austin使用的MySQL版本**5.7x**。如果目前使用的MySQL版本8.0,注意改变`pom.xml`所依赖的版本 **2**、填写`application.properties`中`austin-database`对应的`ip/port/username/password`信息 -**3**、执行`sql`文件夹下的`austin.sql`创建对应的表以及插入测试数据 +**3**、执行`sql`文件夹下的`austin.sql`创建对应的表 **4**、如果配置`austin.mq.pipeline=kafka`,需要填写`application.properties`中`austin.kafka`对应的`ip`/`port`信息 @@ -80,15 +80,7 @@ austin项目**核心流程**:`austin-api`接收到发送消息请求,直接 **7**、以上配置信息都在`application.properties`文件中修改。(`prometheus`/`graylog`/`flink`/`xxl-job`/`apollo`可选) -**8**、发送渠道**账号的信息**都配置在**local.properties**,配置的示例参照`com.java3y.austin.support.utils#getAccount`中的注释 - -**10**、调用http接口`com.java3y.austin.web.controller#send`给自己发一条邮件或短信感受(**邮件门槛相对较低,建议配置邮件**) - -```shell -curl -XPOST "127.0.0.1:8080/send" -H 'Content-Type: application/json' -d '{"code":"send","messageParam":{"extra":null,"receiver":"13719333899"},"messageTemplateId":1}' -``` - -**11**、austin前端管理系统部署(一分钟即能打开),戳[GitHub](https://github.com/ZhongFuCheng3y/austin-admin)或[Gitee](https://gitee.com/zhongfucheng/austin-admin)查看 +**8**、austin前端管理系统部署(一分钟即能打开),戳[GitHub](https://github.com/ZhongFuCheng3y/austin-admin)或[Gitee](https://gitee.com/zhongfucheng/austin-admin)查看 ![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a023d9082fa644bda9b50144e02985cb~tplv-k3u1fbpfcp-zoom-1.image) @@ -98,6 +90,14 @@ curl -XPOST "127.0.0.1:8080/send" -H 'Content-Type: application/json' -d '{"co ![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/01d028359e6e4229825a7fd8cc22c6c7~tplv-k3u1fbpfcp-zoom-1.image) +**9**、发送渠道**账号的信息**都在**账号**,配置的示例可参照对应的提示案例 + +![](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/2039b96045494ded8e6f55528eb20b1d~tplv-k3u1fbpfcp-watermark.image?) + +**10**、新建一个模板消息(**邮件门槛相对较低,建议配置邮件**) + +**11**、测试发送一条消息 + **12**、正常使用**数据管理**(查看实时数据链路下发)需要将`austin-stream`的`jar`包上传至`Flink`,根据[部署文档](INSTALL.md)启动Flink。在打`jar`包前需要填写`com.java3y.austin.stream.constants.AustinFlinkConstant`中的`redis`和`kafka`的`ip/port`(注:日志的topic在`application.properties`中的`austin.business.log.topic.name`。如果没有该topic,需要提前创建,并使用Kafka作为消息队列实现) **13**、正常使用**定时任务**需要部署`xxl-job`,根据[部署文档](INSTALL.md)启动xxl的调度中心,并在`application.properteis`中填写 `austin.xxl.job.ip`和`austin.xxl.job.port` @@ -124,7 +124,7 @@ curl -XPOST "127.0.0.1:8080/send" -H 'Content-Type: application/json' -d '{"co 5、除了项目,还可以问我些学习经验、学习路线、简历编写、面试经验等等问题,技术和学习上的知识**知无不言** -详情可以看戳:[我开通了付费渠道](https://mp.weixin.qq.com/s?__biz=MzI4Njg5MDA5NA==&mid=2247507166&idx=1&sn=d4437089c2db18b90a6d3ec742380554&chksm=ebd49ddfdca314c94d49a02da2ecb1358ac08d86616b6f1fce34720cc96e81d3006a51e86beb&token=28465847&lang=zh_CN#rd) +详情可以看戳:[我开通了付费渠道](https://mp.weixin.qq.com/s/4cOhNG5JBSvBkbSKTfw7eQ) ## 项目交流 @@ -147,6 +147,8 @@ curl -XPOST "127.0.0.1:8080/send" -H 'Content-Type: application/json' -d '{"co ## 里程碑 +![](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/80fc1c550ee145eda95cfac4bd617a04~tplv-k3u1fbpfcp-watermark.image?) + - [x] Maven+SpringBoot项目搭建 - [x] logback日志记录项目运行时信息,引入common/guava/Hutool/Lombok/fastjson/OkHttp工具包 - [x] 接入腾讯云渠道发送一条短信 @@ -178,9 +180,10 @@ curl -XPOST "127.0.0.1:8080/send" -H 'Content-Type: application/json' -d '{"co - [x] 完成接入钉钉工作渠道所有类型的消息,包括对文件素材的上传功能 - [x] Kafka消息支持tag过滤 - [x] MQ层支持可插拔,默认使用eventbus单机队列,Kafka变为弱依赖 +- [x] 渠道账号改为读取数据库,优化短信回执拉取功能 - [ ] 总体架构已完成,持续做基础建设和优化代码 -**近期更新时间**:7月11号 +**近期更新时间**:11月27号 -**近期更新功能**:MQ层可插拔重构 \ No newline at end of file +**近期更新功能**:渠道账号改为读取数据库,优化短信回执拉取功能 \ No newline at end of file diff --git a/austin-common/src/main/java/com/java3y/austin/common/constant/AustinConstant.java b/austin-common/src/main/java/com/java3y/austin/common/constant/AustinConstant.java index cb23a55..026887a 100644 --- a/austin-common/src/main/java/com/java3y/austin/common/constant/AustinConstant.java +++ b/austin-common/src/main/java/com/java3y/austin/common/constant/AustinConstant.java @@ -2,30 +2,16 @@ package com.java3y.austin.common.constant; /** - * 基础的常量信息 + * Austin常量信息 * * @author 3y */ public class AustinConstant { /** - * boolean转换 + * 跨域地址端口 */ - public final static Integer TRUE = 1; - public final static Integer FALSE = 0; - - /** - * cron时间格式 - */ - public final static String CRON_FORMAT = "ss mm HH dd MM ? yyyy-yyyy"; - - - /** - * apollo默认的值 - */ - public final static String APOLLO_DEFAULT_VALUE_JSON_OBJECT = "{}"; - public final static String APOLLO_DEFAULT_VALUE_JSON_ARRAY = "[]"; - + public static final String ORIGIN_VALUE = "http://localhost:3000"; /** * businessId默认的长度 @@ -33,6 +19,10 @@ public class AustinConstant { */ public final static Integer BUSINESS_ID_LENGTH = 16; + /** + * 接口限制 最多的人数 + */ + public static final Integer BATCH_RECEIVER_SIZE = 100; /** * 消息发送给全部人的标识 @@ -43,23 +33,5 @@ public class AustinConstant { public static final String SEND_ALL = "@all"; - /** - * 加密算法 - */ - public static final String HMAC_SHA256_ENCRYPTION_ALGO = "HmacSHA256"; - - /** - * 编码格式 - */ - public static final String CHARSET_NAME = "UTF-8"; - - - /** - * HTTP 请求方法 - */ - public static final String REQUEST_METHOD_GET = "GET"; - public static final String REQUEST_METHOD_POST = "POST"; - - } diff --git a/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java b/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java index ffc9088..8f41ae7 100644 --- a/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java +++ b/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java @@ -1,6 +1,7 @@ package com.java3y.austin.common.constant; public class CommonConstant { + public final static String PERIOD = "."; public final static String COMMA = ","; public final static String COLON = ":"; @@ -9,10 +10,54 @@ public class CommonConstant { public final static String SLASH = "/"; public final static String BACKSLASH = "\\"; public final static String EMPTY_STRING = ""; - // + public final static String RADICAL = "|"; + + public final static String QM_STRING = "?"; + public final static String EQUAL_STRING = "="; + public final static String AND_STRING = "&"; + + public final static String ONE = "1"; public final static String ZERO = "0"; public final static String MINUS_ONE = "-1"; public final static String YES = "Y"; public final static String NO = "N"; + + + public final static char QM = '?'; + + /** + * boolean转换 + */ + public final static Integer TRUE = 1; + public final static Integer FALSE = 0; + + + /** + * 加密算法 + */ + public static final String HMAC_SHA256_ENCRYPTION_ALGO = "HmacSHA256"; + + /** + * 编码格式 + */ + public static final String CHARSET_NAME = "UTF-8"; + + /** + * HTTP 请求方法 + */ + public static final String REQUEST_METHOD_GET = "GET"; + public static final String REQUEST_METHOD_POST = "POST"; + + /** + * JSON默认值 + */ + public final static String EMPTY_JSON_OBJECT = "{}"; + public final static String EMPTY_VALUE_JSON_ARRAY = "[]"; + + /** + * cron时间格式 + */ + public final static String CRON_FORMAT = "ss mm HH dd MM ? yyyy-yyyy"; + } \ No newline at end of file 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 675c81f..67b5df8 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 @@ -3,99 +3,19 @@ package com.java3y.austin.common.constant; /** * 发送账号的常量信息汇总 - *

- * (读取apollo的key和前缀) - *

- * 约定:所有的账号都从10开始,步长为10 - * * @author 3y */ public class SendAccountConstant { - /** - * 账号约定:所有的账号都从10开始,步长为10 - */ - public static final Integer START = 10; - public static final Integer STEP = 10; - - /** * 钉钉 工作应用消息 账号 */ - public static final String DING_DING_WORK_NOTICE_ACCOUNT_KEY = "dingDingWorkNoticeAccount"; - public static final String DING_DING_WORK_NOTICE_PREFIX = "ding_ding_work_notice_"; public static final String DING_DING_ACCESS_TOKEN_PREFIX = "ding_ding_access_token_"; /** * 个推PUSH 消息账号 */ - public static final String GE_TUI_ACCOUNT_KEY = "geTuiAccount"; - public static final String GE_TUI_ACCOUNT_PREFIX = "ge_tui_account_"; public static final String GE_TUI_ACCESS_TOKEN_PREFIX = "ge_tui_access_token_"; - - /** - * 邮件 账号 - */ - public static final String EMAIL_ACCOUNT_KEY = "emailAccount"; - public static final String EMAIL_ACCOUNT_PREFIX = "email_"; - - - /** - * 钉钉群自定义机器人 账号 - */ - public static final String DING_DING_ROBOT_ACCOUNT_KEY = "dingDingRobotAccount"; - public static final String DING_DING_ROBOT_PREFIX = "ding_ding_robot_"; - - /** - * 企业微信群机器人 账号 - */ - public static final String ENTERPRISE_WECHAT_ROBOT_ACCOUNT_KEY = "enterpriseWechatAccountRobot"; - public static final String ENTERPRISE_WECHAT_ROBOT_PREFIX = "enterprise_wechat_robot_"; - - /** - * 飞书群机器人 账号 - */ - public static final String FEI_SHU_ROBOT_ACCOUNT_KEY = "feiShuAccountRobot"; - public static final String FEI_SHU_ROBOT_PREFIX = "fei_shu_robot_"; - - /** - * 企业微信 应用消息 账号 - */ - public static final String ENTERPRISE_WECHAT_ACCOUNT_KEY = "enterpriseWechatAccount"; - public static final String ENTERPRISE_WECHAT_PREFIX = "enterprise_wechat_"; - - /** - * 微信服务号 应用消息 账号 - */ - public static final String WECHAT_OFFICIAL_ACCOUNT_KEY = "officialAccount"; - public static final String WECHAT_OFFICIAL__PREFIX = "official_"; - - /** - * 微信小程序 应用消息 账号 - */ - public static final String WECHAT_MINI_PROGRAM_ACCOUNT_KEY = "miniProgramAccount"; - public static final String WECHAT_MINI_PROGRAM_PREFIX = "mini_program_"; - - /** - * 支付宝小程序 应用消息 账号 - */ - public static final String ALIPAY_MINI_PROGRAM_ACCOUNT_KEY = "alipayMiniProgramAccount"; - public static final String ALIPAY_MINI_PROGRAM_PREFIX = "alipay_mini_program_"; - - /** - * 短信 账号 - */ - public static final String SMS_ACCOUNT_KEY = "smsAccount"; - public static final String SMS_PREFIX = "sms_"; - - - /** - * 短信账号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/dto/account/TencentSmsAccount.java b/austin-common/src/main/java/com/java3y/austin/common/dto/account/TencentSmsAccount.java deleted file mode 100644 index 81a1353..0000000 --- a/austin-common/src/main/java/com/java3y/austin/common/dto/account/TencentSmsAccount.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.java3y.austin.common.dto.account; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * 腾讯短信参数 - * - * 参数示例: - * [{"sms_10":{"url":"sms.tencentcloudapi.com","region":"ap-guangzhou","secretId":"AKIDhDUUDfffffMEqBF1WljQq","secretKey":"B4h39yWnfffff7D2btue7JErDJ8gxyi","smsSdkAppId":"140025","templateId":"11897","signName":"Java3y公众号","supplierId":10,"supplierName":"腾讯云"}}] - * - * @author 3y - */ -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -public class TencentSmsAccount { - - /** - * api相关 - */ - private String url; - private String region ; - - /** - * 账号相关 - */ - private String secretId; - private String secretKey; - private String smsSdkAppId; - private String templateId; - private String signName; - - /** - * 标识渠道商Id - */ - private Integer supplierId; - - /** - * 标识渠道商名字 - */ - private String supplierName; - -} diff --git a/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/SmsAccount.java b/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/SmsAccount.java new file mode 100644 index 0000000..9d1c99f --- /dev/null +++ b/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/SmsAccount.java @@ -0,0 +1,28 @@ +package com.java3y.austin.common.dto.account.sms; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class SmsAccount { + /** + * 标识渠道商Id + */ + protected Integer supplierId; + + /** + * 标识渠道商名字 + */ + protected String supplierName; + + /** + * 【重要】类名,定位到具体的处理"下发"/"回执"逻辑 + * 依据ScriptName对应具体的某一个短信账号 + */ + protected String scriptName; + + +} diff --git a/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/TencentSmsAccount.java b/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/TencentSmsAccount.java new file mode 100644 index 0000000..73fe7cf --- /dev/null +++ b/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/TencentSmsAccount.java @@ -0,0 +1,34 @@ +package com.java3y.austin.common.dto.account.sms; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 腾讯短信参数 + *

+ * 账号参数示例: + * {"url":"sms.tencentcloudapi.com","region":"ap-guangzhou","secretId":"AKIDhDxxxxxxxx1WljQq","secretKey":"B4hwww39yxxxrrrrgxyi","smsSdkAppId":"1423123125","templateId":"1182097","signName":"Java3y公众号","supplierId":10,"supplierName":"腾讯云","scriptName":"TencentSmsScript"} + * + * @author 3y + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class TencentSmsAccount extends SmsAccount { + + /** + * api相关 + */ + private String url; + private String region; + + /** + * 账号相关 + */ + private String secretId; + private String secretKey; + private String smsSdkAppId; + private String templateId; + private String signName; +} diff --git a/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/YunPianSmsAccount.java b/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/YunPianSmsAccount.java new file mode 100644 index 0000000..f33e369 --- /dev/null +++ b/austin-common/src/main/java/com/java3y/austin/common/dto/account/sms/YunPianSmsAccount.java @@ -0,0 +1,34 @@ +package com.java3y.austin.common.dto.account.sms; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 云片账号信息 + *

+ * 账号参数示例: + * {"url":"https://sms.yunpian.com/v2/sms/tpl_batch_send.json","apikey":"caffff8234234231b5cd7","tpl_id":"523333332","supplierId":20,"supplierName":"云片","scriptName":"YunPianSmsScript"} + * + * @author 3y + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class YunPianSmsAccount extends SmsAccount { + + /** + * apikey + */ + private String apikey; + /** + * tplId + */ + private String tplId; + + /** + * api相关 + */ + private String url; + +} 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..84b5c59 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,15 +1,20 @@ 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; import com.dingtalk.api.response.OapiGettokenResponse; import com.google.common.base.Throwables; import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.constant.CommonConstant; 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 +22,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 +43,8 @@ public class RefreshDingDingAccessTokenHandler { private StringRedisTemplate redisTemplate; @Autowired - private AccountUtils accountUtils; + private ChannelAccountDao channelAccountDao; + /** * 每小时请求一次接口刷新(以防失效) @@ -45,14 +53,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(CommonConstant.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); } } }); @@ -71,7 +77,7 @@ public class RefreshDingDingAccessTokenHandler { OapiGettokenRequest req = new OapiGettokenRequest(); req.setAppkey(account.getAppKey()); req.setAppsecret(account.getAppSecret()); - req.setHttpMethod(AustinConstant.REQUEST_METHOD_GET); + req.setHttpMethod(CommonConstant.REQUEST_METHOD_GET); OapiGettokenResponse rsp = client.execute(req); accessToken = rsp.getAccessToken(); } catch (Exception e) { 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..94977fe 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,16 @@ 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.CommonConstant; 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 +24,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 +42,8 @@ public class RefreshGeTuiAccessTokenHandler { private StringRedisTemplate redisTemplate; @Autowired - private AccountUtils accountUtils; + private ChannelAccountDao channelAccountDao; + /** * 每小时请求一次接口刷新(以防失效) @@ -44,14 +52,12 @@ public class RefreshGeTuiAccessTokenHandler { public void execute() { log.info("refreshGeTuiAccessTokenJob#execute!"); SupportThreadPoolConfig.getPendingSingleThreadPool().execute(() -> { - 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; - } + List accountList = channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(CommonConstant.FALSE, ChannelType.PUSH.getCode()); + 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); + redisTemplate.opsForValue().set(SendAccountConstant.GE_TUI_ACCESS_TOKEN_PREFIX + channelAccount.getId(), accessToken); } } }); diff --git a/austin-cron/src/main/java/com/java3y/austin/cron/pending/CrowdBatchTaskPending.java b/austin-cron/src/main/java/com/java3y/austin/cron/pending/CrowdBatchTaskPending.java index 50339ab..7b420df 100644 --- a/austin-cron/src/main/java/com/java3y/austin/cron/pending/CrowdBatchTaskPending.java +++ b/austin-cron/src/main/java/com/java3y/austin/cron/pending/CrowdBatchTaskPending.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.StrUtil; import com.google.common.collect.Lists; +import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.cron.config.CronAsyncThreadPoolConfig; import com.java3y.austin.cron.constants.PendingConstant; import com.java3y.austin.cron.vo.CrowdInfoVo; @@ -40,9 +41,9 @@ public class CrowdBatchTaskPending extends AbstractLazyPending { public CrowdBatchTaskPending() { PendingParam pendingParam = new PendingParam<>(); - pendingParam.setNumThreshold(PendingConstant.NUM_THRESHOLD) - .setQueue(new LinkedBlockingQueue(PendingConstant.QUEUE_SIZE)) + pendingParam.setQueue(new LinkedBlockingQueue(PendingConstant.QUEUE_SIZE)) .setTimeThreshold(PendingConstant.TIME_THRESHOLD) + .setNumThreshold(AustinConstant.BATCH_RECEIVER_SIZE) .setExecutorService(CronAsyncThreadPoolConfig.getConsumePendingThreadPool()); this.pendingParam = pendingParam; } diff --git a/austin-cron/src/main/java/com/java3y/austin/cron/xxl/utils/XxlJobUtils.java b/austin-cron/src/main/java/com/java3y/austin/cron/xxl/utils/XxlJobUtils.java index cb6de84..4df140c 100644 --- a/austin-cron/src/main/java/com/java3y/austin/cron/xxl/utils/XxlJobUtils.java +++ b/austin-cron/src/main/java/com/java3y/austin/cron/xxl/utils/XxlJobUtils.java @@ -3,6 +3,7 @@ package com.java3y.austin.cron.xxl.utils; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.constant.CommonConstant; import com.java3y.austin.common.enums.RespStatusEnum; import com.java3y.austin.common.vo.BasicResultVO; import com.java3y.austin.cron.xxl.constants.XxlJobConstant; @@ -44,8 +45,8 @@ public class XxlJobUtils { String scheduleConf = messageTemplate.getExpectPushTime(); // 如果没有指定cron表达式,说明立即执行(给到xxl-job延迟5秒的cron表达式) - if (messageTemplate.getExpectPushTime().equals(String.valueOf(AustinConstant.FALSE))) { - scheduleConf = DateUtil.format(DateUtil.offsetSecond(new Date(), XxlJobConstant.DELAY_TIME), AustinConstant.CRON_FORMAT); + if (messageTemplate.getExpectPushTime().equals(String.valueOf(CommonConstant.FALSE))) { + scheduleConf = DateUtil.format(DateUtil.offsetSecond(new Date(), XxlJobConstant.DELAY_TIME), CommonConstant.CRON_FORMAT); } XxlJobInfo xxlJobInfo = XxlJobInfo.builder() @@ -61,7 +62,7 @@ public class XxlJobUtils { .executorTimeout(XxlJobConstant.TIME_OUT) .executorFailRetryCount(XxlJobConstant.RETRY_COUNT) .glueType(GlueTypeEnum.BEAN.name()) - .triggerStatus(AustinConstant.FALSE) + .triggerStatus(CommonConstant.FALSE) .glueRemark(StrUtil.EMPTY) .glueSource(StrUtil.EMPTY) .alarmEmail(StrUtil.EMPTY) @@ -80,7 +81,7 @@ public class XxlJobUtils { private Integer queryJobGroupId() { BasicResultVO basicResultVO = cronTaskService.getGroupId(appName, jobHandlerName); if (basicResultVO.getData() == null) { - XxlJobGroup xxlJobGroup = XxlJobGroup.builder().appname(appName).title(jobHandlerName).addressType(AustinConstant.FALSE).build(); + XxlJobGroup xxlJobGroup = XxlJobGroup.builder().appname(appName).title(jobHandlerName).addressType(CommonConstant.FALSE).build(); if (RespStatusEnum.SUCCESS.getCode().equals(cronTaskService.createGroup(xxlJobGroup).getStatus())) { return (int) cronTaskService.getGroupId(appName, jobHandlerName).getData(); } diff --git a/austin-handler/pom.xml b/austin-handler/pom.xml index eb6ef31..94ca8bb 100644 --- a/austin-handler/pom.xml +++ b/austin-handler/pom.xml @@ -41,16 +41,7 @@ com.sun.mail javax.mail - - - com.github.binarywang - weixin-java-mp - - - - com.github.binarywang - weixin-java-miniapp - + diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/alipay/impl/AlipayMiniProgramAccountServiceImpl.java b/austin-handler/src/main/java/com/java3y/austin/handler/alipay/impl/AlipayMiniProgramAccountServiceImpl.java index 5d59622..4fa1d56 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/alipay/impl/AlipayMiniProgramAccountServiceImpl.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/alipay/impl/AlipayMiniProgramAccountServiceImpl.java @@ -38,10 +38,7 @@ public class AlipayMiniProgramAccountServiceImpl implements AlipayMiniProgramAcc */ @Override public void send(AlipayMiniProgramParam miniProgramParam) throws AlipayApiException { - AlipayMiniProgramAccount miniProgramAccount = accountUtils.getAccount(miniProgramParam.getSendAccount(), - SendAccountConstant.ALIPAY_MINI_PROGRAM_ACCOUNT_KEY, - SendAccountConstant.ALIPAY_MINI_PROGRAM_PREFIX, - AlipayMiniProgramAccount.class); + AlipayMiniProgramAccount miniProgramAccount = accountUtils.getAccountById(miniProgramParam.getSendAccount(), AlipayMiniProgramAccount.class); AlipayClient client = initService(miniProgramAccount); List request = assembleReq(miniProgramParam, miniProgramAccount); diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/DeduplicationRuleService.java b/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/DeduplicationRuleService.java index 1fbb90b..bf254b2 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/DeduplicationRuleService.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/DeduplicationRuleService.java @@ -1,6 +1,7 @@ package com.java3y.austin.handler.deduplication; import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.constant.CommonConstant; import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.enums.DeduplicationType; import com.java3y.austin.support.service.ConfigService; @@ -27,7 +28,7 @@ public class DeduplicationRuleService { public void duplication(TaskInfo taskInfo) { // 配置样例:{"deduplication_10":{"num":1,"time":300},"deduplication_20":{"num":5}} - String deduplicationConfig = config.getProperty(DEDUPLICATION_RULE_KEY, AustinConstant.APOLLO_DEFAULT_VALUE_JSON_OBJECT); + String deduplicationConfig = config.getProperty(DEDUPLICATION_RULE_KEY, CommonConstant.EMPTY_JSON_OBJECT); // 去重 List deduplicationList = DeduplicationType.getDeduplicationList(); diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/limit/SimpleLimitService.java b/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/limit/SimpleLimitService.java index c543a5f..569188b 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/limit/SimpleLimitService.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/limit/SimpleLimitService.java @@ -2,6 +2,7 @@ package com.java3y.austin.handler.deduplication.limit; import cn.hutool.core.collection.CollUtil; import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.constant.CommonConstant; import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.handler.deduplication.DeduplicationParam; import com.java3y.austin.handler.deduplication.service.AbstractDeduplicationService; @@ -66,7 +67,7 @@ public class SimpleLimitService extends AbstractLimitService { if (inRedisValue.get(key) != null) { keyValues.put(key, String.valueOf(Integer.valueOf(inRedisValue.get(key)) + 1)); } else { - keyValues.put(key, String.valueOf(AustinConstant.TRUE)); + keyValues.put(key, String.valueOf(CommonConstant.TRUE)); } } if (CollUtil.isNotEmpty(keyValues)) { diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/discard/DiscardMessageService.java b/austin-handler/src/main/java/com/java3y/austin/handler/discard/DiscardMessageService.java index 49850b2..e056ed6 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/discard/DiscardMessageService.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/discard/DiscardMessageService.java @@ -3,6 +3,7 @@ package com.java3y.austin.handler.discard; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.constant.CommonConstant; import com.java3y.austin.common.domain.AnchorInfo; import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.enums.AnchorState; @@ -33,8 +34,7 @@ public class DiscardMessageService { */ public boolean isDiscard(TaskInfo taskInfo) { // 配置示例: ["1","2"] - JSONArray array = JSON.parseArray(config.getProperty(DISCARD_MESSAGE_KEY, - AustinConstant.APOLLO_DEFAULT_VALUE_JSON_ARRAY)); + JSONArray array = JSON.parseArray(config.getProperty(DISCARD_MESSAGE_KEY, CommonConstant.EMPTY_VALUE_JSON_ARRAY)); if (array.contains(String.valueOf(taskInfo.getMessageTemplateId()))) { logUtils.print(AnchorInfo.builder().businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).state(AnchorState.DISCARD.getCode()).build()); 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..827b26d 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; + /** + * 渠道账号的脚本名标识 + */ + private String scriptName; + + /** * 发送文案 */ diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/flowcontrol/FlowControlFactory.java b/austin-handler/src/main/java/com/java3y/austin/handler/flowcontrol/FlowControlFactory.java index 92b22da..217b790 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/flowcontrol/FlowControlFactory.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/flowcontrol/FlowControlFactory.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.google.common.util.concurrent.RateLimiter; import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.constant.CommonConstant; import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.handler.enums.RateLimitStrategy; @@ -76,7 +77,7 @@ public class FlowControlFactory implements ApplicationContextAware { * @param channelCode */ private Double getRateLimitConfig(Integer channelCode) { - String flowControlConfig = config.getProperty(FLOW_CONTROL_KEY, AustinConstant.APOLLO_DEFAULT_VALUE_JSON_OBJECT); + String flowControlConfig = config.getProperty(FLOW_CONTROL_KEY, CommonConstant.EMPTY_JSON_OBJECT); JSONObject jsonObject = JSON.parseObject(flowControlConfig); if (jsonObject.getDouble(FLOW_CONTROL_PREFIX + channelCode) == null) { return null; diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/Handler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/Handler.java index d9c3165..88291b5 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/Handler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/Handler.java @@ -24,5 +24,4 @@ public interface Handler { */ void recall(MessageTemplate messageTemplate); - } diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingRobotHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingRobotHandler.java index e378215..997db58 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingRobotHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingRobotHandler.java @@ -6,6 +6,7 @@ import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; import com.google.common.base.Throwables; import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.constant.CommonConstant; import com.java3y.austin.common.constant.SendAccountConstant; import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.dto.account.DingDingRobotAccount; @@ -48,7 +49,7 @@ public class DingDingRobotHandler extends BaseHandler implements Handler { @Override public boolean handler(TaskInfo taskInfo) { try { - DingDingRobotAccount account = accountUtils.getAccount(taskInfo.getSendAccount(), SendAccountConstant.DING_DING_ROBOT_ACCOUNT_KEY, SendAccountConstant.DING_DING_ROBOT_PREFIX, DingDingRobotAccount.class); + DingDingRobotAccount account = accountUtils.getAccountById(taskInfo.getSendAccount(), DingDingRobotAccount.class); DingDingRobotParam dingDingRobotParam = assembleParam(taskInfo); String httpResult = HttpUtil.post(assembleParamUrl(account), JSON.toJSONString(dingDingRobotParam)); DingDingRobotResult dingDingRobotResult = JSON.parseObject(httpResult, DingDingRobotResult.class); @@ -126,10 +127,10 @@ public class DingDingRobotHandler extends BaseHandler implements Handler { String sign = ""; try { String stringToSign = currentTimeMillis + String.valueOf(StrUtil.C_LF) + secret; - Mac mac = Mac.getInstance(AustinConstant.HMAC_SHA256_ENCRYPTION_ALGO); - mac.init(new SecretKeySpec(secret.getBytes(AustinConstant.CHARSET_NAME), AustinConstant.HMAC_SHA256_ENCRYPTION_ALGO)); - byte[] signData = mac.doFinal(stringToSign.getBytes(AustinConstant.CHARSET_NAME)); - sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)), AustinConstant.CHARSET_NAME); + Mac mac = Mac.getInstance(CommonConstant.HMAC_SHA256_ENCRYPTION_ALGO); + mac.init(new SecretKeySpec(secret.getBytes(CommonConstant.CHARSET_NAME), CommonConstant.HMAC_SHA256_ENCRYPTION_ALGO)); + byte[] signData = mac.doFinal(stringToSign.getBytes(CommonConstant.CHARSET_NAME)); + sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)), CommonConstant.CHARSET_NAME); } catch (Exception e) { log.error("DingDingHandler#assembleSign fail!:{}", Throwables.getStackTraceAsString(e)); } diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingWorkNoticeHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingWorkNoticeHandler.java index 7b47c2a..19e5954 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingWorkNoticeHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingWorkNoticeHandler.java @@ -59,13 +59,14 @@ public class DingDingWorkNoticeHandler extends BaseHandler implements Handler { private static final String SEND_URL = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2"; private static final String RECALL_URL = "https://oapi.dingtalk.com/topapi/message/corpconversation/recall"; + private static final String PULL_URL = "https://oapi.dingtalk.com/topapi/message/corpconversation/getsendresult"; private static final String DING_DING_RECALL_KEY_PREFIX = "RECALL_"; private static final String RECALL_BIZ_TYPE = "DingDingWorkNoticeHandler#recall"; @Override public boolean handler(TaskInfo taskInfo) { try { - DingDingWorkNoticeAccount account = accountUtils.getAccount(taskInfo.getSendAccount(), SendAccountConstant.DING_DING_WORK_NOTICE_ACCOUNT_KEY, SendAccountConstant.DING_DING_WORK_NOTICE_PREFIX, DingDingWorkNoticeAccount.class); + DingDingWorkNoticeAccount account = accountUtils.getAccountById(taskInfo.getSendAccount(), DingDingWorkNoticeAccount.class); OapiMessageCorpconversationAsyncsendV2Request request = assembleParam(account, taskInfo); String accessToken = redisTemplate.opsForValue().get(SendAccountConstant.DING_DING_ACCESS_TOKEN_PREFIX + taskInfo.getSendAccount()); OapiMessageCorpconversationAsyncsendV2Response response = new DefaultDingTalkClient(SEND_URL).execute(request, accessToken); @@ -179,7 +180,7 @@ public class DingDingWorkNoticeHandler extends BaseHandler implements Handler { public void recall(MessageTemplate messageTemplate) { SupportThreadPoolConfig.getPendingSingleThreadPool().execute(() -> { try { - DingDingWorkNoticeAccount account = accountUtils.getAccount(messageTemplate.getSendAccount(), SendAccountConstant.DING_DING_WORK_NOTICE_ACCOUNT_KEY, SendAccountConstant.DING_DING_WORK_NOTICE_PREFIX, DingDingWorkNoticeAccount.class); + DingDingWorkNoticeAccount account = accountUtils.getAccountById(messageTemplate.getSendAccount(), DingDingWorkNoticeAccount.class); String accessToken = redisTemplate.opsForValue().get(SendAccountConstant.DING_DING_ACCESS_TOKEN_PREFIX + messageTemplate.getSendAccount()); while (redisTemplate.opsForList().size(DING_DING_RECALL_KEY_PREFIX + messageTemplate.getId()) > 0) { String taskId = redisTemplate.opsForList().leftPop(DING_DING_RECALL_KEY_PREFIX + messageTemplate.getId()); @@ -195,5 +196,23 @@ public class DingDingWorkNoticeHandler extends BaseHandler implements Handler { } }); } + + /** + * 拉取回执 + */ + public void pull(Long accountId) { + try { +// DingDingWorkNoticeAccount account = accountUtils.getAccountById(accountId, DingDingWorkNoticeAccount.class); +// String accessToken = redisTemplate.opsForValue().get(SendAccountConstant.DING_DING_ACCESS_TOKEN_PREFIX + accountId); +// DingTalkClient client = new DefaultDingTalkClient(PULL_URL); +// OapiMessageCorpconversationGetsendresultRequest req = new OapiMessageCorpconversationGetsendresultRequest(); +// req.setAgentId(Long.valueOf(account.getAgentId())); +// req.setTaskId(456L); +// OapiMessageCorpconversationGetsendresultResponse rsp = client.execute(req, accessToken); +// System.out.println(rsp.getBody()); + } catch (Exception e) { + log.error("DingDingWorkNoticeHandler#pull fail:{}", Throwables.getStackTraceAsString(e)); + } + } } diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EmailHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EmailHandler.java index db2c7cf..a9512b2 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EmailHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EmailHandler.java @@ -63,7 +63,7 @@ public class EmailHandler extends BaseHandler implements Handler { * @return */ private MailAccount getAccountConfig(Integer sendAccount) { - MailAccount account = accountUtils.getAccount(sendAccount, SendAccountConstant.EMAIL_ACCOUNT_KEY, SendAccountConstant.EMAIL_ACCOUNT_PREFIX, MailAccount.class); + MailAccount account = accountUtils.getAccountById(sendAccount, MailAccount.class); try { MailSSLSocketFactory sf = new MailSSLSocketFactory(); sf.setTrustAllHosts(true); diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EnterpriseWeChatHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EnterpriseWeChatHandler.java index 15d34e6..4b6a6ae 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EnterpriseWeChatHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EnterpriseWeChatHandler.java @@ -1,9 +1,11 @@ package com.java3y.austin.handler.handler.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.google.common.base.Throwables; import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.constant.CommonConstant; import com.java3y.austin.common.constant.SendAccountConstant; import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.dto.model.EnterpriseWeChatContentModel; @@ -38,11 +40,6 @@ import java.util.Map; @Slf4j public class EnterpriseWeChatHandler extends BaseHandler implements Handler { - /** - * 切割userId 的分隔符 - */ - private static final String DELIMITER = "|"; - @Autowired private AccountUtils accountUtils; @@ -53,7 +50,7 @@ public class EnterpriseWeChatHandler extends BaseHandler implements Handler { @Override public boolean handler(TaskInfo taskInfo) { try { - WxCpDefaultConfigImpl accountConfig = accountUtils.getAccount(taskInfo.getSendAccount(), SendAccountConstant.ENTERPRISE_WECHAT_ACCOUNT_KEY, SendAccountConstant.ENTERPRISE_WECHAT_PREFIX, WxCpDefaultConfigImpl.class); + WxCpDefaultConfigImpl accountConfig = accountUtils.getAccountById(taskInfo.getSendAccount(), WxCpDefaultConfigImpl.class); WxCpMessageServiceImpl messageService = new WxCpMessageServiceImpl(initService(accountConfig)); WxCpMessageSendResult result = messageService.send(buildWxCpMessage(taskInfo, accountConfig.getAgentId())); if (Integer.valueOf(WxMpErrorMsgEnum.CODE_0.getCode()).equals(result.getErrCode())) { @@ -93,7 +90,7 @@ public class EnterpriseWeChatHandler extends BaseHandler implements Handler { if (AustinConstant.SEND_ALL.equals(CollUtil.getFirst(taskInfo.getReceiver()))) { userId = CollUtil.getFirst(taskInfo.getReceiver()); } else { - userId = StringUtils.join(taskInfo.getReceiver(), DELIMITER); + userId = StringUtils.join(taskInfo.getReceiver(), CommonConstant.RADICAL); } EnterpriseWeChatContentModel contentModel = (EnterpriseWeChatContentModel) taskInfo.getContentModel(); diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EnterpriseWeChatRobotHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EnterpriseWeChatRobotHandler.java index f2ddae4..e66c3eb 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EnterpriseWeChatRobotHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EnterpriseWeChatRobotHandler.java @@ -51,7 +51,7 @@ public class EnterpriseWeChatRobotHandler extends BaseHandler implements Handler @Override public boolean handler(TaskInfo taskInfo) { try { - EnterpriseWeChatRobotAccount account = accountUtils.getAccount(taskInfo.getSendAccount(), SendAccountConstant.ENTERPRISE_WECHAT_ROBOT_ACCOUNT_KEY, SendAccountConstant.ENTERPRISE_WECHAT_ROBOT_PREFIX, EnterpriseWeChatRobotAccount.class); + EnterpriseWeChatRobotAccount account = accountUtils.getAccountById(taskInfo.getSendAccount(), EnterpriseWeChatRobotAccount.class); EnterpriseWeChatRobotParam enterpriseWeChatRobotParam = assembleParam(taskInfo); String result = HttpRequest.post(account.getWebhook()).header(Header.CONTENT_TYPE.getValue(), ContentType.JSON.getValue()) .body(JSON.toJSONString(enterpriseWeChatRobotParam)) diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/FeiShuRobotHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/FeiShuRobotHandler.java index dc80ae4..a18ff07 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/FeiShuRobotHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/FeiShuRobotHandler.java @@ -50,7 +50,7 @@ public class FeiShuRobotHandler extends BaseHandler implements Handler { @Override public boolean handler(TaskInfo taskInfo) { try { - FeiShuRobotAccount account = accountUtils.getAccount(taskInfo.getSendAccount(), SendAccountConstant.FEI_SHU_ROBOT_ACCOUNT_KEY, SendAccountConstant.FEI_SHU_ROBOT_PREFIX, FeiShuRobotAccount.class); + FeiShuRobotAccount account = accountUtils.getAccountById(taskInfo.getSendAccount(), FeiShuRobotAccount.class); FeiShuRobotParam feiShuRobotParam = assembleParam(taskInfo); String result = HttpRequest.post(account.getWebhook()) .header(Header.CONTENT_TYPE.getValue(), ContentType.JSON.getValue()) diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/PushHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/PushHandler.java index fed2a1d..8856452 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/PushHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/PushHandler.java @@ -58,7 +58,7 @@ public class PushHandler extends BaseHandler implements Handler { public boolean handler(TaskInfo taskInfo) { try { - GeTuiAccount account = accountUtils.getAccount(taskInfo.getSendAccount(), SendAccountConstant.GE_TUI_ACCOUNT_KEY, SendAccountConstant.GE_TUI_ACCOUNT_PREFIX, GeTuiAccount.class); + GeTuiAccount account = accountUtils.getAccountById(taskInfo.getSendAccount(), GeTuiAccount.class); String token = redisTemplate.opsForValue().get(SendAccountConstant.GE_TUI_ACCESS_TOKEN_PREFIX + taskInfo.getSendAccount()); PushParam pushParam = PushParam.builder().token(token).appId(account.getAppId()).taskInfo(taskInfo).build(); @@ -83,6 +83,7 @@ public class PushHandler extends BaseHandler implements Handler { /** * 单推 + * * @param pushParam * @return http result */ @@ -101,7 +102,7 @@ public class PushHandler extends BaseHandler implements Handler { /** * 批量推送 * - * @param taskId 个推 返回的任务Id + * @param taskId 个推 返回的任务Id * @param pushParam * @return */ @@ -122,6 +123,7 @@ public class PushHandler extends BaseHandler implements Handler { /** * 群推前需要构建taskId + * * @param pushParam * @return http result */ @@ -161,6 +163,7 @@ public class PushHandler extends BaseHandler implements Handler { } return param; } + @Override public void recall(MessageTemplate messageTemplate) { 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 e3aebdc..c4e1e7f 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 @@ -5,7 +5,7 @@ import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.google.common.base.Throwables; -import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.constant.CommonConstant; import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.dto.model.SmsContentModel; import com.java3y.austin.common.enums.ChannelType; @@ -48,6 +48,9 @@ public class SmsHandler extends BaseHandler implements Handler { @Autowired private Map smsScripts; + private static final String FLOW_KEY = "msgTypeSmsConfig"; + private static final String FLOW_KEY_PREFIX = "message_type_"; + @Override public boolean handler(TaskInfo taskInfo) { SmsParam smsParam = SmsParam.builder() @@ -62,6 +65,7 @@ public class SmsHandler extends BaseHandler implements Handler { */ MessageTypeSmsConfig[] messageTypeSmsConfigs = loadBalance(getMessageTypeSmsConfig(taskInfo.getMsgType())); for (MessageTypeSmsConfig messageTypeSmsConfig : messageTypeSmsConfigs) { + smsParam.setScriptName(messageTypeSmsConfig.getScriptName()); List recordList = smsScripts.get(messageTypeSmsConfig.getScriptName()).send(smsParam); if (CollUtil.isNotEmpty(recordList)) { smsRecordDao.saveAll(recordList); @@ -69,8 +73,7 @@ public class SmsHandler extends BaseHandler implements Handler { } } } catch (Exception e) { - log.error("SmsHandler#handler fail:{},params:{}", - Throwables.getStackTraceAsString(e), JSON.toJSONString(smsParam)); + log.error("SmsHandler#handler fail:{},params:{}", Throwables.getStackTraceAsString(e), JSON.toJSONString(smsParam)); } return false; } @@ -125,14 +128,10 @@ public class SmsHandler extends BaseHandler implements Handler { * @return */ private List getMessageTypeSmsConfig(Integer msgType) { - - String apolloKey = "msgTypeSmsConfig"; - String messagePrefix = "message_type_"; - - String property = config.getProperty(apolloKey, AustinConstant.APOLLO_DEFAULT_VALUE_JSON_ARRAY); + String property = config.getProperty(FLOW_KEY, CommonConstant.EMPTY_VALUE_JSON_ARRAY); JSONArray jsonArray = JSON.parseArray(property); for (int i = 0; i < jsonArray.size(); i++) { - JSONArray array = jsonArray.getJSONObject(i).getJSONArray(messagePrefix + msgType); + JSONArray array = jsonArray.getJSONObject(i).getJSONArray(FLOW_KEY_PREFIX + msgType); if (CollUtil.isNotEmpty(array)) { List result = JSON.parseArray(JSON.toJSONString(array), MessageTypeSmsConfig.class); return result; @@ -150,7 +149,7 @@ public class SmsHandler extends BaseHandler implements Handler { private String getSmsContent(TaskInfo taskInfo) { SmsContentModel smsContentModel = (SmsContentModel) taskInfo.getContentModel(); if (StrUtil.isNotBlank(smsContentModel.getUrl())) { - return smsContentModel.getContent() + " " + smsContentModel.getUrl(); + return smsContentModel.getContent() + StrUtil.SPACE + smsContentModel.getUrl(); } else { return smsContentModel.getContent(); } diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/receipt/DingDingWorkReceipt.java b/austin-handler/src/main/java/com/java3y/austin/handler/receipt/DingDingWorkReceipt.java deleted file mode 100644 index 8420a07..0000000 --- a/austin-handler/src/main/java/com/java3y/austin/handler/receipt/DingDingWorkReceipt.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.java3y.austin.handler.receipt; - - -import cn.hutool.core.util.StrUtil; -import com.dingtalk.api.DefaultDingTalkClient; -import com.dingtalk.api.DingTalkClient; -import com.dingtalk.api.request.OapiMessageCorpconversationGetsendresultRequest; -import com.dingtalk.api.response.OapiMessageCorpconversationGetsendresultResponse; -import com.java3y.austin.common.constant.SendAccountConstant; -import com.java3y.austin.common.dto.account.DingDingWorkNoticeAccount; -import com.java3y.austin.support.utils.AccountUtils; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.stereotype.Component; - -/** - * 拉取钉钉工作消息回执信息 - * - * @author 3y - */ -@Component -@Slf4j -public class DingDingWorkReceipt { - - private static final String URL = "https://oapi.dingtalk.com/topapi/message/corpconversation/getsendresult"; - @Autowired - private StringRedisTemplate redisTemplate; - - @Autowired - private AccountUtils accountUtils; - public void pull() { -// try { -// 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; -// } -// String accessToken = redisTemplate.opsForValue().get(SendAccountConstant.DING_DING_ACCESS_TOKEN_PREFIX + index); -// DingTalkClient client = new DefaultDingTalkClient(URL); -// OapiMessageCorpconversationGetsendresultRequest req = new OapiMessageCorpconversationGetsendresultRequest(); -// req.setAgentId(Long.valueOf(account.getAgentId())); -// req.setTaskId(456L); -// OapiMessageCorpconversationGetsendresultResponse rsp = client.execute(req, accessToken); -// System.out.println(rsp.getBody()); -// } -// } catch (Exception e) { -// log.error("DingDingWorkReceipt#pull"); -// } - } -} 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..a5cd6c9 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,18 @@ 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.handler.receipt.stater.ReceiptMessageStater; 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 +21,20 @@ import java.util.List; public class MessageReceipt { @Autowired - private TencentSmsReceipt tencentSmsReceipt; - - @Autowired - private YunPianSmsReceipt yunPianSmsReceipt; + private List receiptMessageStaterList; @PostConstruct private void init() { SupportThreadPoolConfig.getPendingSingleThreadPool().execute(() -> { while (true) { - - // TODO 回执这里自行打开(免得报错) -// tencentSmsReceipt.pull(); -// yunPianSmsReceipt.pull(); try { - Thread.sleep(200); - } catch (InterruptedException e) { + for (ReceiptMessageStater receiptMessageStater : receiptMessageStaterList) { + // 拉取回执需要打开下面一行注释 + //receiptMessageStater.start(); + } + Thread.sleep(2000); + } catch (Exception e) { + log.error("MessageReceiptApplication#fail:{}", Throwables.getStackTraceAsString(e)); } } }); 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/TencentSmsReceipt.java deleted file mode 100644 index 704422e..0000000 --- a/austin-handler/src/main/java/com/java3y/austin/handler/receipt/TencentSmsReceipt.java +++ /dev/null @@ -1,108 +0,0 @@ -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.dao.SmsRecordDao; -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 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 { - - - @Autowired - private AccountUtils accountUtils; - - @Autowired - private SmsRecordDao smsRecordDao; - - - /** - * 拉取消息并入库 - */ - public void pull() { - - // 获取腾讯云账号信息 - TencentSmsAccount account = accountUtils.getAccount(10, SendAccountConstant.SMS_ACCOUNT_KEY, SendAccountConstant.SMS_PREFIX, TencentSmsAccount.class); - try { - SmsClient client = getSmsClient(account); - - // 每次拉取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))) - .messageTemplateId(0L) - .phone(Long.valueOf(pullSmsSendStatus.getSubscriberNumber())) - .supplierId(account.getSupplierId()) - .supplierName(account.getSupplierName()) - .msgContent("") - .seriesId(pullSmsSendStatus.getSerialNo()) - .chargingNum(0) - .status("SUCCESS".equals(pullSmsSendStatus.getReportStatus()) ? SmsStatus.RECEIVE_SUCCESS.getCode() : SmsStatus.RECEIVE_FAIL.getCode()) - .reportContent(pullSmsSendStatus.getDescription()) - .updated(Math.toIntExact(pullSmsSendStatus.getUserReceiveTime())) - .created(Math.toIntExact(DateUtil.currentSeconds())) - .build(); - smsRecordList.add(smsRecord); - } - } - if (!CollUtil.isEmpty(smsRecordList)) { - smsRecordDao.saveAll(smsRecordList); - } - } catch (Exception e) { - log.error("TencentSmsReceipt#init fail!{}", Throwables.getStackTraceAsString(e)); - } - } - - /** - * 构造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); - } - - -} 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/receipt/stater/ReceiptMessageStater.java b/austin-handler/src/main/java/com/java3y/austin/handler/receipt/stater/ReceiptMessageStater.java new file mode 100644 index 0000000..5895227 --- /dev/null +++ b/austin-handler/src/main/java/com/java3y/austin/handler/receipt/stater/ReceiptMessageStater.java @@ -0,0 +1,14 @@ +package com.java3y.austin.handler.receipt.stater; + +/** + * 拉取回执信息 启动器 + * + * @author 3y + */ +public interface ReceiptMessageStater { + + /** + * 启动拉取回执 + */ + void start(); +} diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/receipt/stater/impl/DingDingWorkReceiptStaterImpl.java b/austin-handler/src/main/java/com/java3y/austin/handler/receipt/stater/impl/DingDingWorkReceiptStaterImpl.java new file mode 100644 index 0000000..aca3495 --- /dev/null +++ b/austin-handler/src/main/java/com/java3y/austin/handler/receipt/stater/impl/DingDingWorkReceiptStaterImpl.java @@ -0,0 +1,33 @@ +package com.java3y.austin.handler.receipt.stater.impl; + +import com.java3y.austin.common.constant.CommonConstant; +import com.java3y.austin.common.enums.ChannelType; +import com.java3y.austin.handler.handler.impl.DingDingWorkNoticeHandler; +import com.java3y.austin.handler.receipt.stater.ReceiptMessageStater; +import com.java3y.austin.support.dao.ChannelAccountDao; +import com.java3y.austin.support.domain.ChannelAccount; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +/** + * 拉取 钉钉工作消息的回执 内容 【未完成】 + * + * @author 3y + */ +public class DingDingWorkReceiptStaterImpl implements ReceiptMessageStater { + + @Autowired + private DingDingWorkNoticeHandler workNoticeHandler; + + @Autowired + private ChannelAccountDao channelAccountDao; + + @Override + public void start() { + List accountList = channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(CommonConstant.FALSE, ChannelType.DING_DING_WORK_NOTICE.getCode()); + for (ChannelAccount channelAccount : accountList) { + workNoticeHandler.pull(channelAccount.getId()); + } + } +} diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/receipt/stater/impl/SmsPullReceiptStarterImpl.java b/austin-handler/src/main/java/com/java3y/austin/handler/receipt/stater/impl/SmsPullReceiptStarterImpl.java new file mode 100644 index 0000000..39e8728 --- /dev/null +++ b/austin-handler/src/main/java/com/java3y/austin/handler/receipt/stater/impl/SmsPullReceiptStarterImpl.java @@ -0,0 +1,60 @@ +package com.java3y.austin.handler.receipt.stater.impl; + +import cn.hutool.core.collection.CollUtil; +import com.alibaba.fastjson.JSON; +import com.google.common.base.Throwables; +import com.java3y.austin.common.constant.CommonConstant; +import com.java3y.austin.common.dto.account.sms.SmsAccount; +import com.java3y.austin.common.enums.ChannelType; +import com.java3y.austin.handler.receipt.stater.ReceiptMessageStater; +import com.java3y.austin.handler.script.SmsScript; +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 lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Map; + + +/** + * 拉取短信回执信息 + * + * @author 3y + */ +@Component +@Slf4j +public class SmsPullReceiptStarterImpl implements ReceiptMessageStater { + + @Autowired + private ChannelAccountDao channelAccountDao; + + @Autowired + private Map scriptMap; + + @Autowired + private SmsRecordDao smsRecordDao; + + /** + * 拉取消息并入库 + */ + public void start() { + try { + List channelAccountList = channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(CommonConstant.FALSE, ChannelType.SMS.getCode()); + for (ChannelAccount channelAccount : channelAccountList) { + SmsAccount smsAccount = JSON.parseObject(channelAccount.getAccountConfig(), SmsAccount.class); + List smsRecordList = scriptMap.get(smsAccount.getScriptName()).pull(smsAccount.getScriptName()); + if (CollUtil.isNotEmpty(smsRecordList)) { + smsRecordDao.saveAll(smsRecordList); + } + } + } catch (Exception e) { + log.error("SmsPullReceiptStarter#start fail:{}", Throwables.getStackTraceAsString(e)); + + } + + } +} diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/script/SmsScript.java b/austin-handler/src/main/java/com/java3y/austin/handler/script/SmsScript.java index 35d6e98..4facaba 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/script/SmsScript.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/script/SmsScript.java @@ -9,16 +9,25 @@ import java.util.List; /** * 短信脚本 接口 + * * @author 3y */ public interface SmsScript { /** * 发送短信 + * * @param smsParam - * @return 渠道商接口返回值 - + * @return 渠道商发送接口返回值 */ List send(SmsParam smsParam); + + /** + * 拉取回执 + * @param scriptName 标识账号的脚本名 + * @return 渠道商回执接口返回值 + */ + List pull(String scriptName); + } 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 2fcf80f..4681020 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 @@ -6,8 +6,7 @@ import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.IdUtil; 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.dto.account.sms.TencentSmsAccount; import com.java3y.austin.common.enums.SmsStatus; import com.java3y.austin.handler.domain.sms.SmsParam; import com.java3y.austin.handler.script.SmsScript; @@ -17,9 +16,7 @@ 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.SendSmsRequest; -import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse; -import com.tencentcloudapi.sms.v20210111.models.SendStatus; +import com.tencentcloudapi.sms.v20210111.models.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -48,19 +45,40 @@ public class TencentSmsScript 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.getSmsAccountByScriptName(smsParam.getScriptName(), TencentSmsAccount.class); SmsClient client = init(tencentSmsAccount); - SendSmsRequest request = assembleReq(smsParam, tencentSmsAccount); + SendSmsRequest request = assembleSendReq(smsParam, tencentSmsAccount); SendSmsResponse response = client.SendSms(request); - return assembleSmsRecord(smsParam, response, tencentSmsAccount); + return assembleSendSmsRecord(smsParam, response, tencentSmsAccount); } catch (Exception e) { log.error("TencentSmsScript#send fail:{},params:{}", Throwables.getStackTraceAsString(e), JSON.toJSONString(smsParam)); return null; } } + @Override + public List pull(String scriptName) { + try { + TencentSmsAccount account = accountUtils.getSmsAccountByScriptName(scriptName, TencentSmsAccount.class); + SmsClient client = init(account); + PullSmsSendStatusRequest req = assemblePullReq(account); + PullSmsSendStatusResponse resp = client.PullSmsSendStatus(req); + return assemblePullSmsRecord(account, resp); + } catch (Exception e) { + log.error("TencentSmsReceipt#pull fail!{}", Throwables.getStackTraceAsString(e)); + return null; + } + } - private List assembleSmsRecord(SmsParam smsParam, SendSmsResponse response, TencentSmsAccount tencentSmsAccount) { + /** + * 组装 发送消息的 返回值 + * + * @param smsParam + * @param response + * @param tencentSmsAccount + * @return + */ + private List assembleSendSmsRecord(SmsParam smsParam, SendSmsResponse response, TencentSmsAccount tencentSmsAccount) { if (response == null || ArrayUtil.isEmpty(response.getSendStatusSet())) { return null; } @@ -95,7 +113,7 @@ public class TencentSmsScript implements SmsScript { /** * 组装发送短信参数 */ - private SendSmsRequest assembleReq(SmsParam smsParam, TencentSmsAccount account) { + private SendSmsRequest assembleSendReq(SmsParam smsParam, TencentSmsAccount account) { SendSmsRequest req = new SendSmsRequest(); String[] phoneNumberSet1 = smsParam.getPhones().toArray(new String[smsParam.getPhones().size() - 1]); req.setPhoneNumberSet(phoneNumberSet1); @@ -123,5 +141,50 @@ public class TencentSmsScript implements SmsScript { return client; } + /** + * 组装 拉取回执信息 + * + * @param account + * @param resp + * @return + */ + private List assemblePullSmsRecord(TencentSmsAccount account, PullSmsSendStatusResponse resp) { + List smsRecordList = new ArrayList<>(); + if (resp != null && resp.getPullSmsSendStatusSet() != null && resp.getPullSmsSendStatusSet().length > 0) { + for (PullSmsSendStatus pullSmsSendStatus : resp.getPullSmsSendStatusSet()) { + SmsRecord smsRecord = SmsRecord.builder() + .sendDate(Integer.valueOf(DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN))) + .messageTemplateId(0L) + .phone(Long.valueOf(pullSmsSendStatus.getSubscriberNumber())) + .supplierId(account.getSupplierId()) + .supplierName(account.getSupplierName()) + .msgContent("") + .seriesId(pullSmsSendStatus.getSerialNo()) + .chargingNum(0) + .status("SUCCESS".equals(pullSmsSendStatus.getReportStatus()) ? SmsStatus.RECEIVE_SUCCESS.getCode() : SmsStatus.RECEIVE_FAIL.getCode()) + .reportContent(pullSmsSendStatus.getDescription()) + .updated(Math.toIntExact(pullSmsSendStatus.getUserReceiveTime())) + .created(Math.toIntExact(DateUtil.currentSeconds())) + .build(); + smsRecordList.add(smsRecord); + } + } + return smsRecordList; + } + + /** + * 组装 拉取回执 入参 + * + * @param account + * @return + */ + private PullSmsSendStatusRequest assemblePullReq(TencentSmsAccount account) { + PullSmsSendStatusRequest req = new PullSmsSendStatusRequest(); + req.setLimit(10L); + req.setSmsSdkAppId(account.getSmsSdkAppId()); + return req; + } + + } 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 fcbe564..991096f 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 @@ -8,8 +8,8 @@ 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.SendAccountConstant; -import com.java3y.austin.common.dto.account.YunPianSmsAccount; +import com.java3y.austin.common.constant.CommonConstant; +import com.java3y.austin.common.dto.account.sms.YunPianSmsAccount; import com.java3y.austin.common.enums.SmsStatus; import com.java3y.austin.handler.domain.sms.SmsParam; import com.java3y.austin.handler.domain.sms.YunPianSendResult; @@ -38,7 +38,7 @@ public class YunPianSmsScript 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.getSmsAccountByScriptName(smsParam.getScriptName(), YunPianSmsAccount.class); Map params = assembleParam(smsParam, account); String result = HttpRequest.post(account.getUrl()) @@ -56,6 +56,13 @@ public class YunPianSmsScript implements SmsScript { } + @Override + public List pull(String scriptName) { + YunPianSmsAccount account = accountUtils.getSmsAccountByScriptName(scriptName, YunPianSmsAccount.class); + // ..... + return null; + } + /** * 组装参数 * @@ -90,7 +97,7 @@ public class YunPianSmsScript implements SmsScript { .msgContent(smsParam.getContent()) .seriesId(datum.getSid()) .chargingNum(Math.toIntExact(datum.getCount())) - .status("0".equals(datum.getCode()) ? SmsStatus.SEND_SUCCESS.getCode() : SmsStatus.SEND_FAIL.getCode()) + .status(CommonConstant.ZERO.equals(datum.getCode()) ? SmsStatus.SEND_SUCCESS.getCode() : SmsStatus.SEND_FAIL.getCode()) .reportContent(datum.getMsg()) .created(Math.toIntExact(DateUtil.currentSeconds())) .updated(Math.toIntExact(DateUtil.currentSeconds())) diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/wechat/impl/MiniProgramAccountServiceImpl.java b/austin-handler/src/main/java/com/java3y/austin/handler/wechat/impl/MiniProgramAccountServiceImpl.java index 6c400bf..a7f83d5 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/wechat/impl/MiniProgramAccountServiceImpl.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/wechat/impl/MiniProgramAccountServiceImpl.java @@ -33,9 +33,7 @@ public class MiniProgramAccountServiceImpl implements MiniProgramAccountService @Override public void send(WeChatMiniProgramParam miniProgramParam) throws Exception { - WeChatMiniProgramAccount miniProgramAccount = accountUtils.getAccount(miniProgramParam.getSendAccount(), - SendAccountConstant.WECHAT_MINI_PROGRAM_ACCOUNT_KEY, - SendAccountConstant.WECHAT_MINI_PROGRAM_PREFIX, + WeChatMiniProgramAccount miniProgramAccount = accountUtils.getAccountById(miniProgramParam.getSendAccount(), WeChatMiniProgramAccount.class); WxMaSubscribeService wxMaSubscribeService = initService(miniProgramAccount); diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/wechat/impl/OfficialAccountServiceImpl.java b/austin-handler/src/main/java/com/java3y/austin/handler/wechat/impl/OfficialAccountServiceImpl.java index 7766713..6ce3703 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/wechat/impl/OfficialAccountServiceImpl.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/wechat/impl/OfficialAccountServiceImpl.java @@ -1,10 +1,10 @@ package com.java3y.austin.handler.wechat.impl; -import com.java3y.austin.common.constant.SendAccountConstant; import com.java3y.austin.common.dto.account.WeChatOfficialAccount; import com.java3y.austin.handler.domain.wechat.WeChatOfficialParam; import com.java3y.austin.handler.wechat.OfficialAccountService; import com.java3y.austin.support.utils.AccountUtils; +import com.java3y.austin.support.utils.WxServiceUtils; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; @@ -31,8 +31,8 @@ public class OfficialAccountServiceImpl implements OfficialAccountService { @Override public List send(WeChatOfficialParam officialParam) throws Exception { - WeChatOfficialAccount officialAccount = accountUtils.getAccount(officialParam.getSendAccount(), SendAccountConstant.WECHAT_OFFICIAL_ACCOUNT_KEY, SendAccountConstant.WECHAT_OFFICIAL__PREFIX, WeChatOfficialAccount.class); - WxMpService wxMpService = initService(officialAccount); + WxMpService wxMpService = WxServiceUtils.wxMpServiceMap.get(officialParam.getSendAccount()); + WeChatOfficialAccount officialAccount = WxServiceUtils.accountHashMap.get(officialParam.getSendAccount()); List messages = assembleReq(officialParam, officialAccount); List messageIds = new ArrayList<>(messages.size()); for (WxMpTemplateMessage wxMpTemplateMessage : messages) { diff --git a/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/AssembleAction.java b/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/AssembleAction.java index 9e0692c..c70d95c 100644 --- a/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/AssembleAction.java +++ b/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/AssembleAction.java @@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.serializer.SerializerFeature; import com.google.common.base.Throwables; import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.constant.CommonConstant; import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.dto.model.ContentModel; import com.java3y.austin.common.enums.ChannelType; @@ -38,6 +39,8 @@ import java.util.*; @Service public class AssembleAction implements BusinessProcess { + private static final String LINK_NAME = "url"; + @Autowired private MessageTemplateDao messageTemplateDao; @@ -48,7 +51,7 @@ public class AssembleAction implements BusinessProcess { try { Optional messageTemplate = messageTemplateDao.findById(messageTemplateId); - if (!messageTemplate.isPresent() || messageTemplate.get().getIsDeleted().equals(AustinConstant.TRUE)) { + if (!messageTemplate.isPresent() || messageTemplate.get().getIsDeleted().equals(CommonConstant.TRUE)) { context.setNeedBreak(true).setResponse(BasicResultVO.fail(RespStatusEnum.TEMPLATE_NOT_FOUND)); return; } @@ -126,10 +129,10 @@ public class AssembleAction implements BusinessProcess { } // 如果 url 字段存在,则在url拼接对应的埋点参数 - String url = (String) ReflectUtil.getFieldValue(contentModel, "url"); + String url = (String) ReflectUtil.getFieldValue(contentModel, LINK_NAME); if (StrUtil.isNotBlank(url)) { String resultUrl = TaskInfoUtils.generateUrl(url, messageTemplate.getId(), messageTemplate.getTemplateType()); - ReflectUtil.setFieldValue(contentModel, "url", resultUrl); + ReflectUtil.setFieldValue(contentModel, LINK_NAME, resultUrl); } return contentModel; } diff --git a/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/PreParamCheckAction.java b/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/PreParamCheckAction.java index 365e81d..6255859 100644 --- a/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/PreParamCheckAction.java +++ b/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/action/PreParamCheckAction.java @@ -2,6 +2,7 @@ package com.java3y.austin.service.api.impl.action; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; +import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.common.enums.RespStatusEnum; import com.java3y.austin.common.vo.BasicResultVO; import com.java3y.austin.service.api.domain.MessageParam; @@ -24,11 +25,6 @@ import java.util.stream.Collectors; @Service public class PreParamCheckAction implements BusinessProcess { - /** - * 最大的人数 - */ - private static final Integer BATCH_RECEIVER_SIZE = 100; - @Override public void process(ProcessContext context) { SendTaskModel sendTaskModel = context.getProcessModel(); @@ -52,7 +48,7 @@ public class PreParamCheckAction implements BusinessProcess { } // 3.过滤receiver大于100的请求 - if (resultMessageParamList.stream().anyMatch(messageParam -> messageParam.getReceiver().split(StrUtil.COMMA).length > BATCH_RECEIVER_SIZE)) { + if (resultMessageParamList.stream().anyMatch(messageParam -> messageParam.getReceiver().split(StrUtil.COMMA).length > AustinConstant.BATCH_RECEIVER_SIZE)) { context.setNeedBreak(true).setResponse(BasicResultVO.fail(RespStatusEnum.TOO_MANY_RECEIVER)); return; } diff --git a/austin-support/pom.xml b/austin-support/pom.xml index f6dfb2b..0a20790 100644 --- a/austin-support/pom.xml +++ b/austin-support/pom.xml @@ -94,21 +94,31 @@ dynamic-tp-spring-boot-starter-apollo - - com.aliyun - alibaba-dingtalk-service-sdk - org.springframework.amqp spring-rabbit - com.alibaba.boot nacos-config-spring-boot-starter + + com.aliyun + alibaba-dingtalk-service-sdk + + + + com.github.binarywang + weixin-java-mp + + + + com.github.binarywang + weixin-java-miniapp + + \ No newline at end of file diff --git a/austin-support/src/main/java/com/java3y/austin/support/dao/ChannelAccountDao.java b/austin-support/src/main/java/com/java3y/austin/support/dao/ChannelAccountDao.java index d149aea..42b3bb6 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/dao/ChannelAccountDao.java +++ b/austin-support/src/main/java/com/java3y/austin/support/dao/ChannelAccountDao.java @@ -35,4 +35,5 @@ public interface ChannelAccountDao extends JpaRepository { * @return */ Long countByIsDeletedEquals(Integer deleted); + } diff --git a/austin-support/src/main/java/com/java3y/austin/support/dao/MessageTemplateDao.java b/austin-support/src/main/java/com/java3y/austin/support/dao/MessageTemplateDao.java index a856f68..cf1bb62 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/dao/MessageTemplateDao.java +++ b/austin-support/src/main/java/com/java3y/austin/support/dao/MessageTemplateDao.java @@ -20,7 +20,7 @@ public interface MessageTemplateDao extends JpaRepository * @param pageable 分页对象 * @return */ - List findAllByIsDeletedEquals(Integer deleted, Pageable pageable); + List findAllByIsDeletedEqualsOrderByUpdatedDesc(Integer deleted, Pageable pageable); /** 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 cf63604..3085942 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 @@ -1,25 +1,31 @@ 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.java3y.austin.common.constant.AustinConstant; -import com.java3y.austin.support.service.ConfigService; +import com.google.common.base.Throwables; +import com.java3y.austin.common.constant.CommonConstant; +import com.java3y.austin.common.dto.account.sms.SmsAccount; +import com.java3y.austin.common.enums.ChannelType; +import com.java3y.austin.support.dao.ChannelAccountDao; +import com.java3y.austin.support.domain.ChannelAccount; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.List; +import java.util.Optional; + /** * 获取账号信息工具类 * * @author 3y */ @Component +@Slf4j public class AccountUtils { @Autowired - private ConfigService config; + private ChannelAccountDao channelAccountDao; + /** * local.properties配置格式 @@ -32,16 +38,48 @@ public class AccountUtils { * (key:miniProgramAccount) 微信小程序订阅消息参数示例:[{"mini_program_10":{"appId":"wxecb4693d2eef1ea7","appSecret":"6240870f4d91701640d769ba20120821","templateId":"JHUk6eE9T5TasdfCrQsk-Q","grantType":"client_credential","miniProgramState":"trial","page":"index?foo=bar"}}] * (key:alipayMiniProgramAccount) 支付宝小程序订阅消息参数实例:[{"alipay_mini_program_10":{"privateKey":"MIIEvQIBADANB......","alipayPublicKey":"MIIBIjANBg...","appId":"2014********7148","userTemplateId":"MDI4YzIxMDE2M2I5YTQzYjUxNWE4MjA4NmU1MTIyYmM=","page":"page/component/index"}}] */ - public T getAccount(Integer sendAccount, String apolloKey, String prefix, Class clazz) { - 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); - if (object != null) { - return object; + public T getAccountById(Integer sendAccountId, 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.error("AccountUtils#getAccount fail!", Throwables.getStackTraceAsString(e)); + } + + log.error("AccountUtils#getAccount not found!:{}", sendAccountId); + return null; + } + + /** + * 通过脚本名 匹配到对应的短信账号 + * + * @param scriptName 脚本名 + * @param clazz + * @param + * @return + */ + public T getSmsAccountByScriptName(String scriptName, Class clazz) { + try { + List channelAccountList = channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(CommonConstant.FALSE, ChannelType.SMS.getCode()); + for (ChannelAccount channelAccount : channelAccountList) { + try { + SmsAccount smsAccount = JSON.parseObject(channelAccount.getAccountConfig(), SmsAccount.class); + if (smsAccount.getScriptName().equals(scriptName)) { + return JSON.parseObject(channelAccount.getAccountConfig(), clazz); + } + } catch (Exception e) { + log.error("AccountUtils#getSmsAccount parse fail! e:{},account:{}", Throwables.getStackTraceAsString(e), JSON.toJSONString(channelAccount)); + } } + } catch (Exception e) { + log.error("AccountUtils#getSmsAccount fail! e:{}", Throwables.getStackTraceAsString(e)); } + log.error("AccountUtils#getSmsAccount not found!:{}", scriptName); return null; } + } diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/RedisUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/RedisUtils.java index 38d23b4..f8977de 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/utils/RedisUtils.java +++ b/austin-support/src/main/java/com/java3y/austin/support/utils/RedisUtils.java @@ -3,6 +3,7 @@ package com.java3y.austin.support.utils; import cn.hutool.core.collection.CollUtil; import com.google.common.base.Throwables; import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.constant.CommonConstant; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisCallback; @@ -170,7 +171,7 @@ public class RedisUtils { try { Long execute = redisTemplate.execute(redisScript, keys, args); - return AustinConstant.TRUE.equals(execute.intValue()); + return CommonConstant.TRUE.equals(execute.intValue()); } catch (Exception e) { log.error("redis execLimitLua fail! e:{}", Throwables.getStackTraceAsString(e)); diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/TaskInfoUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/TaskInfoUtils.java index d3d9272..87936f9 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/utils/TaskInfoUtils.java +++ b/austin-support/src/main/java/com/java3y/austin/support/utils/TaskInfoUtils.java @@ -2,6 +2,8 @@ package com.java3y.austin.support.utils; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; +import com.java3y.austin.common.constant.CommonConstant; import java.util.Date; @@ -13,7 +15,7 @@ import java.util.Date; public class TaskInfoUtils { private static final int TYPE_FLAG = 1000000; - private static final char PARAM = '?'; + private static final String CODE = "track_code_bid"; /** * 生成BusinessId @@ -45,10 +47,10 @@ public class TaskInfoUtils { public static String generateUrl(String url, Long templateId, Integer templateType) { url = url.trim(); Long businessId = generateBusinessId(templateId, templateType); - if (url.indexOf(PARAM) == -1) { - return url + "?track_code_bid=" + businessId; + if (url.indexOf(CommonConstant.QM) == -1) { + return url + CommonConstant.QM_STRING + CODE + CommonConstant.EQUAL_STRING + businessId; } else { - return url + "&track_code_bid=" + businessId; + return url + CommonConstant.AND_STRING + CODE + CommonConstant.EQUAL_STRING + businessId; } } diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/WxServiceUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/WxServiceUtils.java new file mode 100644 index 0000000..cc39aba --- /dev/null +++ b/austin-support/src/main/java/com/java3y/austin/support/utils/WxServiceUtils.java @@ -0,0 +1,60 @@ +package com.java3y.austin.support.utils; + + +import com.alibaba.fastjson.JSON; +import com.java3y.austin.common.constant.CommonConstant; +import com.java3y.austin.common.dto.account.WeChatOfficialAccount; +import com.java3y.austin.common.enums.ChannelType; +import com.java3y.austin.support.dao.ChannelAccountDao; +import com.java3y.austin.support.domain.ChannelAccount; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; +import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 微信服务号/微信小程序 工具类 + * + * @author 3y + */ +@Component +@Slf4j +public class WxServiceUtils { + + public static Map wxMpServiceMap = new HashMap<>(); + public static Map accountHashMap = new HashMap<>(); + + @Autowired + private ChannelAccountDao channelAccountDao; + + @PostConstruct + public void init() { + List officialAccountList = channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(CommonConstant.FALSE, ChannelType.OFFICIAL_ACCOUNT.getCode()); + for (ChannelAccount channelAccount : officialAccountList) { + WeChatOfficialAccount weChatOfficialAccount = JSON.parseObject(channelAccount.getAccountConfig(), WeChatOfficialAccount.class); + wxMpServiceMap.put(channelAccount.getId(), initService(weChatOfficialAccount)); + accountHashMap.put(channelAccount.getId(), weChatOfficialAccount); + } + } + + /** + * 初始化微信服务号 + * + * @return + */ + public WxMpService initService(WeChatOfficialAccount officialAccount) { + WxMpService wxMpService = new WxMpServiceImpl(); + WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl(); + config.setAppId(officialAccount.getAppId()); + config.setSecret(officialAccount.getSecret()); + wxMpService.setWxMpConfigStorage(config); + return wxMpService; + } +} diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/ChannelAccountController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/ChannelAccountController.java index 308beb6..c6c393d 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/controller/ChannelAccountController.java +++ b/austin-web/src/main/java/com/java3y/austin/web/controller/ChannelAccountController.java @@ -2,17 +2,18 @@ package com.java3y.austin.web.controller; import cn.hutool.core.util.StrUtil; +import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.common.vo.BasicResultVO; import com.java3y.austin.support.domain.ChannelAccount; import com.java3y.austin.web.service.ChannelAccountService; +import com.java3y.austin.web.vo.amis.CommonAmisVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import java.util.Arrays; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; /** @@ -24,7 +25,7 @@ import java.util.stream.Collectors; @RestController @RequestMapping("/account") @Api("渠道账号管理接口") -@CrossOrigin(origins = "http://localhost:3000", allowCredentials = "true", allowedHeaders = "*") +@CrossOrigin(origins = AustinConstant.ORIGIN_VALUE, allowCredentials = "true", allowedHeaders = "*") public class ChannelAccountController { @Autowired @@ -47,7 +48,14 @@ public class ChannelAccountController { @GetMapping("/queryByChannelType") @ApiOperation("/根据渠道标识查询相关的记录") public BasicResultVO query(Integer channelType) { - return BasicResultVO.success(channelAccountService.queryByChannelType(channelType)); + List result = new ArrayList<>(); + + List channelAccounts = channelAccountService.queryByChannelType(channelType); + for (ChannelAccount channelAccount : channelAccounts) { + CommonAmisVo commonAmisVo = CommonAmisVo.builder().label(channelAccount.getName()).value(String.valueOf(channelAccount.getId())).build(); + result.add(commonAmisVo); + } + return BasicResultVO.success(result); } /** diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/DataController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/DataController.java index 6477ceb..c886021 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/controller/DataController.java +++ b/austin-web/src/main/java/com/java3y/austin/web/controller/DataController.java @@ -1,6 +1,7 @@ package com.java3y.austin.web.controller; import cn.hutool.core.util.StrUtil; +import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.common.enums.RespStatusEnum; import com.java3y.austin.common.vo.BasicResultVO; import com.java3y.austin.web.service.DataService; @@ -23,7 +24,7 @@ import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/trace") @Api("获取数据接口(全链路追踪)") -@CrossOrigin(origins = "http://localhost:3000", allowCredentials = "true", allowedHeaders = "*") +@CrossOrigin(origins = AustinConstant.ORIGIN_VALUE, allowCredentials = "true", allowedHeaders = "*") public class DataController { @Autowired private DataService dataService; diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/MaterialController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/MaterialController.java index 5ef2cc4..c48da71 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/controller/MaterialController.java +++ b/austin-web/src/main/java/com/java3y/austin/web/controller/MaterialController.java @@ -7,6 +7,7 @@ import com.dingtalk.api.DefaultDingTalkClient; import com.dingtalk.api.DingTalkClient; import com.dingtalk.api.request.OapiMediaUploadRequest; import com.dingtalk.api.response.OapiMediaUploadResponse; +import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.common.constant.SendAccountConstant; import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.common.enums.FileType; @@ -26,15 +27,16 @@ import org.springframework.web.multipart.MultipartFile; /** * 素材管理接口 + * * @author 3y */ @Slf4j @RestController @RequestMapping("/material") @Api("素材管理接口") -@CrossOrigin(origins = "http://localhost:3000", allowCredentials = "true", allowedHeaders = "*") -public class MaterialController { +@CrossOrigin(origins = AustinConstant.ORIGIN_VALUE, allowCredentials = "true", allowedHeaders = "*") +public class MaterialController { @Autowired private MaterialService materialService; diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java index 5d065a1..f16b51d 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java +++ b/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.google.common.base.Throwables; +import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.common.enums.RespStatusEnum; import com.java3y.austin.common.vo.BasicResultVO; import com.java3y.austin.service.api.domain.MessageParam; @@ -43,7 +44,7 @@ import java.util.stream.Collectors; @RestController @RequestMapping("/messageTemplate") @Api("发送消息") -@CrossOrigin(origins = "http://localhost:3000", allowCredentials = "true", allowedHeaders = "*") +@CrossOrigin(origins = AustinConstant.ORIGIN_VALUE, allowCredentials = "true", allowedHeaders = "*") public class MessageTemplateController { @Autowired diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/OfficialAccountController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/OfficialAccountController.java new file mode 100644 index 0000000..2fbef1d --- /dev/null +++ b/austin-web/src/main/java/com/java3y/austin/web/controller/OfficialAccountController.java @@ -0,0 +1,100 @@ +package com.java3y.austin.web.controller; + + +import cn.hutool.core.util.StrUtil; +import com.google.common.base.Throwables; +import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.enums.RespStatusEnum; +import com.java3y.austin.common.vo.BasicResultVO; +import com.java3y.austin.support.utils.WxServiceUtils; +import com.java3y.austin.web.vo.amis.CommonAmisVo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.template.WxMpTemplate; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; + +/** + * 微信服务号 + * + * @author 3y + */ +@Slf4j +@RestController +@RequestMapping("/officialAccount") +@Api("微信服务号") +@CrossOrigin(origins = {AustinConstant.ORIGIN_VALUE, "https://aisuda.bce.baidu.com"}, allowCredentials = "true", allowedHeaders = "*") +public class OfficialAccountController { + + + /** + * @param id 账号Id + * @return + */ + @GetMapping("/template/list") + @ApiOperation("/根据账号Id获取模板列表") + public BasicResultVO queryList(Long id) { + try { + List result = new ArrayList<>(); + + WxMpService wxMpService = WxServiceUtils.wxMpServiceMap.get(id); + List allPrivateTemplate = wxMpService.getTemplateMsgService().getAllPrivateTemplate(); + for (WxMpTemplate wxMpTemplate : allPrivateTemplate) { + CommonAmisVo commonAmisVo = CommonAmisVo.builder().label(wxMpTemplate.getTitle()).value(wxMpTemplate.getTemplateId()).build(); + result.add(commonAmisVo); + } + return BasicResultVO.success(result); + } catch (Exception e) { + log.error("OfficialAccountController#queryList fail:{}", Throwables.getStackTraceAsString(e)); + return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR); + } + } + + + /** + * 根据账号Id和模板ID获取模板列表 + * + * @return + * @ + */ + @GetMapping("/template/detailTemplate") + @ApiOperation("/根据账号Id和模板ID获取模板列表") + public BasicResultVO queryDetailList(Long id, String wxTemplateId) { + try { + List result = new ArrayList<>(); + + WxMpService wxMpService = WxServiceUtils.wxMpServiceMap.get(id); + List allPrivateTemplate = wxMpService.getTemplateMsgService().getAllPrivateTemplate(); + for (WxMpTemplate wxMpTemplate : allPrivateTemplate) { + if (wxTemplateId.equals(wxMpTemplate.getTemplateId())) { + String[] data = wxMpTemplate.getContent().split(StrUtil.LF); + for (String datum : data) { + String name = datum.substring(datum.indexOf("{{") + 2, datum.indexOf(".")); + CommonAmisVo commonAmisVo = CommonAmisVo.builder() + .name(name) + .type("text") + .required(true) + .build(); + if (datum.contains("first")) { + commonAmisVo.setLabel("名字"); + } else if (datum.contains("remark")) { + commonAmisVo.setLabel("备注"); + } else { + commonAmisVo.setLabel(datum.split(":")[0]); + + } + result.add(commonAmisVo); + } + } + } + return BasicResultVO.success(result); + } catch (Exception e) { + log.error("OfficialAccountController#queryList fail:{}", Throwables.getStackTraceAsString(e)); + return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR); + } + } +} diff --git a/austin-web/src/main/java/com/java3y/austin/web/service/impl/ChannelAccountServiceImpl.java b/austin-web/src/main/java/com/java3y/austin/web/service/impl/ChannelAccountServiceImpl.java index 94b01e7..70c9b85 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/service/impl/ChannelAccountServiceImpl.java +++ b/austin-web/src/main/java/com/java3y/austin/web/service/impl/ChannelAccountServiceImpl.java @@ -2,6 +2,7 @@ package com.java3y.austin.web.service.impl; import cn.hutool.core.date.DateUtil; import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.constant.CommonConstant; import com.java3y.austin.support.dao.ChannelAccountDao; import com.java3y.austin.support.domain.ChannelAccount; import com.java3y.austin.web.service.ChannelAccountService; @@ -22,7 +23,7 @@ public class ChannelAccountServiceImpl implements ChannelAccountService { public ChannelAccount save(ChannelAccount channelAccount) { if (channelAccount.getId() == null) { channelAccount.setCreated(Math.toIntExact(DateUtil.currentSeconds())); - channelAccount.setIsDeleted(AustinConstant.FALSE); + channelAccount.setIsDeleted(CommonConstant.FALSE); } channelAccount.setUpdated(Math.toIntExact(DateUtil.currentSeconds())); return channelAccountDao.save(channelAccount); @@ -30,7 +31,7 @@ public class ChannelAccountServiceImpl implements ChannelAccountService { @Override public List queryByChannelType(Integer channelType) { - return channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(AustinConstant.FALSE, channelType); + return channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(CommonConstant.FALSE, channelType); } @Override diff --git a/austin-web/src/main/java/com/java3y/austin/web/service/impl/MessageTemplateServiceImpl.java b/austin-web/src/main/java/com/java3y/austin/web/service/impl/MessageTemplateServiceImpl.java index 11f9ca6..d457982 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/service/impl/MessageTemplateServiceImpl.java +++ b/austin-web/src/main/java/com/java3y/austin/web/service/impl/MessageTemplateServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.constant.CommonConstant; import com.java3y.austin.common.enums.AuditStatus; import com.java3y.austin.common.enums.MessageStatus; import com.java3y.austin.common.enums.RespStatusEnum; @@ -44,12 +45,12 @@ public class MessageTemplateServiceImpl implements MessageTemplateService { @Override public List queryList(MessageTemplateParam param) { PageRequest pageRequest = PageRequest.of(param.getPage() - 1, param.getPerPage()); - return messageTemplateDao.findAllByIsDeletedEquals(AustinConstant.FALSE, pageRequest); + return messageTemplateDao.findAllByIsDeletedEqualsOrderByUpdatedDesc(CommonConstant.FALSE, pageRequest); } @Override public Long count() { - return messageTemplateDao.countByIsDeletedEquals(AustinConstant.FALSE); + return messageTemplateDao.countByIsDeletedEquals(CommonConstant.FALSE); } @Override @@ -68,7 +69,7 @@ public class MessageTemplateServiceImpl implements MessageTemplateService { @Override public void deleteByIds(List ids) { Iterable messageTemplates = messageTemplateDao.findAllById(ids); - messageTemplates.forEach(messageTemplate -> messageTemplate.setIsDeleted(AustinConstant.TRUE)); + messageTemplates.forEach(messageTemplate -> messageTemplate.setIsDeleted(CommonConstant.TRUE)); for (MessageTemplate messageTemplate : messageTemplates) { if (messageTemplate.getCronTaskId()!=null && messageTemplate.getCronTaskId() > 0) { cronTaskService.deleteCronTask(messageTemplate.getCronTaskId()); @@ -137,7 +138,7 @@ public class MessageTemplateServiceImpl implements MessageTemplateService { .setMsgStatus(MessageStatus.INIT.getCode()).setAuditStatus(AuditStatus.WAIT_AUDIT.getCode()) .setCreator("Java3y").setUpdator("Java3y").setTeam("公众号Java3y").setAuditor("3y") .setCreated(Math.toIntExact(DateUtil.currentSeconds())) - .setIsDeleted(AustinConstant.FALSE); + .setIsDeleted(CommonConstant.FALSE); } diff --git a/austin-web/src/main/java/com/java3y/austin/web/vo/amis/CommonAmisVo.java b/austin-web/src/main/java/com/java3y/austin/web/vo/amis/CommonAmisVo.java new file mode 100644 index 0000000..fe89b17 --- /dev/null +++ b/austin-web/src/main/java/com/java3y/austin/web/vo/amis/CommonAmisVo.java @@ -0,0 +1,27 @@ +package com.java3y.austin.web.vo.amis; + + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * amis的通用转化类 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class CommonAmisVo { + + private String type; + + private String label; + + private String value; + + private String name; + + private boolean required; +} diff --git a/austin-web/src/main/resources/application.properties b/austin-web/src/main/resources/application.properties index 9df52e3..81c188d 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,13 +112,15 @@ 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.username= austin.nacos.password= @@ -134,18 +128,26 @@ 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/local.properties b/austin-web/src/main/resources/local.properties index 807c7f2..b2bafc8 100644 --- a/austin-web/src/main/resources/local.properties +++ b/austin-web/src/main/resources/local.properties @@ -1,11 +1,4 @@ discardMsgIds = [] deduplicationRule = {"deduplication_10":{"num":1,"time":300},"deduplication_20":{"num":5}} -emailAccount = [{"email_10":{"host":"smtp.qq.com","port":465,"user":"23423432@qq.com","pass":"234324324","from":"123123@qq.com","starttlsEnable":"true","auth":true,"sslEnable":true}},{"email_20":{"host":"smtp.163.com","port":465,"user":"23423423@163.com","pass":"234234324","from":"112312312@163.com","starttlsEnable":"false","auth":true,"sslEnable":true}}] -smsAccount = [{"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":"云片"}}] -enterpriseWechatAccount = [{"enterprise_wechat_10":{"corpId":"23423423","corpSecret":"-234324234","agentId":1000002,"token":"234234","aesKey":"23423423"}}] -dingDingRobotAccount = [{"ding_ding_robot_10":{"secret":"234324324324","webhook":"https://oapi.dingtalk.com/robot/send?access_token=8d03b68d081f732343243242343247328b0c3003d164715d2c6c6e56"}}] -dingDingWorkNoticeAccount =[{"ding_ding_work_notice_10":{"appKey":"23423423","appSecret":"tQpvmkR863dYcuKDVfM23432432432423Nlx_fYLLLlpPJWHvWKbTu","agentId":"1523423423242"}}] -flowControlRule = {"flow_control_40":1} -geTuiAccount = [{"ge_tui_account_10":{"appId":"23423423","appKey":"234234234","masterSecret":"2342342342342"}}] -feiShuAccountRobot = [{"fei_shu_robot_10":{"webhook":"https://open.feishu.cn/open-apis/bot/v2/hook/c24b09ef-9aa3-4aad-9239-a7e05fcaf6ec"}}] msgTypeSmsConfig = [{"message_type_10":[{"weights":99,"scriptName":"TencentSmsScript"},{"weights":1,"scriptName":"YunPianSmsScript"}]},{"message_type_20":[{"weights":99,"scriptName":"TencentSmsScript"},{"weights":1,"scriptName":"YunPianSmsScript"}]},{"message_type_30":[{"weights":20,"scriptName":"TencentSmsScript"}]},{"message_type_40":[{"weights":20,"scriptName":"TencentSmsScript"}]}] +flowControl = {"flow_control_40":1} \ No newline at end of file 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 @@ - + diff --git a/sql/austin.sql b/sql/austin.sql index 7975658..f23e2ec 100644 --- a/sql/austin.sql +++ b/sql/austin.sql @@ -77,29 +77,3 @@ CREATE TABLE `channel_account` AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT ='渠道账号信息'; - - --- 实时类型 短信(无占位符) -INSERT INTO austin.message_template (id, name, audit_status, flow_id, msg_status, cron_task_id, cron_crowd_path, - expect_push_time, id_type, send_channel, template_type, msg_type, msg_content, - send_account, creator, updator, auditor, team, proposer, is_deleted, created, - updated) -VALUES (1, '买一送十活动', 10, '', 10, null, '', '', 30, 30, 20, 20, '{"content":"6666","url":"","title":""}', 10, 'Java3y', - 'Java3y', '3y', '公众号Java3y', '三歪', 0, 1646274112, 1646275242); - --- 实时类型 邮件(无占位符) -INSERT INTO austin.message_template (id, name, audit_status, flow_id, msg_status, cron_task_id, cron_crowd_path, - expect_push_time, id_type, send_channel, template_type, msg_type, msg_content, - send_account, creator, updator, auditor, team, proposer, is_deleted, created, - updated) -VALUES (2, '校招信息', 10, '', 10, null, '', '', 50, 40, 20, 10, '{"content":"你已成功获取到offer","url":"","title":"招聘通知"}', 10, - 'Java3y', 'Java3y', '3y', '公众号Java3y', '鸡蛋', 0, 1646274195, 1646274195); - --- 实时类型 短信(有占位符)占位符key 为 content -INSERT INTO austin.message_template (id, name, audit_status, flow_id, msg_status, cron_task_id, cron_crowd_path, - expect_push_time, id_type, send_channel, template_type, msg_type, msg_content, - send_account, creator, updator, auditor, team, proposer, is_deleted, created, - updated) -VALUES (3, '验证码通知', 10, '', 10, null, '', '', 30, 30, 20, 30, '{"content":"{$content}","url":"","title":""}', 10, - 'Java3y', 'Java3y', '3y', '公众号Java3y', '孙悟空', 0, 1646275213, 1646275213); -