微信企业号之获取所有部门列表

测试代码

public static void listGroup(){
        List<GroupEntry> list=groupManager.getGroupList();
        for(GroupEntry entry:list){
            System.out.println(entry.getPrintString());
        }
    }

关键代码

/**
     * 取得部门列表
    * @param     
    * @return void   
    * @throws
     */
    public List<GroupEntry> getGroupList(){
        String getUrl=GroupUrls.GET_GROUP_LIST_URL+accessToken;
        String respStr=HttpUtil.getJson(getUrl);

        Map<String,Object> map=new HashMap<String,Object>();
        map.put(DEPARTMENT_FILED,GroupEntry.class);
        JSONObject object = JSONObject.fromObject(respStr);
        DepartmentEntry department=JsonPluginsUtil.jsonToBean(object.toString(), DepartmentEntry.class,map);
        if(department!=null && Constants.ErrCode.OK.equals(department.getErrcode())){
            return department.getDepartment();
        }
        return null;
    }

获取结果json

{"errcode":0,"errmsg":"ok","department":[{"id":2,"name":"影视大部门","parentid":1,"order":200},{"id":10,"name":"绿箭虾组","parentid":2,"order":10},{"id":11,"name":"吸血鬼组","parentid":2,"order":11},{"id":13,"name":"闪电虾组","parentid":2,"order":13},{"id":762146108,"name":"妇联组","parentid":2,"order":762146108}]}

打印结果

2--影视大部门
10--绿箭虾组
11--吸血鬼组
13--闪电虾组
762146108--妇联组
阅读更多

没有更多推荐了,返回首页