@Component
public class ApplicationConfig implements ApplicationListener<ContextRefreshedEvent> {
@Autowired
WebApplicationContext context;
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
this.context.getServletContext().setAttribute("logout", NanWeiConfiguration.LOGOUTBACK);
new Thread(new AccessTokenThread()).start();
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
public class AccessTokenThread extends Thread
{
private static Logger log = LoggerFactory.getLogger(AccessTokenThread.class);
private static String access_token_url=QztConfiguration.GETAPPTOCKEN;
public static String access_token_val;
@Override
public void run() {
while(true){
access_token_val= getAccessToken();
try {
Thread.sleep(6000*1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private static String getAccessToken() {
HashMap hashMap = null;
try {
hashMap = HttpUtils.sendRequestCommon(QztConfiguration.GETAPPTOCKEN,
new HashedMap(),
"GET", false,false);
Integer resultCode = (Integer) hashMap.get("code");
String data = (String) hashMap.get("data");
hashMap = JSON.parseObject(data, HashMap.class);
Integer errCode = (Integer) hashMap.get("errCode");
if (errCode.equals(0)) {
JSONObject tokenInfo = (JSONObject) hashMap.get("data");
String token = (String) tokenInfo.get("appToken");
QztConfiguration.appToken = token;
return token;
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
- 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