天气接口添加开鲁location
This commit is contained in:
parent
3a642833c4
commit
3ad89e44dd
@ -18,16 +18,16 @@ public class WeatherController {
|
|||||||
* 获取七天的天气预报
|
* 获取七天的天气预报
|
||||||
*/
|
*/
|
||||||
@GetMapping("/qitian")
|
@GetMapping("/qitian")
|
||||||
public AjaxResult getWeather() {
|
public AjaxResult getWeather(Long projectId) {
|
||||||
return AjaxResult.success(TianqiApi.QitianApi());
|
return AjaxResult.success(TianqiApi.QitianApi(projectId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取实时天气
|
* 获取实时天气
|
||||||
*/
|
*/
|
||||||
@GetMapping("/shishi")
|
@GetMapping("/shishi")
|
||||||
public AjaxResult getWeatherShiShi() {
|
public AjaxResult getWeatherShiShi(Long projectId) {
|
||||||
return AjaxResult.success(TianqiApi.weatherNow());
|
return AjaxResult.success(TianqiApi.weatherNow(projectId));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,19 @@ public class TianqiApi {
|
|||||||
/**
|
/**
|
||||||
* 获取未来天气预测
|
* 获取未来天气预测
|
||||||
*/
|
*/
|
||||||
public static JSONObject QitianApi() {
|
public static JSONObject QitianApi(Long projectId) {
|
||||||
|
String location="";
|
||||||
|
if(projectId==35){//黑龙江项目
|
||||||
|
location="YBMUBR41ZWVC";
|
||||||
|
|
||||||
|
}else if(projectId==39){//开鲁
|
||||||
|
location="WXY201PUQV5D";
|
||||||
|
}
|
||||||
|
// System.out.println(location);
|
||||||
String url = UrlConstant.QitianApi + "?key=" +
|
String url = UrlConstant.QitianApi + "?key=" +
|
||||||
UrlConstant.PrivateKey +
|
UrlConstant.PrivateKey +
|
||||||
"&location=YBMUBR41ZWVC&language=zh-Hans&unit=c";//指定URL
|
"&location="+location+"&language=zh-Hans&unit=c";//指定URL
|
||||||
|
// System.out.println(url);
|
||||||
HttpResponse execute = HttpUtil.createGet(url).execute();
|
HttpResponse execute = HttpUtil.createGet(url).execute();
|
||||||
if (execute.getStatus() == HttpStatus.HTTP_OK) {
|
if (execute.getStatus() == HttpStatus.HTTP_OK) {
|
||||||
JSONObject jsonObject = new JSONObject(execute.body());
|
JSONObject jsonObject = new JSONObject(execute.body());
|
||||||
@ -33,10 +41,19 @@ public class TianqiApi {
|
|||||||
/**
|
/**
|
||||||
* 获取天气实况
|
* 获取天气实况
|
||||||
*/
|
*/
|
||||||
public static JSONObject weatherNow() {
|
public static JSONObject weatherNow(Long projectId) {
|
||||||
|
String location="";
|
||||||
|
if(projectId==35){//黑龙江项目
|
||||||
|
location="YBMUBR41ZWVC";
|
||||||
|
|
||||||
|
}else if(projectId==39){//开鲁项目
|
||||||
|
location="WXY201PUQV5D";
|
||||||
|
}
|
||||||
|
// System.out.println(location);
|
||||||
String url = UrlConstant.ShishiApi + "?key=" +
|
String url = UrlConstant.ShishiApi + "?key=" +
|
||||||
UrlConstant.PrivateKey +
|
UrlConstant.PrivateKey +
|
||||||
"&location=YBMUBR41ZWVC&language=zh-Hans&unit=c";//指定URL
|
"&location="+location+"&language=zh-Hans&unit=c";//指定URL
|
||||||
|
// System.out.println(url);
|
||||||
HttpResponse execute = HttpUtil.createGet(url).execute();
|
HttpResponse execute = HttpUtil.createGet(url).execute();
|
||||||
if (execute.getStatus() == HttpStatus.HTTP_OK) {
|
if (execute.getStatus() == HttpStatus.HTTP_OK) {
|
||||||
JSONObject jsonObject = new JSONObject(execute.body());
|
JSONObject jsonObject = new JSONObject(execute.body());
|
||||||
@ -71,7 +88,15 @@ public class TianqiApi {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args)
|
||||||
TianqiApi.weatherNow();
|
{
|
||||||
|
TianqiApi.weatherNow(39L);
|
||||||
|
/*String url="https://api.seniverse.com/v3/location/search.json?key="+UrlConstant.PrivateKey
|
||||||
|
+"&q="+"开鲁";
|
||||||
|
HttpResponse execute = HttpUtil.createGet(url).execute();
|
||||||
|
if (execute.getStatus() == HttpStatus.HTTP_OK) {
|
||||||
|
JSONObject jsonObject = new JSONObject(execute.body());
|
||||||
|
System.out.println("jsonObject = " + jsonObject);
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user