diff --git a/src/main/java/com/ljsd/service/QuickVerifyService3.java b/src/main/java/com/ljsd/service/QuickVerifyService3.java index 6cd525a..1c305d2 100644 --- a/src/main/java/com/ljsd/service/QuickVerifyService3.java +++ b/src/main/java/com/ljsd/service/QuickVerifyService3.java @@ -146,8 +146,6 @@ public class QuickVerifyService3 extends AbstractVerifyService { } boolean doVerifyIos(VerifyParams params, String url) { - LOGGER.info("疯体 Ohayoo 登录验证-->{}",params.getOpenId()); - HashMap map = new HashMap<>(); map.put("app_id",params.getProductCode()); map.put("token",params.getToken()); @@ -156,8 +154,9 @@ public class QuickVerifyService3 extends AbstractVerifyService { boolean result = false; String r = null; try { + LOGGER.info("疯体 Ohayoo 登录验证-->{}",JSONObject.toJSONString(map)); r = HttpUtils.doPost2(url, JSONObject.toJSONString(map)); - LOGGER.info("疯体 Ohayoo 请求结果:{}",r); + LOGGER.info("疯体 Ohayoo 请求结果-->{}",r); JSONObject resultJson = JSON.parseObject(r); int status = resultJson.getIntValue("status"); if(status == 0){ diff --git a/src/main/java/com/ljsd/util/HttpUtils.java b/src/main/java/com/ljsd/util/HttpUtils.java index 16aabda..4c8650b 100644 --- a/src/main/java/com/ljsd/util/HttpUtils.java +++ b/src/main/java/com/ljsd/util/HttpUtils.java @@ -41,43 +41,21 @@ public class HttpUtils { } public static String doPost2(String url, String json) throws IOException { - PrintWriter out = null; - String result = ""; + CloseableHttpClient httpclient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(url); + StringEntity stringEntity = new StringEntity(json,ContentType.APPLICATION_FORM_URLENCODED); + httpPost.setEntity(stringEntity); + CloseableHttpResponse response2 = httpclient.execute(httpPost); + try { - URL realUrl = new URL(url); - // 打开和URL之间的连接 - URLConnection conn = realUrl.openConnection(); - // 设置通用的请求属性 - conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - // 发送POST请求必须设置如下两行 - conn.setDoOutput(true); - conn.setDoInput(true); - // 获取URLConnection对象对应的输出流 - out = new PrintWriter(conn.getOutputStream()); - // 发送请求参数 - out.print(json); - // flush输出流的缓冲 - out.flush(); - // 获取请求返回的数据流 - InputStream is = conn.getInputStream(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - // 封装输入流is,并指定字符集 - int i; - while ((i = is.read()) != -1) { - baos.write(i); - } - return baos.toString(); - } catch (Exception e) { - System.out.println("发送 POST 请求出现异常!" + e); + HttpEntity entity = response2.getEntity(); + return EntityUtils.toString(entity); + } catch (IOException e) { e.printStackTrace(); + return null; + } finally { + response2.close(); } - // 使用finally块来关闭输出流、输入流 - finally { - if (out != null) { - out.close(); - } - } - return result; } public static List getFromMap(Map parms){