|
@@ -5,6 +5,7 @@ import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.core.io.FileSystemResource;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.http.HttpEntity;
|
|
@@ -14,7 +15,6 @@ import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
-
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
@@ -35,8 +35,13 @@ public class DingTalkServiceImpl implements DingtalkService {
|
|
|
@Autowired
|
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
- @Autowired
|
|
|
- private RedisTemplate<String, Object> redisTemplate;
|
|
|
+ @Autowired(required = false)
|
|
|
+ @Qualifier("dingtalkRedisTemplate")
|
|
|
+ private RedisTemplate<String, Object> dingtalkRedisTemplate;
|
|
|
+
|
|
|
+ @Autowired(required = false)
|
|
|
+ @Qualifier("redisTemplate")
|
|
|
+ private RedisTemplate<String, Object> defaultRedisTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
private ObjectMapper objectMapper;
|
|
@@ -180,6 +185,11 @@ public class DingTalkServiceImpl implements DingtalkService {
|
|
|
* @return
|
|
|
*/
|
|
|
private String getApiToken() {
|
|
|
+ RedisTemplate<String, Object> redisTemplate = dingtalkRedisTemplate != null ? dingtalkRedisTemplate
|
|
|
+ : defaultRedisTemplate;
|
|
|
+ if (redisTemplate == null) {
|
|
|
+ throw new RuntimeException("缺少RedisTemplate<String, Object>...");
|
|
|
+ }
|
|
|
Object token = redisTemplate.opsForValue().get(API_ACCESS_TOKEN_REDIS_KEY + properties.getAppKey());
|
|
|
if (token == null) {
|
|
|
// 调用api获取accessToken
|
|
@@ -223,8 +233,12 @@ public class DingTalkServiceImpl implements DingtalkService {
|
|
|
* @return
|
|
|
*/
|
|
|
private String getOapiToken() {
|
|
|
+ RedisTemplate<String, Object> redisTemplate = dingtalkRedisTemplate != null ? dingtalkRedisTemplate
|
|
|
+ : defaultRedisTemplate;
|
|
|
+ if (redisTemplate == null) {
|
|
|
+ throw new RuntimeException("缺少RedisTemplate<String, Object>...");
|
|
|
+ }
|
|
|
Object token = redisTemplate.opsForValue().get(OAPI_ACCESS_TOKEN_REDIS_KEY + properties.getAppKey());
|
|
|
-
|
|
|
if (token == null) {
|
|
|
String url = "https://oapi.dingtalk.com/gettoken?appkey={0}&appsecret={1}";
|
|
|
|