修改配置
This commit is contained in:
parent
78c4d5268e
commit
c911ef5dc9
|
|
@ -0,0 +1,36 @@
|
|||
package com.ruoyi.device.domain.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 天气API配置属性
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "weather.api")
|
||||
public class WeatherProperties {
|
||||
|
||||
/**
|
||||
* 天气API AppCode
|
||||
*/
|
||||
private String appcode = "6a152d74a3c249bfa6db6e664f2541f0";
|
||||
|
||||
/**
|
||||
* 天气API Host
|
||||
*/
|
||||
private String host = "https://aliv8.data.moji.com";
|
||||
|
||||
/**
|
||||
* 天气API Path
|
||||
*/
|
||||
private String path = "/whapi/json/aliweather/condition";
|
||||
|
||||
/**
|
||||
* 天气API Token
|
||||
*/
|
||||
private String token = "ff826c205f8f4a59701e64e9e64e01c4";
|
||||
}
|
||||
|
|
@ -5,10 +5,11 @@ import com.ruoyi.device.domain.api.IWeatherDomain;
|
|||
import com.ruoyi.device.domain.impl.weather.HttpUtils;
|
||||
import com.ruoyi.device.domain.model.weather.Weather;
|
||||
import com.ruoyi.device.domain.model.weather.WeatherResponse;
|
||||
import com.ruoyi.device.domain.config.WeatherProperties;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -16,23 +17,24 @@ import java.util.Map;
|
|||
@Component
|
||||
public class WeatherDomainImpl implements IWeatherDomain {
|
||||
|
||||
String appcode = "6a152d74a3c249bfa6db6e664f2541f0";
|
||||
@Autowired
|
||||
private WeatherProperties weatherProperties;
|
||||
|
||||
|
||||
public Weather weatherInfo(String lat, String lon) {
|
||||
String host = "https://aliv8.data.moji.com";
|
||||
String path = "/whapi/json/aliweather/condition";
|
||||
String host = weatherProperties.getHost();
|
||||
String path = weatherProperties.getPath();
|
||||
String method = "POST";
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
||||
headers.put("Authorization", "APPCODE " + appcode);
|
||||
headers.put("Authorization", "APPCODE " + weatherProperties.getAppcode());
|
||||
//根据API的要求,定义相对应的Content-Type
|
||||
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
Map<String, String> querys = new HashMap<String, String>();
|
||||
Map<String, String> bodys = new HashMap<String, String>();
|
||||
Map<String, String> querys = new HashMap<>();
|
||||
Map<String, String> bodys = new HashMap<>();
|
||||
bodys.put("lat", lat);
|
||||
bodys.put("lon", lon);
|
||||
bodys.put("token", "ff826c205f8f4a59701e64e9e64e01c4");
|
||||
bodys.put("token", weatherProperties.getToken());
|
||||
|
||||
Weather weather = new Weather();
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in New Issue