package com.zhiweidata.bjfzxWebapp.util;

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

import com.alibaba.fastjson.JSONObject;


public class WechatCodeUtil {
	
	public static String getToken() {
		String token="";
		String appId="wxd1f40dde7e15845f";
		String jmAppId=AESUtils.encrypt("wechat", appId);
		String path = "http://yuqing.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();
			// 定义 BufferedReader输入流来读取URL的响应
			in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
			String line;
			while ((line = in.readLine()) != null) {
				result += line;
			}
			JSONObject jsonObject = JSONObject.parseObject(result);
			JSONObject inJson = JSONObject.parseObject(jsonObject.getString("data"));
			token=inJson.getString("accessToken");
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return token;
	}

}
