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.
		
		
		
		
			
				
					
					
						
							94 lines
						
					
					
						
							2.6 KiB
						
					
					
				
			
		
		
	
	
							94 lines
						
					
					
						
							2.6 KiB
						
					
					
				package com.ynxbd.ali.helper;
 | 
						|
 | 
						|
import com.ynxbd.common.bean.User;
 | 
						|
import com.ynxbd.common.config.EhCacheConfig;
 | 
						|
import com.ynxbd.wx.wxfactory.WxCacheHelper;
 | 
						|
import org.ehcache.Cache;
 | 
						|
 | 
						|
public class AliCacheHelper {
 | 
						|
    public static final String AUTH_USER = "auth_user";
 | 
						|
    public static final String HOSPITAL_ORDER = "hospital_order"; // 消息推送
 | 
						|
    public static final String MFRS_TRE = "mfrstre"; // 能量
 | 
						|
 | 
						|
    static {
 | 
						|
        createUserCache();
 | 
						|
    }
 | 
						|
 | 
						|
    // 缓存
 | 
						|
    private static Cache<String, User> ALI_USER_CACHE;
 | 
						|
 | 
						|
    private synchronized static void createUserCache() {
 | 
						|
        if (ALI_USER_CACHE == null) {
 | 
						|
            ALI_USER_CACHE = EhCacheConfig.createCacheTTL(String.class, User.class, "ali_user_cache", (5400L)); // 一个半小时
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    public static Cache<String, User> getAliUserCache() {
 | 
						|
        if (ALI_USER_CACHE == null) {
 | 
						|
            createUserCache();
 | 
						|
        }
 | 
						|
        return ALI_USER_CACHE;
 | 
						|
    }
 | 
						|
 | 
						|
    public static User getCacheUser(String openid) {
 | 
						|
        if (ALI_USER_CACHE == null) {
 | 
						|
            createUserCache();
 | 
						|
        }
 | 
						|
        return ALI_USER_CACHE.get(openid);
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    public static User setUserAccessToken(String scopes, User user, String accessToken) {
 | 
						|
        if (scopes == null || user == null) {
 | 
						|
            return null;
 | 
						|
        }
 | 
						|
        user.setAccessToken(accessToken);
 | 
						|
        scopes = scopes.replaceAll("\\s*", "");
 | 
						|
        if (scopes.contains(AUTH_USER)) {
 | 
						|
            user.setAccess_token_user(accessToken);
 | 
						|
        }
 | 
						|
 | 
						|
        if (scopes.contains(HOSPITAL_ORDER)) {
 | 
						|
            user.setAccess_token_hosp_order(accessToken);
 | 
						|
        }
 | 
						|
 | 
						|
        if (scopes.contains(MFRS_TRE)) {
 | 
						|
            user.setAccess_token_energy(accessToken);
 | 
						|
        }
 | 
						|
        return user;
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    /**
 | 
						|
     * 消息推送token
 | 
						|
     */
 | 
						|
    public static String getHospAccessToken(String openid) {
 | 
						|
        if (openid == null) {
 | 
						|
            return null;
 | 
						|
        }
 | 
						|
        Cache<String, User> cache = WxCacheHelper.getUserCache();
 | 
						|
        User user = cache.get(openid);
 | 
						|
        if (user != null) {
 | 
						|
            return user.getAccess_token_hosp_order();
 | 
						|
        }
 | 
						|
        return null;
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    /**
 | 
						|
     * 能量token
 | 
						|
     */
 | 
						|
    public static String getEnergyAccessToken(String openid) {
 | 
						|
        if (openid == null) {
 | 
						|
            return null;
 | 
						|
        }
 | 
						|
        Cache<String, User> cache = WxCacheHelper.getUserCache();
 | 
						|
        User user = cache.get(openid);
 | 
						|
        if (user != null) {
 | 
						|
            return user.getAccess_token_energy();
 | 
						|
        }
 | 
						|
        return null;
 | 
						|
    }
 | 
						|
 | 
						|
}
 | 
						|
 |