示例#1
0
文件: User.java 项目: ccivo100/fire
 /**
  * 删除缓存
  *
  * @param id
  */
 public void cacheRemove(Long id) {
   User user = User.dao.findById(id);
   CacheKit.remove(DictKeys.cache_name_system, ThreadParamInit.cacheStart_user + id);
   CacheKit.remove(
       DictKeys.cache_name_system, ThreadParamInit.cacheStart_user + user.getStr("username"));
   CacheKit.remove(
       DictKeys.cache_name_system, ThreadParamInit.cacheStart_user + user.getStr("email"));
   CacheKit.remove(
       DictKeys.cache_name_system, ThreadParamInit.cacheStart_user + user.getStr("phone"));
 }
示例#2
0
  /**
   * 从微信得到accessToken的凭证公共代码块
   *
   * @return
   */
  private static RecevieToken getAccessTokenCommon() {
    // 参数配置的 appID
    Param paramAppId =
        (Param)
            CacheKit.get(
                DictKeys.cache_name_system, ThreadParamInit.cacheStart_param + weixin_appID_key);
    String weixin_appID = paramAppId.getStr("val");

    // 参数配置的 appSecret
    Param paramAppSecret =
        (Param)
            CacheKit.get(
                DictKeys.cache_name_system,
                ThreadParamInit.cacheStart_param + weixin_appSecret_key);
    String weixin_appSecret = paramAppSecret.getStr("val");

    // 获取地址和参数
    StringBuilder sb = new StringBuilder();
    sb.append(weixin_token_url).append("?").append("grant_type=client_credential");
    sb.append("&appid=").append(weixin_appID);
    sb.append("&secret=").append(weixin_appSecret);

    try {
      // 获取
      String jsonStr = ToolHttp.get(true, sb.toString());
      RecevieToken recevieToken = JSON.parseObject(jsonStr, RecevieToken.class);
      if (recevieToken.getAccess_token() != null && !recevieToken.getAccess_token().isEmpty()) {
        recevieToken.setDate(new Date()); // 设置获取时间
        // 放入缓存
        CacheKit.put(DictKeys.cache_name_system, weixin_access_token, recevieToken);
        log.info("获取AccessToken:" + jsonStr);
        return recevieToken;
      }
      return null;
    } catch (Exception e) {
      log.error("ToolWeiXin.getAccessToken从微信得到accessToken的凭证异常");
      return null;
    }
  }
示例#3
0
  /**
   * 从微信得到accessToken的凭证
   *
   * @return
   */
  public static RecevieToken getAccessToken() {
    // 取缓存
    RecevieToken recevieToken =
        (RecevieToken) CacheKit.get(DictKeys.cache_name_system, weixin_access_token);
    if (null != recevieToken) {
      // 判断是否有效
      long interval = (new Date().getTime() - recevieToken.getDate().getTime()) / 1000; // 存在时间,秒
      long expires_in =
          Long.parseLong(recevieToken.getExpires_in()) - 200; // 凭证有效时间,单位:秒 ,默认有效期为7200秒
      if (interval > expires_in) {
        recevieToken = getAccessTokenCommon();
      }
    } else {
      recevieToken = getAccessTokenCommon();
    }

    return recevieToken;
  }
示例#4
0
 public static void putCache(HttpServletRequest request, Object value) {
   CacheKit.put(CACHE_NAME, getCacheKey(request), value);
 }
示例#5
0
 public static String getCache(String key) {
   return CacheKit.get(CACHE_NAME, key);
 }
示例#6
0
 public static void clearCache() {
   CacheKit.removeAll(CACHE_NAME);
 }
示例#7
0
 public M getCache(Object key, IDataLoader dataloader) {
   return CacheKit.get(CACHE_NAME, key, dataloader);
 }
示例#8
0
 public M getCache(Object key) {
   return CacheKit.get(CACHE_NAME, key);
 }
示例#9
0
 public void putCache(Object key, Object value) {
   CacheKit.put(CACHE_NAME, key, value);
 }
示例#10
0
 public void removeCache(Object key) {
   CacheKit.remove(CACHE_NAME, key);
 }
示例#11
0
文件: User.java 项目: ccivo100/fire
 /**
  * 获取缓存
  *
  * @param id
  * @return
  */
 public User cacheGet(Long id) {
   User user = CacheKit.get(DictKeys.cache_name_system, ThreadParamInit.cacheStart_user + id);
   return user;
 }