package com.cnd3b.utility.qywechat.tools;

import com.cnd3b.utility.qywechat.base.GetAccessToken;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class Department {
	public static void main (String agrs[]){
		Department department = new Department();
		try {
			department.getDepartment();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public String getDepartment() throws IOException {
		URL url = new URL(
				"https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token="
						+ GetAccessToken.get() + "&id=null");
		URLConnection connection = url.openConnection();
		// 获取媒体文件上传的输入流（从微信服务器读数据）
		BufferedReader in = new BufferedReader(new InputStreamReader(
				connection.getInputStream()));
		StringBuffer content = new StringBuffer();
		String line = null;
		while ((line = in.readLine()) != null) {
			content.append(line);
		}
		in.close();
		// 测试打印结果
		return content.toString();
	}
}
