for (String str : array){
if(str.indexOf("access_token") >= 0){
token = str.substring(str.indexOf("=") + 1);
break;
}
}
}
}
httpGet.releaseConnection();
return token;
}
public static String getOpenID(String url) throws IOException {
JSONObject jsonObject = null;
CloseableHttpClient client = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(url);
HttpResponse response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
if(entity != null){
String result = EntityUtils.toString(entity,"UTF-8");
jsonObject = parseJSONP(result);
}
httpGet.releaseConnection();
if(jsonObject != null){
return jsonObject.getString("openid");
}else {
return null;

}
}
public static JSONObject getUserInfo(String url) throws IOException {
JSONObject jsonObject = null;
CloseableHttpClient client = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(url);
HttpResponse response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
if(entity != null){
String result = EntityUtils.toString(entity,"UTF-8");
jsonObject = JSONObject.parseObject(result);
}
httpGet.releaseConnection();
return jsonObject;
}
}
index.html
<!DOCTYPE html>
<html lang="en" xmlns:th=";>
<head>
<meta charset="UTF-8">
<title>登录页</title>
</head>
<body>
<a href="/qq/oauth">QQ授权登录</a>
</body>
</html>
home.html
<!DOCTYPE html>
<html lang="en" xmlns:th=";>
<head>
<meta charset="UTF-8">
<title>QQ授权成功</title>
</head>
<body>
<div>
openid:[[${openid}]]
</div>
<div>
nickName:[[${nickname}]]
</div>
<div>
<img th:src="${figureurl_qq_2}">
</div>
</body>
</html>
---------------------
作者:有酒醉三生丶
原文:
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/sanxing/article-120738-2.html
省下的钱足够养得起军队了