liusuyi
2024-10-21 e30696c0e740a678af9b00c5918b61a9f965e9ec
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.ard.tianyu.config;
 
import com.ard.tianyu.http.TYClient;
import com.ard.tianyu.model.dto.TokenDTO;
import com.ard.tianyu.model.receiver.AccessTokenReceiver;
import com.ard.tianyu.model.receiver.BoxReceiver;
import com.ard.tianyu.model.receiver.TyHttpCommonReceiver;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.DigestUtils;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
/**
 * TianyuConfiguration
 *
 * @author liusuyi
 * @date 2024年10月21日15:16
 **/
@Configuration
@Slf4j
@Data
@ConfigurationProperties(prefix = "tianyu")
public class TianyuConfiguration {
 
    private String endpoint;
 
    private String accesskeyid;
 
    private String accesskeysecret;
 
 
    private long timestamp;
    public long getTimeStamp()
    {
        timestamp = new Date().getTime();
        return timestamp;
    }
    private String encryptstr;
 
    public String getEncryptStr()
    {
        String sb = new StringBuilder()
                .append(accesskeyid)
                .append(accesskeysecret)
                .append(getTimeStamp())
                .toString();
        encryptstr = DigestUtils.md5DigestAsHex(sb.getBytes());
        return encryptstr;
    }
    @Resource
    private TYClient tyClient;
 
    private AccessTokenReceiver accessToken;
 
    public AccessTokenReceiver getAccessToken() {
        if(accessToken != null)
            return accessToken;
        // 准备请求的json
        TokenDTO gtd = TokenDTO.builder()
                .accessKeyId(accesskeyid)
                .encryptStr(getEncryptStr())
                .timeStamp(timestamp)
                .build();
        TyHttpCommonReceiver<AccessTokenReceiver> getTokenRes = tyClient.getToken(gtd);
        //{"state":0,"content":{"companyId":4127,"accessToken":"sOONT0MMVdoKcMBibb40xxgrUrq0Hw9RFiajic3KOzoNtk"}}
        accessToken = getTokenRes.getContent();
        return accessToken;
    }
 
    private List<BoxReceiver> boxList;
 
    public List<BoxReceiver> getBoxList(){
        if(boxList !=null)
            return boxList;
        //请求云盒列表
        TyHttpCommonReceiver<List<BoxReceiver>> getBoxList = tyClient.getBoxList(getAccessToken().convertFromDTO());
        boxList = getBoxList.getContent();
        return boxList;
    }
}