From 4ab69a8887c73378021a66e5290fbd2a948c38be Mon Sep 17 00:00:00 2001 From: chaiyapeng <3535863041@qq.com> Date: Sat, 24 Aug 2024 18:45:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E9=97=BB=E5=A4=B4=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mart/service/impl/MarketServiceImpl.java | 27 ++--------- .../com/muyu/cloud/mart/utils/Headlines.java | 47 +++++++++++++++++++ 2 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 cloud-mart-server/src/main/java/com/muyu/cloud/mart/utils/Headlines.java diff --git a/cloud-mart-server/src/main/java/com/muyu/cloud/mart/service/impl/MarketServiceImpl.java b/cloud-mart-server/src/main/java/com/muyu/cloud/mart/service/impl/MarketServiceImpl.java index aad5f6f..5b81221 100644 --- a/cloud-mart-server/src/main/java/com/muyu/cloud/mart/service/impl/MarketServiceImpl.java +++ b/cloud-mart-server/src/main/java/com/muyu/cloud/mart/service/impl/MarketServiceImpl.java @@ -3,6 +3,7 @@ package com.muyu.cloud.mart.service.impl; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muyu.cloud.mart.utils.Headlines; import com.muyu.cloud.mart.utils.IPLocation; import com.muyu.cloud.mart.utils.MobileLocation; import com.muyu.cloud.mart.mapper.MarketMapper; @@ -87,29 +88,7 @@ public class MarketServiceImpl extends ServiceImpl impleme */ @Override public Result getHeadlines() { - String apiKey = "cdbb93769c75054e6beda4c1dc0b6a0b"; - String apiUrl = "http://v.juhe.cn/toutiao/index"; - - HashMap map = new HashMap<>(); - map.put("key", apiKey); - map.put("type", "top"); - map.put("page", "20"); - map.put("page_size", ""); - map.put("is_filter", ""); - System.out.println("111"); - try { - URL url = new URL(String.format(apiUrl + "?" + params(map))); - BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream())); - String inputLine; - StringBuffer response = new StringBuffer(); - while ((inputLine = in.readLine()) != null) { - response.append(inputLine); - } - in.close(); - System.out.println(response); - return Result.success(response); - } catch (Exception e) { - throw new RuntimeException(e); - } + StringBuffer stringBuffer = Headlines.queryMobileLocation(); + return Result.success(stringBuffer); } } diff --git a/cloud-mart-server/src/main/java/com/muyu/cloud/mart/utils/Headlines.java b/cloud-mart-server/src/main/java/com/muyu/cloud/mart/utils/Headlines.java new file mode 100644 index 0000000..e6718bc --- /dev/null +++ b/cloud-mart-server/src/main/java/com/muyu/cloud/mart/utils/Headlines.java @@ -0,0 +1,47 @@ +package com.muyu.cloud.mart.utils; + +import com.muyu.common.core.domain.Result; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.HashMap; + +import static com.muyu.cloud.mart.config.IPLocation.params; + +/** + * @Author:chaiyapeng + * @Package:com.muyu.cloud.mart.utils + * @Project:cloud-mart + * @name:Headlines + * @Date:2024/8/24 18:39 + */ +public class Headlines { + + public static StringBuffer queryMobileLocation(){ + String apiKey = "cdbb93769c75054e6beda4c1dc0b6a0b"; + String apiUrl = "http://v.juhe.cn/toutiao/index"; + + HashMap map = new HashMap<>(); + map.put("key", apiKey); + map.put("type", "top"); + map.put("page", "20"); + map.put("page_size", ""); + map.put("is_filter", ""); + System.out.println("111"); + try { + URL url = new URL(String.format(apiUrl + "?" + params(map))); + BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream())); + String inputLine; + StringBuffer response = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + System.out.println(response); + return response; + } catch (Exception e) { + throw new RuntimeException(e); + } + } +}