zhanghua
2023-10-25 31155ed32e2f2e2022b4b1697c8a2052a8543a48
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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获取失败");
//        }
//    }
 
}