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

com.zopen.wechat.mp.task.WechatInfo Maven / Gradle / Ivy

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

import com.zcj.util.UtilString;

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

public class WechatInfo {

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

    private String appId;
    private String appSecret;
    private String accessToken;
    private String jsapiTicket;

    private WechatInfo() {

    }

    public static synchronized void saveAccessToken(final String appId, final String appSecret,
                                                    final String appAccessToken, final String jsapiTicket) {
        if (UtilString.isBlank(appId) || UtilString.isBlank(appSecret) || UtilString.isBlank(appAccessToken)) {
            return;
        }
        WechatInfo wechatInfo = new WechatInfo();
        wechatInfo.appId = appId;
        wechatInfo.appSecret = appSecret;
        wechatInfo.accessToken = appAccessToken;
        wechatInfo.jsapiTicket = jsapiTicket;
        openIdInfoMap.put(appId, wechatInfo);
    }

    public static String getAccessToken(final String appId) {
        if (UtilString.isBlank(appId)) {
            return null;
        }
        WechatInfo wechatInfo = openIdInfoMap.get(appId);
        if (wechatInfo == null) {
            return null;
        }
        return wechatInfo.accessToken;
    }

    public static String getAppSecret(final String appId) {
        if (UtilString.isBlank(appId)) {
            return null;
        }
        WechatInfo wechatInfo = openIdInfoMap.get(appId);
        if (wechatInfo == null) {
            return null;
        }
        return wechatInfo.appSecret;
    }

    public static String getJsapiTicket(final String appId) {
        if (UtilString.isBlank(appId)) {
            return null;
        }
        WechatInfo wechatInfo = openIdInfoMap.get(appId);
        if (wechatInfo == null) {
            return null;
        }
        return wechatInfo.jsapiTicket;
    }

    public static Map getOpenIdInfoMap() {
        return openIdInfoMap;
    }

    public String getAppId() {
        return appId;
    }

    public String getAppSecret() {
        return appSecret;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy