public static NutMap toAttrMap(NamedNodeMap attrs) {
   NutMap map = new NutMap();
   int len = attrs.getLength();
   for (int j = 0; j < len; j++) {
     Attr attr = (Attr) attrs.item(j);
     map.put(attr.getName(), attr.getValue());
   }
   return map;
 }
Example #2
0
 public static NutMap kv2map(String kv) {
   NutMap re = new NutMap();
   if (kv == null || kv.length() == 0 || !kv.contains("=")) return re;
   String[] tmps = kv.split(",");
   for (String tmp : tmps) {
     if (!tmp.contains("=")) continue;
     String[] tmps2 = tmp.split("=", 2);
     re.put(tmps2[0], tmps2[1]);
   }
   return re;
 }
  public static Map<String, NutMap> read(String path) {
    Map<String, NutMap> maps = new LinkedHashMap<>();
    Document doc = Xmls.xml(DubboConfigureReader.class.getClassLoader().getResourceAsStream(path));
    doc.normalizeDocument();
    Element top = doc.getDocumentElement();
    NodeList list = top.getChildNodes();
    int count = list.getLength();

    for (int i = 0; i < count; i++) {
      Node node = list.item(i);
      if (node instanceof Element) {
        Element ele = (Element) node;
        String eleName = ele.getNodeName();
        if (!eleName.startsWith("dubbo:")) continue; // 跳过非dubbo节点
        String typeName = eleName.substring("dubbo:".length());
        NutMap attrs = toAttrMap(ele.getAttributes());
        log.debug("found " + typeName);
        String genBeanName = ele.getAttribute("id");
        if (Strings.isBlank(genBeanName)) {
          if ("protocol".equals(typeName)) genBeanName = "dubbo";
          else {
            genBeanName = ele.getAttribute("interface");
            if (Strings.isBlank(genBeanName)) {
              try {
                genBeanName =
                    Class.forName(
                            "com.alibaba.dubbo.config." + Strings.upperFirst(typeName) + "Config")
                        .getName();
              } catch (ClassNotFoundException e) {
                throw Lang.wrapThrow(e);
              }
            }
          }
          if (maps.containsKey(genBeanName)) {
            int _count = 2;
            while (true) {
              String key = genBeanName + "_" + _count;
              if (maps.containsKey(key)) {
                _count++;
                continue;
              }
              genBeanName += "_" + _count;
              break;
            }
          }
        }
        attrs.put("_typeName", typeName);
        maps.put(genBeanName, attrs);
      }
    }
    return maps;
  }
  /**
   * @api {get} /yvr/api/v1/topic/:id 获取帖子的详细数据
   * @apiGroup Topic
   * @apiVersion 1.0.0
   * @apiParam {String} id 帖子id
   * @apiParam {boolean} [mdrender=true] 是否渲染Markdown
   * @apiSuccess {Object[]} data 帖子数据
   * @apiSuccess {String} data.id 唯一标示符
   * @apiSuccess {String} data.title 标题
   * @apiSuccess {String} data.tab 类型
   * @apiSuccess {String} data.content 内容
   * @apiSuccess {String} [data.last_reply_at] 最后回复时间
   * @apiSuccess {boolean} data.top 是否置顶
   * @apiSuccess {boolean} data.good 是否为精华帖
   * @apiSuccess {int} data.reply_count 总回复数量
   * @apiSuccess {int} data.visit_count 总浏览数量
   * @apiSuccess {Object} data.author 作者信息
   * @apiSuccess {String} data.author.id 作者id
   * @apiSuccess {String} data.author.loginname 作者登陆名
   * @apiSuccess {Object[]} [data.replies] 回复列表
   * @apiSuccess {String} data.replies.id 回复id
   * @apiSuccess {String} data.replies.author 回复的作者
   * @apiSuccess {String} data.replies.author.id 回复的作者的id
   * @apiSuccess {String} data.replies.author.loginname 回复的作者的登陆名称
   * @apiSuccess {String} data.replies.content 回复的内容
   * @apiSuccess {String[]} data.replies.ups 点赞数
   * @apiSuccess {Object} data.replies.author 回帖作者信息
   * @apiSuccess {String} data.replies.create_at 回帖时间
   * @apiSuccess {String} data.replies.author.id 作者id
   * @apiSuccess {String} data.replies.author.loginname 作者登陆名
   * @apiError 404 The <code>id</code> of the Topic was not found.
   */
  @Aop("redis")
  @GET
  @At("/topic/?")
  public Object topic(String id, @Param("mdrender") String mdrender) {
    Topic topic = dao.fetch(Topic.class, id);
    if (id == null) {
      return HttpStatusView.HTTP_404;
    }
    NutMap tp = _topic(topic, new HashMap<Integer, UserProfile>(), mdrender);

    List<NutMap> replies = new ArrayList<NutMap>();
    for (TopicReply reply :
        dao.query(TopicReply.class, Cnd.where("topicId", "=", id).asc("createTime"))) {
      dao.fetchLinks(reply, null);
      reply.setUps(jedis().zrange(RKEY_REPLY_LIKE + reply.getId(), 0, System.currentTimeMillis()));

      NutMap re = new NutMap();
      re.put("id", reply.getId());
      re.put("author", _author(reply.getAuthor()));

      re.put(
          "content",
          "false".equals(mdrender)
              ? reply.getContent()
              : Markdowns.toHtml(reply.getContent(), urlbase));
      re.put("ups", new ArrayList<String>(reply.getUps()));
      re.put("create_at", _time(reply.getCreateTime()));
      replies.add(re);
    }

    tp.put("replies", replies);

    jedis().zincrby(RKEY_TOPIC_VISIT, 1, topic.getId());
    return _map("data", tp);
  }
 @OnEvent("get_auth_qr")
 public void getAuthQr(SocketIOClient client, Object data, AckRequest ackRequest) {
   NutMap re = new NutMap();
   try {
     // TODO 可配置
     SeckenResp resp =
         secken
             .getAuth(1, "https://nutz.cn/secken/callback/" + R.UU32(client.getSessionId()))
             .check();
     String url = resp.qrcode_url();
     re.put("ok", true);
     re.put("url", url);
   } catch (Exception e) {
     log.debug("获取洋葱授权二维码识别", e);
     re.put("msg", "获取洋葱授权二维码识别");
   }
   client.sendEvent("new_auth_qr", re);
 }
Example #6
0
  @Aop("redis")
  public Object check(String topicId, int replies) {
    Topic topic = dao.fetch(Topic.class, topicId);
    if (topic == null) return "";
    Double reply_count = jedis().zscore(RKEY_REPLY_COUNT, topicId);
    if (reply_count == null) reply_count = Double.valueOf(0);
    if (reply_count.intValue() == replies) {
      return "";
    }
    String replyId = jedis().hget(RKEY_REPLY_LAST, topicId);
    TopicReply reply = dao.fetch(TopicReply.class, replyId);
    dao.fetchLinks(reply, null);

    NutMap re = new NutMap().setv("count", reply_count.intValue());
    re.put("data", reply.getAuthor().getNickname() + " 回复了帖子:" + topic.getTitle());
    re.put("options", new NutMap().setv("tag", topicId));
    return re;
  }
 public boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue)
     throws Exception {
   HttpServletRequest req = (HttpServletRequest) request;
   HttpServletResponse resp = (HttpServletResponse) response;
   if ("GET".equals(req.getMethod()) && !Strings.isBlank(req.getParameter("token"))) {
     String token = req.getParameter("token");
     try {
       token = Toolkit._3DES_decode(CrossScreen.csKEY, Toolkit.hexstr2bytearray(token));
       NutMap map = Json.fromJson(NutMap.class, token);
       Long t = map.getLong("t", -1);
       if (System.currentTimeMillis() - t > timeout * 1000) {
         resp.sendError(403); // TODO 提示token已经过期
         return false;
       }
       Integer uid = (Integer) map.get("uid");
       if (uid != null) {
         // 有登陆用户
         Toolkit.doLogin(new CrossScreenUserToken(uid), uid);
         if (sysLogService == null) {
           try {
             sysLogService = Mvcs.ctx().getDefaultIoc().get(SysLogService.class);
           } catch (Throwable e) {
           }
         }
         sysLogService.async(SysLog.c("method", "用户登陆", null, uid, "用户通过跨屏二维码登陆"));
       }
       resp.sendRedirect(map.getString("url"));
       return false;
     } catch (Exception e) {
       log.debug("bad token?", e);
       resp.sendError(502);
       return false;
     }
   } else {
     resp.sendError(403);
     return false;
   }
 }
Example #8
0
  // 微信推荐链接等信息
  private String wx_shareurl(String uri, HashMap<String, String> minfo) throws Exception {
    NutMap rowx = NutMap.NEW();

    String redirecturl = ApiConfigKit.apiConfig.getServercontext() + "/oauth.action?info=";
    String realurl =
        "/author/login/wxlogin.action?recommender="
            + minfo.get("openid"); // minfo.get("openid")就是刚点进来链接的人;
    realurl = BlueDes.encrypt(realurl);

    redirecturl += realurl;

    String url =
        String.format(OAuthAccessTokenApi.oauthurl, ApiConfigKit.apiConfig.getAppId(), redirecturl);

    System.out.println("url:" + url);
    System.out.println("redirecturl:" + redirecturl);

    return url;
  }
Example #9
0
  public NutMap wx_init(String uri, HashMap<String, String> minfo) {
    NutMap mapwx = NutMap.NEW();

    try {
      String shareurl = wx_shareurl(uri, minfo);
      NutMap jscfg = wx_jsconfig(uri);

      mapwx.put("recommender", minfo.get("recommender"));
      mapwx.put("openid", minfo.get("openid"));
      mapwx.put("shareurl", shareurl);
      mapwx.put("jscfg", jscfg);
    } catch (Exception e) {
      System.out.println(e);
    }

    return mapwx;
  }
Example #10
0
 public NutMap upload(TempFile tmp, int userId) throws IOException {
   NutMap re = new NutMap();
   if (userId < 1) return re.setv("msg", "请先登陆!");
   if (tmp == null || tmp.getSize() == 0) {
     return re.setv("msg", "空文件");
   }
   if (tmp.getSize() > 10 * 1024 * 1024) {
     tmp.delete();
     return re.setv("msg", "文件太大了");
   }
   String id = R.UU32();
   String path = "/" + id.substring(0, 2) + "/" + id.substring(2);
   File f = new File(imageDir + path);
   Files.createNewFile(f);
   Files.write(f, tmp.getInputStream());
   tmp.delete();
   re.put("url", Mvcs.getServletContext().getContextPath() + "/yvr/upload" + path);
   re.setv("success", true);
   return re;
 }
Example #11
0
 @At
 public Object add(@Param("..") User user) {
   NutMap nutMap = new NutMap();
   dao.insert(user);
   return nutMap.setv("ok", true).setv("msg", "添加用户成功");
 }
 public NutMap _topic(Topic topic, Map<Integer, UserProfile> authors, String mdrender) {
   yvrService.fillTopic(topic, authors);
   NutMap tp = new NutMap();
   tp.put("id", topic.getId());
   tp.put("author_id", "" + topic.getAuthor().getUserId());
   tp.put("tab", topic.getType().toString());
   tp.put(
       "content",
       "false".equals(mdrender)
           ? topic.getContent()
           : Markdowns.toHtml(topic.getContent(), urlbase));
   tp.put("title", StringEscapeUtils.unescapeHtml(topic.getTitle()));
   if (topic.getLastComment() != null)
     tp.put("last_reply_at", _time(topic.getLastComment().getCreateTime()));
   tp.put("good", topic.isGood());
   tp.put("top", topic.isTop());
   tp.put("reply_count", topic.getReplyCount());
   tp.put("visit_count", topic.getVisitCount());
   tp.put("create_at", _time(topic.getCreateTime()));
   UserProfile profile = topic.getAuthor();
   if (profile != null) {
     profile.setScore(yvrService.getUserScore(topic.getUserId()));
   }
   tp.put("author", _author(profile));
   return tp;
 }
 public NutMap _author(UserProfile profile) {
   NutMap author = new NutMap();
   author.setv("loginname", profile.getLoginname());
   author.setv("avatar_url", _avatar_url(profile.getLoginname()));
   return author;
 }