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();
|
}
|
|
|
}
|
|
}
|