package com.ycl.config;
|
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.xxpt.gateway.shared.api.request.OapiGettokenJsonRequest;
|
import com.alibaba.xxpt.gateway.shared.api.response.OapiGettokenJsonResponse;
|
import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient;
|
import com.alibaba.xxpt.gateway.shared.client.http.IntelligentGetClient;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.PostConstruct;
|
import java.util.concurrent.TimeUnit;
|
@Slf4j
|
@Component
|
@EnableScheduling
|
public class DdTest {
|
|
// @Autowired
|
// private RedisTemplate<Object,Object> redisTemplate;
|
|
@Value("${zzding.app-key}")
|
public String appKey;
|
|
@Value("${zzding.app-secret}")
|
public String appSecret;
|
|
private static ExecutableClient executableClient;
|
|
@PostConstruct
|
public void init(){
|
executableClient= ExecutableClient.getInstance();
|
executableClient.setDomainName("openplatform.dg-work.cn");
|
executableClient.setProtocal("https");
|
executableClient.setAccessKey(appKey);
|
executableClient.setSecretKey(appSecret);
|
executableClient.init();
|
}
|
|
public static ExecutableClient getExecutableClient() {
|
return executableClient;
|
}
|
|
|
// //每一小时30分执行一次,获取最新token放入redis
|
// @Scheduled(initialDelay = 0L,fixedDelay = 5400000L)
|
// public void getToken() {
|
// IntelligentGetClient intelligentGetClient = DdTest.getExecutableClient().newIntelligentGetClient("/gettoken.json");
|
// OapiGettokenJsonRequest oapiGettokenJsonRequest = new OapiGettokenJsonRequest();
|
// oapiGettokenJsonRequest.setAppkey(appKey);
|
// oapiGettokenJsonRequest.setAppsecret(appSecret);
|
// OapiGettokenJsonResponse apiResult = intelligentGetClient.get(oapiGettokenJsonRequest);
|
// String data = apiResult.getContent().getData();
|
// if (data != null && !data.contains("errorCode")) {
|
// log.info("获取token成功");
|
// JSONObject jsonObject = JSON.parseObject(data);
|
// String token = (String) jsonObject.get("accessToken");
|
// log.info("获取token成功:{}",token);
|
// redisTemplate.opsForValue().set(MqConstant.DD_ACCESS_TOKEN, token, 2, TimeUnit.HOURS);
|
// }else {
|
// throw new RuntimeException("钉钉token获取失败");
|
// }
|
// }
|
|
}
|