예제 #1
0
파일: User.java 프로젝트: ccivo100/fire
 /**
  * 添加或更新缓存
  *
  * @param id
  */
 public void cacheAdd(Long id) {
   User user = User.dao.findById(id);
   CacheKit.put(DictKeys.cache_name_system, ThreadParamInit.cacheStart_user + id, user);
   CacheKit.put(
       DictKeys.cache_name_system,
       ThreadParamInit.cacheStart_user + user.getStr("username"),
       user);
   CacheKit.put(
       DictKeys.cache_name_system, ThreadParamInit.cacheStart_user + user.getStr("email"), user);
   CacheKit.put(
       DictKeys.cache_name_system, ThreadParamInit.cacheStart_user + user.getStr("phone"), user);
 }
예제 #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
 public static void putCache(HttpServletRequest request, Object value) {
   CacheKit.put(CACHE_NAME, getCacheKey(request), value);
 }
예제 #4
0
 public void putCache(Object key, Object value) {
   CacheKit.put(CACHE_NAME, key, value);
 }