From 6559511a76cb02117ff3d3a12db428cfd1c9db39 Mon Sep 17 00:00:00 2001 From: "zhang.xw" Date: Mon, 12 Sep 2022 20:12:59 +0800 Subject: [PATCH] =?UTF-8?q?ems=20=E5=BC=82=E5=B8=B8=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/base/WhiteController.java | 31 ++++++++++++++++------ .../src/main/resources/application-dev.properties | 10 ++++++- .../src/main/resources/log4j2-spring-dev.xml | 4 +-- .../src/main/resources/log4j2-spring.xml | 6 ++--- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/base/WhiteController.java b/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/base/WhiteController.java index 27e6f38..726b1c1 100644 --- a/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/base/WhiteController.java +++ b/modules/i3plus-core-apiservice/src/main/java/cn/estsh/i3plus/core/apiservice/controller/base/WhiteController.java @@ -1171,9 +1171,12 @@ public class WhiteController extends CoreBaseController { private static final Long ACCESS_TOKEN_EXPIRE_TIME = 7080L; private static final String ACCESS_TOKEN_KEY = "ding_talk:access_token"; + private static final String ACCESS_EMS_TOKEN_KEY = "ding_talk_ems:access_token"; private static final String ACCESS_MENU_TOKEN_KEY = "ding_talk:menu_access_token"; + + /** * 钉钉单聊机器人批量发送消息 * @@ -1248,7 +1251,7 @@ public class WhiteController extends CoreBaseController { return ResultBean.fail(e).setMsg("发送失败"); } BatchSendOTOHeaders batchSendOTOHeaders = new BatchSendOTOHeaders(); - batchSendOTOHeaders.xAcsDingtalkAccessToken = getAccessToken(); + batchSendOTOHeaders.xAcsDingtalkAccessToken = getAccessToken(dingSendBatchRequestModel.getSoftType()); BatchSendOTORequest batchSendOTORequest = new BatchSendOTORequest(); List userIdList = new ArrayList(); phoneNumberList.forEach(el -> { @@ -1267,6 +1270,9 @@ public class WhiteController extends CoreBaseController { // userIdList.add("070537336424114523"); String dingTalkAppKey = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_KEY); + if (Objects.equals(dingSendBatchRequestModel.getSoftType(), "ems")) { + dingTalkAppKey = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_EMS_APP_KEY); + } batchSendOTORequest.setRobotCode(dingTalkAppKey); batchSendOTORequest.setUserIds(userIdList); // markdown officialImageMsg @@ -1351,18 +1357,27 @@ public class WhiteController extends CoreBaseController { * * @return */ - private String getAccessToken() { - Object accessTokenCached = redisCore.getObject(ACCESS_TOKEN_KEY); + private String getAccessToken(String softType) { + String accessTokenKey = ACCESS_TOKEN_KEY; + + String dingTalkAppKey = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_KEY); + String dingTalkAppSecret = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_SECRET); + if (Objects.equals(softType, "ems")) { + accessTokenKey = ACCESS_EMS_TOKEN_KEY; + dingTalkAppKey = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_EMS_APP_KEY); + dingTalkAppSecret = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_EMS_APP_SECRET); + } + Object accessTokenCached = redisCore.getObject(accessTokenKey); if (accessTokenCached != null) { - LOGGER.info("通过缓存获取到的钉钉token, key={},value={}", ACCESS_TOKEN_KEY, accessTokenCached); + LOGGER.info("通过缓存获取andon到的钉钉token, key={},value={}", accessTokenKey, accessTokenCached); return String.valueOf(accessTokenCached); } + Config config = new Config(); config.protocol = "https"; config.regionId = "central"; com.aliyun.dingtalkoauth2_1_0.Client client = null; - String dingTalkAppKey = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_KEY); - String dingTalkAppSecret = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_SECRET); + try { client = new com.aliyun.dingtalkoauth2_1_0.Client(config); } catch (Exception e) { @@ -1374,8 +1389,8 @@ public class WhiteController extends CoreBaseController { try { GetAccessTokenResponse response = client.getAccessToken(getAccessTokenRequest); if (!StringUtils.isEmpty(response.body.accessToken)) { - LOGGER.info("插入钉钉token缓存, key={},value={}", ACCESS_TOKEN_KEY, response.body.accessToken); - redisCore.putObject(ACCESS_TOKEN_KEY, response.body.accessToken, ACCESS_TOKEN_EXPIRE_TIME); + LOGGER.info("插入钉钉token缓存, key={},value={}", accessTokenKey, response.body.accessToken); + redisCore.putObject(accessTokenKey, response.body.accessToken, ACCESS_TOKEN_EXPIRE_TIME); } return response.body.accessToken; } catch (TeaException err) { diff --git a/modules/i3plus-core-apiservice/src/main/resources/application-dev.properties b/modules/i3plus-core-apiservice/src/main/resources/application-dev.properties index 2cae99b..0cc2720 100644 --- a/modules/i3plus-core-apiservice/src/main/resources/application-dev.properties +++ b/modules/i3plus-core-apiservice/src/main/resources/application-dev.properties @@ -11,7 +11,7 @@ logging.config=classpath:log4j2-spring-dev.xml ########\u5E73\u53F0\u76F8\u5173\u53C2\u6570########## #\u662F\u5426\u5F00\u542Fredis\u7F13\u5B58 -impp.config.redis=true +#impp.config.redis=true #\u662F\u5426\u5F00\u542FrabbitMQ impp.config.rabbitmq=true #\u662F\u5426\u5F00\u542Fswagger @@ -115,6 +115,14 @@ redis.hostName=192.168.1.55 redis.port=16376 #\u5982\u679C\u6709\u5BC6\u7801 redis.password= + +impp.config.redis=false +impp.config.sentinel.redis = true + +spring.redis.sentinel.master=mymaster +spring.redis.sentinel.password = +spring.redis.sentinel.nodes= 192.168.2.246:6382,192.168.2.246:6383,192.168.2.246:6384 + ##\u5176\u4ED6redis\u914D\u7F6E\u9700\u8981\u8C03\u6574\u7684\u52A0\u5728\u6B64\u5904 ################## rabbitMQ\u914D\u7F6E #################### spring.rabbitmq.vhost=/ diff --git a/modules/i3plus-core-apiservice/src/main/resources/log4j2-spring-dev.xml b/modules/i3plus-core-apiservice/src/main/resources/log4j2-spring-dev.xml index 81fb966..25f7cae 100644 --- a/modules/i3plus-core-apiservice/src/main/resources/log4j2-spring-dev.xml +++ b/modules/i3plus-core-apiservice/src/main/resources/log4j2-spring-dev.xml @@ -7,13 +7,13 @@ - %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %p %c(%M:%L) - %m%n + %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%X{traceId}] %p %c(%M:%L) - %m%n - + diff --git a/modules/i3plus-core-apiservice/src/main/resources/log4j2-spring.xml b/modules/i3plus-core-apiservice/src/main/resources/log4j2-spring.xml index 4d45419..779dbf0 100644 --- a/modules/i3plus-core-apiservice/src/main/resources/log4j2-spring.xml +++ b/modules/i3plus-core-apiservice/src/main/resources/log4j2-spring.xml @@ -10,14 +10,14 @@ - %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %p %c(%M:%L) - %m%n - %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %p %-5level %class{36} %L %M - %msg%xEx%n + %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%X{traceId}] %p %c(%M:%L) - %m%n + %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%X{traceId}] %p %-5level %class{36} %L %M - %msg%xEx%n - +