All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.net.wanmo.plugin.wechat.officialaccount.storage.AccessTokenLog Maven / Gradle / Ivy

package cn.net.wanmo.plugin.wechat.officialaccount.storage;

import cn.net.wanmo.plugin.wechat.officialaccount.util.accesstoken.pojo.AccessToken;
import com.google.common.collect.Lists;

import java.util.*;

public class AccessTokenLog {
    /**
     * 令牌的记录 
*/ public static Map> map = new HashMap<>(); /** * 每个令牌类型保存日志的最多个数 */ private static int maxSize = 30; /** * 获取令牌日志 * * @param appId 企业ID * @return 日志集合 */ public static List get(String appId) { List list = map.getOrDefault(appId, Lists.newArrayList()); Collections.reverse(list); return list; } /** * 添加 token 日志; * * @param appId 企业ID * @param accessToken 待保存的令牌 */ public static void put(String appId, AccessToken accessToken) { List list = map.getOrDefault(appId, Lists.newArrayList()); { // 添加日志 list.add(accessToken); } { // 日志数量控制 int size = list.size(); for (int i = 0; i < size - maxSize; i++) { list.remove(0); } } map.put(appId, list); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy