// 获取第三方平台accesstoken //synchronized public JSONObject getAccessToken(WxPublicpartyControl wppc) { WePublicparty wpp = wppc.getWePublicparty(); JSONObject accesstokeninfo = new JSONObject(); JSONObject param = new JSONObject(); if (wpp == null || nds.util.Validator.isNull(wpp.getAppid()) || nds.util.Validator.isNull(wpp.getAppsecret())) { logger.debug("WePublicparty error->"); return accesstokeninfo; } try { param.put("component_appid", wpp.getAppid()); param.put("component_appsecret", wpp.getAppsecret()); param.put("component_verify_ticket", wpp.getComponent_verify_ticket()); } catch (Exception e) { } ValueHolder vh = null; logger.debug("get publicparty access token"); try { vh = RestUtils.sendRequest_buff(weixingetpublicpartyaccesstoken, param.toString(), "POST"); String result = (String) vh.get("message"); logger.debug("get publicparty access token result->" + result); JSONObject tjo = new JSONObject(result); String returns = "获取授权码失败!"; if (tjo != null && tjo.has("component_access_token")) { accesstokeninfo.put("code", 0); accesstokeninfo.put("message", "获取成功"); accesstokeninfo.put("data", tjo); } else { accesstokeninfo.put("code", -1); accesstokeninfo.put("message", returns); } } catch (Exception e) { logger.debug("get publicparty access token error->" + e.getLocalizedMessage()); e.printStackTrace(); try { accesstokeninfo.put("code", -1); accesstokeninfo.put("message", "获取授权码失败!"); } catch (JSONException e1) { } } return accesstokeninfo; }
/** * Get viewable subsystem list * * @param request * @return never null, elements are nds.schema.SubSystem */ public List getSubSystems(HttpServletRequest request) { UserWebImpl userWeb = ((UserWebImpl) WebUtils.getSessionContextManager(request.getSession()) .getActor(nds.util.WebKeys.USER)); ArrayList subs = new ArrayList(); if (userWeb.getUserId() == userWeb.GUEST_ID) { return subs; } List al = (List) userWeb.getProperty("subsystems"); // elements are subystem.id TableManager manager = TableManager.getInstance(); if (al != null) { for (int i = 0; i < al.size(); i++) { int sid = ((Integer) al.get(i)).intValue(); SubSystem ss = manager.getSubSystem(sid); if (ss != null) subs.add(ss); } } else { // search all tablecategoris for subsystem // add users subsystems param al = new ArrayList(); String[] sub_list; try { String subsystems = (String) QueryEngine.getInstance() .doQueryOne("SELECT subsystems from users where id=" + userWeb.getUserId()); if (Validator.isNotNull(subsystems)) { sub_list = subsystems.split(","); for (int m = 0; m < sub_list.length; m++) { SubSystem usersub = manager.getSubSystem(sub_list[m].trim()); if (usersub != null) { if (usersub.getId() == 10) continue; al.add(new Integer(usersub.getId())); subs.add(usersub); } } userWeb.setProperty("subsystems", al); return subs; } } catch (QueryException e) { logger.error("Fail to load subsystems from users", e); } for (int i = 0; i < manager.getSubSystems().size(); i++) { SubSystem ss = (SubSystem) manager.getSubSystems().get(i); if (containsViewableChildren(request, ss)) { al.add(new Integer(ss.getId())); subs.add(ss); } } userWeb.setProperty("subsystems", al); } return subs; }
@Override public ValueHolder execute(DefaultWebEvent event) throws NDSException, RemoteException { ValueHolder vh = new ValueHolder(); User user = this.helper.getOperator(event); if (user == null) { logger.debug("publish menu error->user logout"); vh.put("code", "-1"); vh.put("message", "用户不存在,请重新登陆->"); return vh; } JSONObject jo = (JSONObject) event.getParameterValue("jsonObject"); try { jo = new JSONObject(jo.optString("params")); } catch (Exception e) { logger.debug("get params error->" + e.getLocalizedMessage()); e.printStackTrace(); } // 获取与接口相关的信息对象 WeUtils wu = WeUtilsManager.getByAdClientId(user.adClientId); if (wu == null) { logger.debug( "massreply error->not find WeUtils WeUtilsManager.getByAdClientId(" + user.adClientId + ")"); vh.put("code", "-1"); vh.put("message", "请到菜单【微信】的【微信接口配置】中设置APPID与APPSECRET并点击【刷新APP】按钮"); return vh; } // 判断APPID与APPSECRET是否为空 if (nds.util.Validator.isNull(wu.getAppId())) { logger.debug( "massreply error->appid or appsecret is null[appid:" + wu.getAppId() + "][appsecret:" + wu.getAppSecret() + "]"); vh.put("code", "-1"); vh.put("message", "请到菜单【微信】的【微信接口配置】中设置APPID与APPSECRET并点击【刷新APP】按钮"); return vh; } WxPublicControl wc = WxPublicControl.getInstance(wu.getAppId()); if (wc == null) { logger.debug( "massreply error->not find WeControl WeControl.getInstance(" + wu.getAppId() + ")"); vh.put("code", "-1"); vh.put("message", "请到菜单【微信】的【微信接口配置】中设置APPID与APPSECRET并点击【刷新APP】按钮"); return vh; } logger.debug("getAllMaterial"); // 素材类型 String type = jo.optString("type"); // "news" WeBatchGetMaterial bgm = WeBatchGetMaterial.getInstance(wu.getAppId()); JSONObject tempjo = null; try { tempjo = bgm.getAllMaterials(wc, user, type); if (tempjo != null) { vh.put("code", tempjo.optInt("code", -1)); vh.put("message", tempjo.optString("message")); } else { vh.put("code", "-1"); vh.put("message", "获取素材列表异常!"); } } catch (Exception e) { vh.put("code", "-1"); vh.put("message", wu.getAppId() + " getMaterial error2->" + e.toString()); e.printStackTrace(); } return vh; }
/** * @param request * @param permissionType PERMISSION_VIEWABLE, PERMISSION_NO_PERM or PERMISSION_NO_LICENSE * @return never null, elements are nds.schema.SubSystem */ public List<SubSystem> getSubSystems(HttpServletRequest request, int permissionType) throws Exception { if (permissionType == PERMISSION_VIEWABLE) return getSubSystems(request); UserWebImpl userWeb = ((UserWebImpl) WebUtils.getSessionContextManager(request.getSession()) .getActor(nds.util.WebKeys.USER)); String subsystems = (String) QueryEngine.getInstance() .doQueryOne("SELECT subsystems from users where id=" + userWeb.getUserId()); if (Validator.isNotNull(subsystems)) { return Collections.EMPTY_LIST; } TableManager manager = TableManager.getInstance(); if (permissionType == PERMISSION_NO_PERM) { ArrayList subs = new ArrayList(); List al = (List) userWeb.getProperty("subsystems"); // elements are subystem.id if (al == null) { getSubSystems(request); al = (List) userWeb.getProperty("subsystems"); } // no perm List ss = manager.getSubSystems(); for (int i = 0; i < ss.size(); i++) { SubSystem sa = (SubSystem) ss.get(i); boolean found = false; for (int j = 0; j < al.size(); j++) { if (((Integer) al.get(j)).intValue() == sa.getId()) { found = true; break; } } if (!found) subs.add(sa); } return subs; } // else{ // no license if (subSystemNoLicense == null) { subSystemNoLicense = new ArrayList<SubSystem>(); List al = QueryEngine.getInstance() .doQueryList( "select id, name, orderno, iconurl,url from ad_subsystem s where exists(select 1 from ad_tablecategory c where c.ad_subsystem_id=s.id) order by orderno asc"); for (int i = 0; i < al.size(); i++) { List als = (List) al.get(i); if (manager.getSubSystem(Tools.getInt(als.get(0), -1)) == null) { SubSystem ss = new SubSystem(); ss.setId(Tools.getInt(als.get(0), -1)); ss.setName((String) als.get(1)); ss.setOrderno(Tools.getInt(als.get(2), -1)); ss.setIconURL((String) als.get(3)); ss.setPageURL((String) als.get(4)); subSystemNoLicense.add(ss); } } } return subSystemNoLicense; // } }