package org.jeecg.api.untils;

import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.jeecg.common.exception.JeecgBootException;
import org.springframework.stereotype.Component;

@Component
public class HttpConf {


    /**
     * 微信授权登录工具类
     * @param url
     * @return
     */
    public JSONObject getJSONObject(String url){
        String jsonObjectStr = null;
        try {
            CloseableHttpClient client = null;
            CloseableHttpResponse response = null;
            HttpGet httpGet = new HttpGet(url);
            client = HttpClients.createDefault();
            response = client.execute(httpGet);
            HttpEntity entity = response.getEntity();
            jsonObjectStr = EntityUtils.toString(entity);
        } catch (Exception e) {
            throw new JeecgBootException("授权失败，请稍后重试");
        }
        JSONObject jsonObject = JSONObject.parseObject(jsonObjectStr);
        return jsonObject;
    }

}

