package com.zhiwei.manage.util;

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

import net.sf.json.JSONObject;

public class JsonToObject {

	public static String getToken() {
		String token="";
		String appId="wxd1f40dde7e15845f";
		String jmAppId=AESUtils.encrypt("wechat", appId);
		String path = "http://test.zhiweidata.com/WechatPublic/common/getToken?appId="+jmAppId;
		BufferedReader in = null;
		try {
			String result = "";
			URL url = new URL(path);
			URLConnection connection = url.openConnection();
			connection.setConnectTimeout(3000);
			connection.connect();
			in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
			String line;
			while ((line = in.readLine()) != null) {
				result += line;
			}
			JSONObject jsonObject = JSONObject.fromObject(result);
			JSONObject inJson = JSONObject.fromObject(jsonObject.getString("data"));
			token=inJson.getString("accessToken");
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return token;
	}
	
}
