|
|
|
@ -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<String> userIdList = new ArrayList<String>();
|
|
|
|
|
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) {
|
|
|
|
|