Esempio n. 1
0
 public static final String wxGetJsapiTicket() {
   Cache cache = Cache.getInstance();
   long now = new Date().getTime() / 1000;
   if (!cache.exist("wxJsapiTicket")
       || now - (long) cache.get("wxJsapiTicketTime") > Constant.W_EXPIRE_IN) {
     String accessToken = Constant.wxGetAccessToken();
     if (accessToken == null) {
       return null;
     }
     String url = Constant.W_GET_JSAPI_TICKET + "?access_token=" + accessToken + "&type=jsapi";
     String ret = Web.sendGet(url);
     JSONObject json = JSONObject.fromObject(ret);
     if (json.containsKey("errcode") && json.getInt("errcode") != 0) {
       return null;
     }
     cache.set("wxJsapiTicket", json.getString("ticket"));
     cache.set("wxJsapiTicketTime", now);
     Constant.W_EXPIRE_IN = json.getInt("expires_in") - 200;
   }
   return (String) cache.get("wxJsapiTicket");
 }
Esempio n. 2
0
 // 获取微信accessToken和JsapiTicket缓存
 public static final String wxGetAccessToken() {
   Cache cache = Cache.getInstance();
   long now = new Date().getTime() / 1000;
   if (!cache.exist("wxAccessToken")
       || now - (long) cache.get("wxAccessTokenTime") > Constant.W_EXPIRE_IN) {
     String url =
         Constant.W_GET_ACCESS_TOKEN_URL
             + "?grant_type=client_credential&appid="
             + Constant.W_APP_ID
             + "&secret="
             + Constant.W_APP_SECRET;
     String ret = Web.sendGet(url);
     JSONObject json = JSONObject.fromObject(ret);
     if (json.containsKey("errcode") && json.getInt("errcode") != 0) {
       return null;
     }
     cache.set("wxAccessToken", json.getString("access_token"));
     cache.set("wxAccessTokenTime", now);
     Constant.W_EXPIRE_IN = json.getInt("expires_in") - 200;
   }
   return (String) cache.get("wxAccessToken");
 }
  protected Listener getListener(Container.Entry entry) {
    URI key = entry.getUri();

    if (cache.containsKey(key)) {
      return cache.get(key);
    } else {
      Listener listener;

      try (InputStream inputStream = entry.getInputStream()) {
        ANTLRJavaParser.parse(new ANTLRInputStream(inputStream), listener = new Listener(entry));
      } catch (IOException ignore) {
        listener = null;
      }

      cache.put(key, listener);
      return listener;
    }
  }