You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.0 KiB
67 lines
2.0 KiB
/* |
|
* Copyright (C), 2018-2021 |
|
* Project: starter |
|
* FileName: DingTokenUtils |
|
* Author: Louis |
|
* Date: 2021/5/14 14:23 |
|
*/ |
|
package com.fr.plugin.xxxx.dingtalksyn.utils; |
|
|
|
import com.fanruan.api.log.LogKit; |
|
import com.fanruan.api.util.StringKit; |
|
import com.fr.plugin.xxxx.dingtalksyn.config.DingSynConfig; |
|
import com.fr.store.StateHubManager; |
|
import com.fr.store.StateHubService; |
|
|
|
import static com.fr.plugin.xxxx.dingtalksyn.utils.DingAPI.TOKEN_EXPIRE_TIME; |
|
|
|
/** |
|
* <Function Description><br> |
|
* <DingTokenUtils> |
|
* |
|
* @author fr.open |
|
* @since 1.0.0 |
|
*/ |
|
public class DingTokenUtils { |
|
|
|
public static final String DINGTALKSYN_ACCESS_TOKEN = "dingtalksyn_access_token"; |
|
public static final String DINGTALKSYN_SUITE_TICKET = "dingtalksyn_suite_ticket"; |
|
|
|
private static final StateHubService tokenService = StateHubManager.applyForService(DINGTALKSYN_ACCESS_TOKEN); |
|
private static final StateHubService ticketService = StateHubManager.applyForService(DINGTALKSYN_SUITE_TICKET); |
|
|
|
public DingTokenUtils() { |
|
} |
|
|
|
/** |
|
* 缓存钉钉端AccessToken |
|
* |
|
* @return |
|
*/ |
|
public static String getAccessToken() { |
|
String appKey = DingSynConfig.getInstance().getAppKey(); |
|
try { |
|
if (StringKit.isBlank(tokenService.get(appKey))) { |
|
tokenService.put(appKey, DingAPI.getAccessToken(), TOKEN_EXPIRE_TIME); |
|
} |
|
return tokenService.get(appKey); |
|
} catch (Exception e) { |
|
LogKit.error(e.getMessage(), e); |
|
return StringKit.EMPTY; |
|
} |
|
} |
|
|
|
/** |
|
* 缓存钉钉端SuiteTicket |
|
* |
|
* @return |
|
*/ |
|
public static void setSuiteTicket(String suiteTicket) { |
|
String appKey = DingSynConfig.getInstance().getAppKey(); |
|
try { |
|
ticketService.put(appKey, suiteTicket, TOKEN_EXPIRE_TIME); |
|
} catch (Exception e) { |
|
LogKit.error(e.getMessage(), e); |
|
} |
|
} |
|
} |