package cn.wise.sc.acquisition.business.util.weixin;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.client.RestTemplate;

import java.util.*;

/**
 * 对外开放接口 工具类
 */
public class WeixinInterfaceUtil {

	public static void main(String[] args){
		String param = "corpid=%s&corpsecret=%s";
		param = String.format(param, "ww348f91b2573c1867", "gFa_7XvXtCaoeAYERzjRwwz_OTJkJfgBb8weOKjmI3o");
		try {
			JSONObject jsonObject = WeixinInterfaceUtil.doGet(Global.ACCESSTOKENURL, param);
			String accessToken = jsonObject.getString("access_token");
			System.out.println("accessToken" + accessToken);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static JSONObject doGet(String url, String param) {
		String path= url+"?"+ param;
		RestTemplate restTemplate = new RestTemplate();
		JSONObject resultMap = restTemplate.getForObject(path,JSONObject.class);
		return resultMap;
	}


}
