气象预警
parent
4ab69a8887
commit
ef47644c0b
|
@ -65,5 +65,12 @@ public class MarketController extends BaseController {
|
||||||
public Result getHeadlines(){
|
public Result getHeadlines(){
|
||||||
return marketService.getHeadlines();
|
return marketService.getHeadlines();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 气象预警
|
||||||
|
*/
|
||||||
|
@GetMapping("getWeather")
|
||||||
|
public Result getWeather(){
|
||||||
|
return marketService.getWeather();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,4 +21,6 @@ public interface MarketService extends IService<Market> {
|
||||||
Result getIpPlace(String ip);
|
Result getIpPlace(String ip);
|
||||||
|
|
||||||
Result getHeadlines();
|
Result getHeadlines();
|
||||||
|
|
||||||
|
Result getWeather();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ 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;
|
||||||
import com.muyu.cloud.mart.service.MarketService;
|
import com.muyu.cloud.mart.service.MarketService;
|
||||||
|
import com.muyu.cloud.mart.utils.Weather;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.domain.Market;
|
import com.muyu.domain.Market;
|
||||||
import com.muyu.domain.PhonePlace;
|
import com.muyu.domain.PhonePlace;
|
||||||
|
@ -79,7 +80,7 @@ public class MarketServiceImpl extends ServiceImpl<MarketMapper, Market> impleme
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result getIpPlace(String ip) {
|
public Result getIpPlace(String ip) {
|
||||||
StringBuffer stringBuffer = IPLocation.queryMobileLocation(ip);
|
StringBuffer stringBuffer = IPLocation.queryIPLocation(ip);
|
||||||
return Result.success(stringBuffer);
|
return Result.success(stringBuffer);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -88,7 +89,13 @@ public class MarketServiceImpl extends ServiceImpl<MarketMapper, Market> impleme
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result getHeadlines() {
|
public Result getHeadlines() {
|
||||||
StringBuffer stringBuffer = Headlines.queryMobileLocation();
|
StringBuffer stringBuffer = Headlines.queryHeadlines();
|
||||||
|
return Result.success(stringBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result getWeather() {
|
||||||
|
StringBuffer stringBuffer = Weather.queryWeather();
|
||||||
return Result.success(stringBuffer);
|
return Result.success(stringBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import static com.muyu.cloud.mart.config.IPLocation.params;
|
||||||
*/
|
*/
|
||||||
public class Headlines {
|
public class Headlines {
|
||||||
|
|
||||||
public static StringBuffer queryMobileLocation(){
|
public static StringBuffer queryHeadlines(){
|
||||||
String apiKey = "cdbb93769c75054e6beda4c1dc0b6a0b";
|
String apiKey = "cdbb93769c75054e6beda4c1dc0b6a0b";
|
||||||
String apiUrl = "http://v.juhe.cn/toutiao/index";
|
String apiUrl = "http://v.juhe.cn/toutiao/index";
|
||||||
|
|
||||||
|
@ -28,7 +28,6 @@ public class Headlines {
|
||||||
map.put("page", "20");
|
map.put("page", "20");
|
||||||
map.put("page_size", "");
|
map.put("page_size", "");
|
||||||
map.put("is_filter", "");
|
map.put("is_filter", "");
|
||||||
System.out.println("111");
|
|
||||||
try {
|
try {
|
||||||
URL url = new URL(String.format(apiUrl + "?" + params(map)));
|
URL url = new URL(String.format(apiUrl + "?" + params(map)));
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
|
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
|
||||||
|
|
|
@ -17,7 +17,7 @@ import java.util.stream.Collectors;
|
||||||
* @Date:2024/8/23 20:54
|
* @Date:2024/8/23 20:54
|
||||||
*/
|
*/
|
||||||
public class IPLocation {
|
public class IPLocation {
|
||||||
public static StringBuffer queryMobileLocation(String ip){
|
public static StringBuffer queryIPLocation(String ip){
|
||||||
String apiKey = "e84b7d13a9fb87b4ebcc9813e4518955";
|
String apiKey = "e84b7d13a9fb87b4ebcc9813e4518955";
|
||||||
String apiUrl = "http://apis.juhe.cn/ip/ipNewV3";
|
String apiUrl = "http://apis.juhe.cn/ip/ipNewV3";
|
||||||
HashMap<String, String> map = new HashMap<>();
|
HashMap<String, String> map = new HashMap<>();
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.muyu.cloud.mart.utils;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:chaiyapeng
|
||||||
|
* @Package:com.muyu.cloud.mart.utils
|
||||||
|
* @Project:cloud-mart
|
||||||
|
* @name:Weather
|
||||||
|
* @Date:2024/8/24 18:51
|
||||||
|
*/
|
||||||
|
public class Weather {
|
||||||
|
public static StringBuffer queryWeather() {
|
||||||
|
String apiKey = "80e78ee9adaded8b1f42ec9cbdf69ac9";
|
||||||
|
String apiUrl = "https://apis.juhe.cn/fapig/alarm/citys";
|
||||||
|
|
||||||
|
HashMap<String, String> map = new HashMap<>();
|
||||||
|
map.put("key", apiKey);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public static String params(Map<String, String> map) {
|
||||||
|
return map.entrySet().stream()
|
||||||
|
.map(entry -> {
|
||||||
|
try {
|
||||||
|
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return entry.getKey() + "=" + entry.getValue();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect(Collectors.joining("&"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue