新闻头条

pull/1/head
chaiyapeng 2024-08-24 18:45:58 +08:00
parent 92f0018697
commit 4ab69a8887
2 changed files with 50 additions and 24 deletions

View File

@ -3,6 +3,7 @@ package com.muyu.cloud.mart.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 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.IPLocation;
import com.muyu.cloud.mart.utils.MobileLocation; import com.muyu.cloud.mart.utils.MobileLocation;
import com.muyu.cloud.mart.mapper.MarketMapper; import com.muyu.cloud.mart.mapper.MarketMapper;
@ -87,29 +88,7 @@ public class MarketServiceImpl extends ServiceImpl<MarketMapper, Market> impleme
*/ */
@Override @Override
public Result getHeadlines() { public Result getHeadlines() {
String apiKey = "cdbb93769c75054e6beda4c1dc0b6a0b"; StringBuffer stringBuffer = Headlines.queryMobileLocation();
String apiUrl = "http://v.juhe.cn/toutiao/index"; return Result.success(stringBuffer);
HashMap<String, String> 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);
}
} }
} }

View File

@ -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;
/**
* @Authorchaiyapeng
* @Packagecom.muyu.cloud.mart.utils
* @Projectcloud-mart
* @nameHeadlines
* @Date2024/8/24 18:39
*/
public class Headlines {
public static StringBuffer queryMobileLocation(){
String apiKey = "cdbb93769c75054e6beda4c1dc0b6a0b";
String apiUrl = "http://v.juhe.cn/toutiao/index";
HashMap<String, String> 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);
}
}
}