新闻头条
parent
92f0018697
commit
4ab69a8887
|
@ -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<MarketMapper, Market> impleme
|
|||
*/
|
||||
@Override
|
||||
public Result getHeadlines() {
|
||||
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 Result.success(response);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
StringBuffer stringBuffer = Headlines.queryMobileLocation();
|
||||
return Result.success(stringBuffer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue