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

com.zopen.wechat.work.task.WechatWorkInfo Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
package com.zopen.wechat.work.task;

import com.zcj.util.UtilString;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class WechatWorkInfo {

    private static Map agentIdInfoMap = new ConcurrentHashMap<>();

    private String corpId;// 企业ID
    private String agentId;// 应用ID
    private String corpSecret;// 应用秘钥
    private String accessToken;// 用于 API 调用的 TOKEN

    private WechatWorkInfo() {

    }

    public static synchronized void saveAccessToken(final String corpId, final String agentId, final String corpSecret, final String appAccessToken) {
        if (UtilString.isBlank(corpId) || UtilString.isBlank(agentId) || UtilString.isBlank(corpSecret) || UtilString.isBlank(appAccessToken)) {
            return;
        }
        WechatWorkInfo wechatInfo = new WechatWorkInfo();
        wechatInfo.corpId = corpId;
        wechatInfo.agentId = agentId;
        wechatInfo.corpSecret = corpSecret;
        wechatInfo.accessToken = appAccessToken;
        agentIdInfoMap.put(agentId, wechatInfo);
    }

    public static String getAccessToken(final String agentId) {
        if (UtilString.isBlank(agentId)) {
            return null;
        }
        WechatWorkInfo wechatInfo = agentIdInfoMap.get(agentId);
        if (wechatInfo == null) {
            return null;
        }
        return wechatInfo.accessToken;
    }

    public static String getCorpSecret(final String agentId) {
        if (UtilString.isBlank(agentId)) {
            return null;
        }
        WechatWorkInfo wechatInfo = agentIdInfoMap.get(agentId);
        if (wechatInfo == null) {
            return null;
        }
        return wechatInfo.corpSecret;
    }

    public static String getCorpId(final String agentId) {
        if (UtilString.isBlank(agentId)) {
            return null;
        }
        WechatWorkInfo wechatInfo = agentIdInfoMap.get(agentId);
        if (wechatInfo == null) {
            return null;
        }
        return wechatInfo.corpId;
    }

    public static Map getAgentIdInfoMap() {
        return agentIdInfoMap;
    }

    public String getCorpId() {
        return corpId;
    }

    public String getAgentId() {
        return agentId;
    }

    public String getCorpSecret() {
        return corpSecret;
    }

    public String getAccessToken() {
        return accessToken;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy