package com.ruoyi.applet.utils.wechat;

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.springframework.stereotype.Component;

@Component
public class WechatHttpConf {

    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 RuntimeException("服务繁忙，稍后再试");
        }
        JSONObject jsonObject = JSONObject.parseObject(jsonObjectStr);
        return jsonObject;
    }


}
