From 8f5cd72dea41a9e0f4e4fecf5f19e68e9f228401 Mon Sep 17 00:00:00 2001 From: xyiege Date: Fri, 16 Sep 2022 15:18:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3get=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../szwh/service/impl/GoodsServiceImpl.java | 163 +++++++++--------- .../szwh/service/impl/LoginServiceImpl.java | 2 +- .../szwh/service/impl/UserServiceImpl.java | 2 +- .../cn/chjyj/szwh/utils/RequestUtils.java | 18 +- .../cn/chjyj/szwh/utils/SzwhApiUtils.java | 6 +- src/test/java/cn/chjyj/szwh/ApiTest.java | 2 +- 6 files changed, 99 insertions(+), 94 deletions(-) diff --git a/src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java b/src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java index 1401dc1..d7ac127 100644 --- a/src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java +++ b/src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java @@ -84,95 +84,96 @@ public class GoodsServiceImpl implements GoodsService { Map hmap = new HashMap(); hmap.put("entrust_token", sign); // get 方式获取 - JSONObject jsonObject = RequestUtils.GetData(apiurl, hmap); - // json的data节点 - JSONArray jsonArray = jsonObject.getJSONArray("data"); + JSONObject jsonObject = RequestUtils.GetData(apiurl, hmap,true); // 产品详情地址 String gdurl = host + "/consign/exchange/v1/selectEntrustDetails"; // 循环查询商品的详情 - for(int i=0;i map){ + public static JSONObject GetData(String surl, Map map,boolean wflag){ JSONObject jsonObject = new JSONObject(); try{ URL url = new URL(surl); @@ -51,13 +52,16 @@ public class RequestUtils { InputStream inputStream = httpcon.getInputStream(); //请求结果写入 String filename =String.valueOf(Calendar.getInstance().getTimeInMillis()); - SzFileUtils.createFile(inputStream,filename); - //字节转为utf-8 - String message=SzFileUtils.readJson(filename); - if(message!=null){ - jsonObject = JSONObject.parseObject(message); + if(wflag){ + SzFileUtils.createFile(inputStream,filename); + //字节转为utf-8 + String message=SzFileUtils.readJson(filename); + if(message!=null){ + jsonObject = JSONObject.parseObject(message); + logger.info("respone message :"+message); + } + logger.info("respone message is null"); } - logger.info("respone message :"+message); }catch (IOException ex){ // 罗列出明细错误 logger.error("请求错误:"+ex); diff --git a/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java b/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java index 718e2be..145cc52 100644 --- a/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java +++ b/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java @@ -37,7 +37,7 @@ public class SzwhApiUtils { hmap.put("token",sign); hmap.put("Content-Type","application/json"); //执行请求 - JSONObject json = RequestUtils.GetData(userUrl,hmap); + JSONObject json = RequestUtils.GetData(userUrl,hmap,false); log.info("request result:"+json); return json; } @@ -78,7 +78,7 @@ public class SzwhApiUtils { System.out.println("token :"+sign); Map hmap = new HashMap(); hmap.put("entrust_token",sign); - JSONObject json = RequestUtils.GetData(url,hmap); + JSONObject json = RequestUtils.GetData(url,hmap,false); return json; } @@ -94,7 +94,7 @@ public class SzwhApiUtils { String sign=SignUtils.createSign("entrust"); Map hmap = new HashMap(); hmap.put("entrust_token",sign); - JSONObject json = RequestUtils.GetData(url,hmap); + JSONObject json = RequestUtils.GetData(url,hmap,true); return json; } /** diff --git a/src/test/java/cn/chjyj/szwh/ApiTest.java b/src/test/java/cn/chjyj/szwh/ApiTest.java index 322621c..8957a5d 100644 --- a/src/test/java/cn/chjyj/szwh/ApiTest.java +++ b/src/test/java/cn/chjyj/szwh/ApiTest.java @@ -64,7 +64,7 @@ public class ApiTest { // 请求头 Map hmap = new HashMap(); hmap.put("entrust_token", sign); - JSONObject jsonObject = RequestUtils.GetData(url, hmap); + JSONObject jsonObject = RequestUtils.GetData(url, hmap,true); // 抽取data // String data = jsonObject.getString("data"); JSONArray jsonArray = jsonObject.getJSONArray("data");