suerprisePlus
2024-10-18 1efa47bc58fe0673a231233f644d3a5f8277e42c
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
package com.yb.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yb.config.XzConfig;
import com.yb.helper.RsaHelper;
import com.yb.util.EntityHttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import sun.text.resources.FormatData;
 
import java.io.IOException;
import java.util.HashMap;
 
@Component
@Configuration
@EnableScheduling
public class TokenController {
    @Autowired
    private EntityHttpUtil entityHttpUtil;
    @Autowired
    private XzConfig xzConfig;
    @Autowired
    WebSocketController webSocketController;
 
    private String publickey = null;
 
    @Async
    @Scheduled(fixedRate = 900000L)
    public void webSocketGetInfo() throws Exception, IOException, InterruptedException {
 
        getGedbPublickey();
    }
 
    private void getGedbPublickey() throws Exception {
        String url = xzConfig.accountgraphicalUrl + xzConfig.securityPublickey;
        JSONObject data = JSONObject.parseObject(entityHttpUtil.getAgentMessage(url));
        System.out.println("webSocketGetInfo: data" + data);
        String code = data.getString("code");
        if (code.contains("200")) {
            publickey = data.getString("data");
            getGedbToken();
        } else {
            System.out.println("webSocketGetInfo: 接口异常" + data);
            getGedbPublickey();
        }
    }
 
    private void getGedbToken() throws Exception {
        String url = xzConfig.accountgraphicalUrl + xzConfig.securityLogin;
        HashMap<String, String> hashMap = new HashMap();
        hashMap.put("userid", xzConfig.logUser);
        String encrypt = RsaHelper.encrypt(publickey, xzConfig.logPass);
        hashMap.put("password", encrypt);
        JSONObject data = JSON.parseObject(entityHttpUtil.getPostAccount(url, hashMap));
        String code = data.getString("code");
        if (code.contains("200")) {
            JSONObject token_data = JSONObject.parseObject(data.getString("data"));
            xzConfig.token = token_data.getString("token");
        } else {
            System.out.println("webSocketGetInfo: 接口异常" + data);
            getGedbToken();
        }
 
 
    }
 
}