//调用微信接口
//appid:公众号appid
//secret:公众号appid密钥
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx039fa5e93cf51b8e&secret=e2fa4c2a05ce99575e6c139a5c37de1c";
JSONObject jsonObject = doGetStr(url);
//accesstoken 值
accessToken = jsonObject .getString("access_token");
/**
* Http Get 请求方法
* @param url
* @return
* @throws Exception
*/
public static JSONObject doGet(String url) throws Exception {
JSONObject json = null;
HttpGet httpGet = new HttpGet(url);
// 创建httpClientBuilder
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
// httpclient
CloseableHttpClient httpClient = clientBuilder.build();
try {
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
String result = EntityUtils.toString(entity, "UTF-8");
json = JSONObject.fromObject(result);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
logger.error(e.getMessage());
throw new RecruitException(ErrorsInfo.ERR00001, "HttpClient 请求异常", "HttpClient 请求异常,请检查日志!");
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage());
throw new RecruitException(ErrorsInfo.ERR00002, "IO 读取异常", "IO 读取异常,请检查日志!");
}
return json;
}