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); + } + } +}