generated from root/miduo_server
修改 请求方式
parent
d9a5ad3b0b
commit
0f7606efd3
|
@ -20,7 +20,7 @@ public class KTGetUserOpenIdController extends HttpServlet {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(KTGetUserOpenIdController.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(KTGetUserOpenIdController.class);
|
||||||
|
|
||||||
public static String login_url = "http://api.kt007.com/api/v1/verify/user";
|
public static String login_url = "http://api.kt007.com/api/v1/verify/user?";
|
||||||
public static String appkey = "vNCn3fkgZHt6wxGYl9IQUJo0R4LKPjW2";
|
public static String appkey = "vNCn3fkgZHt6wxGYl9IQUJo0R4LKPjW2";
|
||||||
|
|
||||||
public KTGetUserOpenIdController() {
|
public KTGetUserOpenIdController() {
|
||||||
|
@ -41,8 +41,6 @@ public class KTGetUserOpenIdController extends HttpServlet {
|
||||||
}
|
}
|
||||||
String gid = request.getParameter("gid"); //gid
|
String gid = request.getParameter("gid"); //gid
|
||||||
String pid = request.getParameter("pid"); //pid
|
String pid = request.getParameter("pid"); //pid
|
||||||
// String tm = request.getParameter("tm"); //tm
|
|
||||||
// String sign = request.getParameter("sign"); //sign
|
|
||||||
String tm = Long.toString(System.currentTimeMillis() / 1000);
|
String tm = Long.toString(System.currentTimeMillis() / 1000);
|
||||||
LOGGER.info("the token = {},gid={},pid={} tm=>{}", token, gid, pid, tm);
|
LOGGER.info("the token = {},gid={},pid={} tm=>{}", token, gid, pid, tm);
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
@ -70,8 +68,19 @@ public class KTGetUserOpenIdController extends HttpServlet {
|
||||||
sbKey.append(appkey);
|
sbKey.append(appkey);
|
||||||
String mySign = MD5Util.encrypByMd5(sbKey.toString());
|
String mySign = MD5Util.encrypByMd5(sbKey.toString());
|
||||||
params.put("sign", mySign);
|
params.put("sign", mySign);
|
||||||
String loginResult = HttpUtils.doPost(login_url,params);
|
StringBuilder httpUrl = new StringBuilder();
|
||||||
|
httpUrl.append(login_url).append("gid").append("=").append(gid).append("&")
|
||||||
|
.append("pid").append("=").append(pid).append("&")
|
||||||
|
.append("tm").append("=").append(tm).append("&")
|
||||||
|
.append("access_token").append("=").append(tm).append(token)
|
||||||
|
.append("sign").append("=").append(mySign);
|
||||||
|
LOGGER.info("KTGetUserOpenIdController request={}", httpUrl.toString());
|
||||||
|
String loginResult = HttpUtils.httpRequest(httpUrl.toString());
|
||||||
LOGGER.info("KTGetUserOpenIdController 加密前={} 加密后={} 请求结果={}", sbKey.toString(), mySign, loginResult);
|
LOGGER.info("KTGetUserOpenIdController 加密前={} 加密后={} 请求结果={}", sbKey.toString(), mySign, loginResult);
|
||||||
|
if (loginResult == null || loginResult.isEmpty()) {
|
||||||
|
returnErrorToFront(res, response, "token is empty");
|
||||||
|
return;
|
||||||
|
}
|
||||||
JSONObject jsonObject = JSONObject.parseObject(loginResult);
|
JSONObject jsonObject = JSONObject.parseObject(loginResult);
|
||||||
int state = jsonObject.getIntValue("code");
|
int state = jsonObject.getIntValue("code");
|
||||||
if (state == 200) {
|
if (state == 200) {
|
||||||
|
|
|
@ -10,7 +10,13 @@ import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -42,4 +48,63 @@ public class HttpUtils {
|
||||||
}
|
}
|
||||||
return nvps;
|
return nvps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String httpRequest(String httpUrl){
|
||||||
|
HttpURLConnection connection = null;
|
||||||
|
InputStream is = null;
|
||||||
|
BufferedReader br = null;
|
||||||
|
String result = null;// 返回结果字符串
|
||||||
|
try {
|
||||||
|
// 创建远程url连接对象
|
||||||
|
URL url = new URL(httpUrl);
|
||||||
|
// 通过远程url连接对象打开一个连接,强转成httpURLConnection类
|
||||||
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
|
// 设置连接方式:get
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
// 设置连接主机服务器的超时时间:15000毫秒
|
||||||
|
connection.setConnectTimeout(15000);
|
||||||
|
// 设置读取远程返回的数据时间:60000毫秒
|
||||||
|
connection.setReadTimeout(60000);
|
||||||
|
// 发送请求
|
||||||
|
connection.connect();
|
||||||
|
// 通过connection连接,获取输入流
|
||||||
|
if (connection.getResponseCode() == 200) {
|
||||||
|
is = connection.getInputStream();
|
||||||
|
// 封装输入流is,并指定字符集
|
||||||
|
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||||
|
// 存放数据
|
||||||
|
StringBuffer sbf = new StringBuffer();
|
||||||
|
String temp = null;
|
||||||
|
while ((temp = br.readLine()) != null) {
|
||||||
|
sbf.append(temp);
|
||||||
|
sbf.append("\r\n");
|
||||||
|
}
|
||||||
|
result = sbf.toString();
|
||||||
|
}
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
// 关闭资源
|
||||||
|
if (null != br) {
|
||||||
|
try {
|
||||||
|
br.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null != is) {
|
||||||
|
try {
|
||||||
|
is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connection.disconnect();// 关闭远程连接
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue