import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.json.JsonObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.platform.sdk.m2.bean.Location;
import com.platform.sdk.m2.bean.WeatherInfo;
import com.platform.sdk.m2.prarm.LauncherAreaWeatherParam;
import com.platform.sdk.m2.util.Code;
import com.platform.web.m2.constants.NumberKeys;
import com.platform.web.m2.constants.ServiceConstants;
import com.platform.web.m2.log.MyLog;
import com.platform.web.m2.util.PlatformConfig;
public class WeatherTest
{
private static String convertStreamToString(InputStream is) {
StringBuilder sb1 = new StringBuilder();
byte[] bytes = new byte[4096];
int size;
try {
while ((size = is.read(bytes)) > 0) {
String str = new String(bytes, 0, size, "UTF-8");
sb1.append(str);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb1.toString();
}
@Test
public void webServiceApi()
{
String uri = String.format("https://free-api.heweather.com/s6/weather/forecast?location=%s&key=%s", "深圳","c0d7b9f9e3dc4f82845c58673618b2a4");
HttpGet httpGet = new HttpGet(uri);
httpGet.setHeader("Content-Type", "application/json;charset=UTF-8");
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
try
{
response = httpClient.execute(httpGet);
response.setHeader("Content-Type", "application/json;charset=UTF-8");
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK)
{
String result = EntityUtils.toString(response.getEntity());
JSONObject json = JSON.parseObject(result);
System.out.println(json.toString());
return;
}
return;
}
catch (IOException e)
{
MyLog.error("请求第三方接口异常");
return;
}
finally
{
try
{
if (null != response)
{
EntityUtils.consume(response.getEntity());
response.close();
}
httpClient.close();
}
catch (IOException e)
{
MyLog.error("关闭 httpClient 异常");
return;
}
}
}
/**
* 请求新浪获取地址API
* <功能详细描述>
* @param ip ip地址
* @return Location
* @see [类、类#方法、类#成员]
*/
@Test
public void getSinaLocaltion()
{
String uri = String.format("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=%s", "120.79.184.201");
HttpGet httpGet = new HttpGet(uri);
httpGet.setHeader("Content-Type", "application/json;charset=UTF-8");
CloseableHttpClient httpClient = HttpClients.createDefault();
//RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(30000).setConnectTimeout(30000).build();
//httpGet.setConfig(requestConfig);
CloseableHttpResponse response = null;
try
{
response = httpClient.execute(httpGet);
response.setHeader("Content-Type", "application/json;charset=UTF-8");
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK)
{
String result = EntityUtils.toString(response.getEntity());
JSONObject json = JSON.parseObject(result);
if (null == json)
{
return;
}
Integer ret = Integer.parseInt(String.valueOf(json.get("ret")));
if (ret != NumberKeys.NUM_1)
{
return;
}
String province = String.valueOf(json.get("province"));
String city = String.valueOf(json.get("city"));
Location location = new Location();
location.setProvinceName(province);
location.setCityName(city);
return;
}
return;
}
catch (IOException e)
{
return;
}
finally
{
try
{
if (null != response)
{
EntityUtils.consume(response.getEntity());
response.close();
}
httpClient.close();
}
catch (IOException e)
{
MyLog.error("释放资源异常");
}
}
}
@Test
public void getAreaWeather() throws ClientProtocolException, IOException
{
// 前端可以传ip或者城市名 都可以查下到相对应的天气
// 前端5小时调用一次后台获取天气 我是本地缓存城市天气 如果相隔四个小时就会根据api获取天气
//出于第三方服务器压力考虑
String city = "深圳";
String cityName = null;
String provinceName = null;
String ip = "120.236.15.10";
// 获取地区
Location location = getArea(ip);
// 城市名称
provinceName = location.getProvinceName();
cityName = location.getCityName();
MyLog.debug("provinceName : {} city:{}", provinceName, cityName);
MyLog.debug("location:{}", JSONObject.toJSONString(location));
// 获取中华万年历天气
WeatherInfo weather = getChinaCalendarWeather(city);
MyLog.debug("wannianli get weather",weather);
if (null == weather)
{
// 获取中国天气
weather = getChinaWeather(city);
}
MyLog.debug("zhongguo get weather",weather);
if (null == weather)
{
// 获取和风天气
weather = getHeWeather(city);
}
MyLog.debug("hefeng get weather",weather);
if (null == weather)
{
MyLog.error("无法获取{}天气", city);
MyLog.debug("get {} weather error",city);
}else{
System.out.println(JSONObject.toJSONString(weather));
}
}
/**
* 中华万年历天气
* <功能详细描述>
* @param city
* @return
* @throws IOException
* @throws ClientProtocolException
* @see [类、类#方法、类#成员]
*/
public WeatherInfo getChinaCalendarWeather(String city) throws ClientProtocolException, IOException
{
MyLog.info("调用中华万年历天气接口");
WeatherInfo weather = null;
CloseableHttpClient client;
client = HttpClients.createDefault();
HttpGet get = new HttpGet("http://wthrcdn.etouch.cn/weather_mini?city=" + city);
HttpResponse response;
JSONObject json = null;
response = client.execute(get);
HttpEntity entity = response.getEntity();
if (entity != null)
{
InputStream instreams = entity.getContent();
String str = convertStreamToString(instreams);
get.abort();
json = JSONObject.parseObject(str);
MyLog.info(json.toString());
// 城市名称错误 获取不到城市天气
if (NumberKeys.NUM_1000 != Integer.parseInt(json.get("status").toString()))
{
MyLog.error("获取不到城市的天气状况", city);
return null;
}
}
JSONObject data = JSONObject.parseObject(String.valueOf(json.get("data")));
if (null == data)
{
MyLog.error("获取不到城市的天气状况", city);
return null;
}
String wendu = String.valueOf(data.get("wendu"));
JSONArray forecast = JSONArray.parseArray(String.valueOf(data.get("forecast")));
JSONObject forecastJson = JSONObject.parseObject(forecast.get(0).toString());
String fengli = String.valueOf(forecastJson.get("fengli")).substring(9,
String.valueOf(forecastJson.get("fengli")).length() - 3);
String fengxiang = String.valueOf(forecastJson.get("fengxiang"));
String type = String.valueOf(forecastJson.get("type"));
String lowTemp = String.valueOf(forecastJson.get("low")).substring(3);
String highTemp = String.valueOf(forecastJson.get("high")).substring(3);
weather = new WeatherInfo();
weather.setTemp(wendu);
weather.setWindPower(fengli);
weather.setWindDirection(fengxiang);
weather.setWeather(type);
weather.setLowTemp(lowTemp);
weather.setHighTemp(highTemp);
return weather;
}
/**
* 获取中国天气
* <功能详细描述>
* @param cityName 城市名称
* @return WeatherInfo 天气数据
* @throws UnsupportedEncodingException
* @see [类、类#方法、类#成员]
*/
private WeatherInfo getChinaWeather(String cityName) throws UnsupportedEncodingException
{
String cityCode = getCityCode(cityName);
String uri = String.format("http://d1.weather.com.cn/sk_2d/%s.html?_=%s", cityCode, System.currentTimeMillis());
HttpGet httpGet = new HttpGet(uri);
//httpGet.setHeader("Content-Type", "application/json;charset=UTF-8");
httpGet.setHeader("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36");
httpGet.setHeader("Referer", "http://www.weather.com.cn/weather1d/" + cityCode + ".shtml");
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
CloseableHttpResponse response2 = null;
try
{
response = httpClient.execute(httpGet);
//response.setHeader("Content-Type", "application/json;charset=UTF-8");
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK)
{
String result = EntityUtils.toString(response.getEntity(), "utf-8");
try
{
JSONObject json = JSON.parseObject(result.split("=")[1]);
if (null == json)
{
return null;
}
// 温度
String temp = json.getString("temp");
// 风向
String wd = json.getString("WD");
// 风等级
String ws = json.getString("WS");
// 天气状况
String weather = json.getString("weather");
uri = String.format("http://d1.weather.com.cn/dingzhi/%s.html?_=%s",
cityCode,
System.currentTimeMillis());
httpGet = new HttpGet(uri);
//httpGet.setHeader("Content-Type", "application/json;charset=UTF-8");
httpGet.setHeader("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36");
httpGet.setHeader("Referer", "http://www.weather.com.cn/weather1d/" + cityCode + ".shtml");
response2 = httpClient.execute(httpGet);
//response2.setHeader("Content-Type", "application/json;charset=UTF-8");
statusCode = response2.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK)
{
result = EntityUtils.toString(response2.getEntity(), "utf-8");
String cityWeather = result.split(";")[0].toString();
if (!StringUtils.isEmpty(cityWeather))
{
String weatherInfo = cityWeather.split("=")[1].toString();
if (!StringUtils.isEmpty(weatherInfo))
{
JSONObject hisWeather =
JSON.parseObject(JSON.parseObject(weatherInfo).getString("weatherinfo"));
// 最低温度
String lowTemp = hisWeather.getString("tempn");
// 最高温度
String highTemp = hisWeather.getString("temp");
WeatherInfo areaWeather = new WeatherInfo();
areaWeather.setHighTemp(highTemp);
areaWeather.setLowTemp(lowTemp);
areaWeather.setWindDirection(wd);
areaWeather.setWindPower(ws);
areaWeather.setTemp(temp);
areaWeather.setWeather(weather);
return areaWeather;
}
}
}
}
catch (Exception e)
{
MyLog.error("无法获取城市的天气{}", cityName);
return null;
}
}
}
catch (IOException e)
{
MyLog.error("请求第三方接口异常");
return null;
}
finally
{
try
{
if (null != response)
{
EntityUtils.consume(response.getEntity());
response.close();
}
if (null != response2)
{
EntityUtils.consume(response2.getEntity());
response2.close();
}
httpClient.close();
}
catch (IOException e)
{
MyLog.error("关闭 httpClient 异常");
return null;
}
}
return null;
}
/**
* 中国天气接口
* <功能详细描述>
* @param city
* @return
* @throws UnsupportedEncodingException
* @see [类、类#方法、类#成员]
*/
public String getCityCode(String city) throws UnsupportedEncodingException
{
// 先从数据库中获取城市编码,不存在则新增
String dbCityCode = null;
if (null != dbCityCode)
{
return dbCityCode;
}
MyLog.info("调用中国天气网查询城市编码接口");
BufferedReader bufferedReader = null;
InputStreamReader inputStreamReader = null;
InputStream inputStream = null;
HttpURLConnection httpUrlConn = null;
String cityCode = ServiceConstants.BEIJING_CITY_CODE;
// 获取城市编码
String uri = String.format("http://toy1.weather.com.cn/search?cityname=%s", URLEncoder.encode(city, "utf-8"));
// 建立get请求
URL url;
try
{
url = new URL(uri);
httpUrlConn = (HttpURLConnection)url.openConnection();
httpUrlConn.setDoInput(true);
httpUrlConn.setReadTimeout(3000);
httpUrlConn.setConnectTimeout(3000);
httpUrlConn.setRequestMethod("GET");
// 获取输入流
inputStream = httpUrlConn.getInputStream();
inputStreamReader = new InputStreamReader(inputStream, "utf-8");
bufferedReader = new BufferedReader(inputStreamReader);
// 从输入流读取结果
StringBuffer buffer = new StringBuffer();
String str = null;
while ((str = bufferedReader.readLine()) != null)
{
buffer.append(str);
}
MyLog.info(buffer.toString());
String codeStr = buffer.toString().substring(1, buffer.toString().length() - 1);
JSONArray array = JSON.parseArray(codeStr);
if (NumberKeys.NUM_0 == array.size())
{
MyLog.error("中国天气网获取城市编码异常...");
}
else
{
JSONObject cityInfo = JSON.parseObject(array.get(0).toString());
cityCode = cityInfo.get("ref").toString().substring(0, 9);
// launcherMapper.insertCityCode(cityCode, city);
}
}
catch (Exception e)
{
MyLog.error("获取万年历天气异常...");
}
finally
{
// 释放资源
try
{
if (null != bufferedReader)
{
bufferedReader.close();
}
if (null != inputStreamReader)
{
inputStreamReader.close();
}
if (null != inputStream)
{
inputStream.close();
}
if (null != httpUrlConn)
{
httpUrlConn.disconnect();
}
}
catch (IOException e)
{
System.out.println("释放资源异常...");
}
}
return cityCode;
}
/**
* 和风天气 (免费用户只允许1000次调用)
* <功能详细描述>
* @param cityName
* @return
* @see [类、类#方法、类#成员]
*/
private WeatherInfo getHeWeather(String cityName)
{
// 获取和风天气
String hefengKey = "c0d7b9f9e3dc4f82845c58......";
String uri =
String.format("https://free-api.heweather.com/s6/weather/now?location=%s&key=%s", cityName, hefengKey);
JSONObject heWeather6Now = webServiceApi(uri);
if (null == heWeather6Now)
{
return null;
}
JSONArray heWeather6ArrayNow = JSON.parseArray(heWeather6Now.getString("HeWeather6"));
if (null == heWeather6ArrayNow || heWeather6ArrayNow.size() == 0)
{
return null;
}
JSONObject weatherJson = JSONObject.parseObject(heWeather6ArrayNow.get(0).toString());
if (!"ok".equals(weatherJson.getString("status")))
{
return null;
}
uri =
String.format("https://free-api.heweather.com/s6/weather/forecast?location=%s&key=%s", cityName, hefengKey);
JSONObject HeWeather6 = webServiceApi(uri);
if (null == HeWeather6)
{
return null;
}
JSONArray heWeather6Array = JSON.parseArray(HeWeather6.getString("HeWeather6"));
if (null == heWeather6Array || heWeather6Array.size() == 0)
{
return null;
}
JSONObject weatherJson2 = JSONObject.parseObject(heWeather6Array.get(0).toString());
if (!"ok".equals(weatherJson2.getString("status")))
{
return null;
}
// 天气实况
JSONObject dailyForecastNow = JSONObject.parseObject(weatherJson.getString("now"));
// 预报天气
JSONArray dailyForecastArray = JSONObject.parseArray(weatherJson2.getString("daily_forecast"));
if (null == dailyForecastNow || null == dailyForecastArray || NumberKeys.NUM_0 == dailyForecastArray.size())
{
return null;
}
JSONObject dailyForecast = JSONObject.parseObject(dailyForecastArray.get(0).toString());
if (null == dailyForecast)
{
return null;
}
WeatherInfo weather = new WeatherInfo();
weather.setWeather(dailyForecastNow.getString("cond_txt"));
weather.setWindDirection(dailyForecastNow.getString("wind_dir"));
weather.setWindPower(dailyForecastNow.getString("wind_sc"));
weather.setTemp(dailyForecastNow.getString("tmp"));
weather.setLowTemp(dailyForecast.getString("tmp_min"));
weather.setHighTemp(dailyForecast.getString("tmp_max"));
return weather;
}
public JSONObject webServiceApi(String uri)
{
MyLog.info("请求api:" + uri);
HttpGet httpGet = new HttpGet(uri);
httpGet.setHeader("Content-Type", "application/json;charset=UTF-8");
CloseableHttpClient httpClient = HttpClients.createDefault();
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(3000).setConnectTimeout(3000).build();
httpGet.setConfig(requestConfig);
CloseableHttpResponse response = null;
try
{
response = httpClient.execute(httpGet);
response.setHeader("Content-Type", "application/json;charset=UTF-8");
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK)
{
String result = EntityUtils.toString(response.getEntity(), "utf-8");
JSONObject json = JSON.parseObject(result);
return json;
}
return null;
}
catch (IOException e)
{
MyLog.error("请求第三方接口异常");
return null;
}
finally
{
try
{
if (null != response)
{
EntityUtils.consume(response.getEntity());
response.close();
}
httpClient.close();
}
catch (IOException e)
{
MyLog.error("关闭 httpClient 异常");
return null;
}
}
}
/**
* 获取地区
* <功能详细描述>
* @param ip
* @return
* @see [类、类#方法、类#成员]
*/
private Location getArea(String ip)
{
String province = null;
String city = null;
JSONObject json = null;
String uri = null;
// 获取新浪地址
Location location = getTaobaoLocaltion(ip);
/*if (!checkLocation(location))
{
// 获取淘宝地址
location = getSinaLocaltion(ip);
}*/
if (!checkLocation(location))
{
MyLog.error("淘宝地址获取失败");
MyLog.info("获取百度地址");
// 获取百度位置
String baiduAk = "Z2jjwUHuNOVrQXGVMg.....";
uri = String.format("http://api.map.baidu.com/location/ip?ak=%s&ip=%s", baiduAk, ip);
json = webServiceApi(uri);
if (null == json || Code.SUCCESS != Integer.parseInt(json.get("status").toString()))
{
MyLog.error("百度地址获取失败");
}
else
{
JSONObject content = JSONObject.parseObject(String.valueOf(json.get("content")));
JSONObject addressDetail = JSONObject.parseObject(String.valueOf(content.get("address_detail")));
province = String.valueOf(addressDetail.get("province"));
city = String.valueOf(addressDetail.get("city"));
location = new Location();
location.setProvinceName(province);
location.setCityName(city);
}
}
if (!checkLocation(location))
{
// 获取腾讯位置
MyLog.info("获取腾讯地址");
String tengxunKey = "7YMBZ-JGJL6-63DSR-ELFTG......";
uri = String.format("https://apis.map.qq.com/ws/location/v1/ip?ip=%s&key=%s", ip, tengxunKey);
json = webServiceApi(uri);
if (null == json || Code.SUCCESS != Integer.parseInt(String.valueOf(json.get("status"))))
{
MyLog.error("腾讯地址获取失败");
}
else
{
JSONObject result = JSONObject.parseObject(String.valueOf(json.get("result")));
JSONObject addressDetail = JSONObject.parseObject(String.valueOf(result.get("ad_info")));
province = String.valueOf(addressDetail.get("province"));
city = String.valueOf(addressDetail.get("city"));
location = new Location();
location.setProvinceName(province);
location.setCityName(city);
}
}
if (!checkLocation(location))
{
location = new Location();
location.setProvinceName("北京市");
location.setCityName("北京");
}
return location;
}
/**
* 校验位置
* <功能详细描述>
* @param location 位置
* @return boolean 校验是否通过
* @see [类、类#方法、类#成员]
*/
private boolean checkLocation(Location location)
{
if (null == location || StringUtils.isEmpty(location.getProvinceName())
|| StringUtils.isEmpty(location.getCityName()))
{
return false;
}
return true;
}
/**
* 请求淘宝获取地址API
* <功能详细描述>
* @param ip ip地址
* @return Location
* @see [类、类#方法、类#成员]
*/
private Location getTaobaoLocaltion(String ip)
{
BufferedReader bufferedReader = null;
InputStreamReader inputStreamReader = null;
InputStream inputStream = null;
HttpURLConnection httpUrlConn = null;
try
{
String uri = String.format("http://ip.taobao.com/service/getIpInfo.php?ip=%s", ip);
// 建立get请求
URL url = new URL(uri);
httpUrlConn = (HttpURLConnection)url.openConnection();
httpUrlConn.setDoInput(true);
httpUrlConn.setRequestMethod("GET");
httpUrlConn.setReadTimeout(3000);
httpUrlConn.setConnectTimeout(3000);
// 获取输入流
inputStream = httpUrlConn.getInputStream();
inputStreamReader = new InputStreamReader(inputStream, "utf-8");
bufferedReader = new BufferedReader(inputStreamReader);
// 从输入流读取结果
StringBuffer buffer = new StringBuffer();
String str = null;
while ((str = bufferedReader.readLine()) != null)
{
buffer.append(str);
}
JSONObject json = JSON.parseObject(buffer.toString());
if (null == json)
{
return null;
}
Integer code = Integer.parseInt(String.valueOf(json.get("code")));
if (code != NumberKeys.NUM_0)
{
return null;
}
JSONObject data = json.getJSONObject("data");
String province = String.valueOf(data.get("region"));
String city = String.valueOf(data.get("city"));
// 省份和城市都有数据
if (!StringUtils.isEmpty(province) && !StringUtils.isEmpty(city) && !"XX".equals(province)
&& !"XX".equals(city))
{
Location location = new Location();
location.setProvinceName(province);
location.setCityName(city);
return location;
}
}
catch (Exception e)
{
MyLog.error("获取淘宝位置异常");
}
finally
{
// 释放资源
try
{
if (null != bufferedReader)
{
bufferedReader.close();
}
if (null != inputStreamReader)
{
inputStreamReader.close();
}
if (null != inputStream)
{
inputStream.close();
}
if (null != httpUrlConn)
{
httpUrlConn.disconnect();
}
}
catch (IOException e)
{
MyLog.error("释放资源异常");
}
}
return null;
}
}
相关推荐
本案例“android studio 简单获取天气”旨在教你如何利用Android Studio开发一个应用,该应用能够从网络获取天气预报数据并将其展示在用户界面(UI)上。下面我们将详细探讨这个过程涉及的关键知识点。 1. **网络...
Android中基于心知天气获取天气信息JSONJSON简介JSON对象JSON数组JSON解析Android中获取天气获取天气的流程获取心知天气的API key获取心知天气的API代码部分实现的效果如下进阶-获取任意城市的天气信息 为什么要写这...
2. **天气预报API**:为了获取天气数据,开发者通常会利用第三方提供的天气预报API,如OpenWeatherMap、Weather Underground等。这些API提供了JSON或XML格式的天气数据,包括温度、湿度、风速等信息。开发者需要注册...
在Qt开发中,获取天气信息是一项常见的功能,可以用于创建应用程序来展示实时的天气预报。Qt是一个跨平台的C++库,提供了丰富的图形用户界面(GUI)工具和网络功能,使得开发者可以方便地构建这样的应用。本文将详细...
在这个“JSON获取天气源码”项目中,开发者提供了通过JSON获取天气预报的方法,支持GB2312和UTF-8两种字符编码,以适应不同的数据处理需求。 源码通常是程序员编写的未经编译或解释的原始代码,它展示了程序的具体...
【基于WebService服务获取天气信息】 在信息技术领域,WebService是一种通过标准协议(如SOAP或REST)在互联网上交换数据的方式。这种技术使得不同系统之间能够共享数据和服务,即使它们使用不同的编程语言、操作...
### 获取天气预报信息的Web服务:关键知识点解析 #### 标题解读: “获取天气预报信息的Web服务”这一标题明确指出了文章的核心主题——如何通过Web服务接口获取天气预报数据。这通常涉及到一系列的技术细节,包括...
在C++编程中,获取天气信息通常涉及到网络编程和数据解析技术。这个源码示例可能展示了一个C++程序如何通过调用Web服务器上的API来获取实时天气预报。以下是一些相关的知识点: 1. **HTTP协议**:首先,C++程序需要...
标题中的“天气预报接口,自动获取天气”是指利用编程接口(API)来自动化地获取实时或预测性的天气信息。在互联网时代,许多气象服务提供商开放了API,允许开发者通过发送请求来获取特定地理位置的天气状况,包括...
标题中的“获取天气预报API,免费接口,项目下载可运行,Java实现”表明这是一个关于使用Java语言开发的天气预报API项目,它提供了免费的API接口,并且已经打包为可直接运行的形式。这样的项目通常对开发者来说是很...
使用: ...编译烧录后即可使用。 在ATK_ESP8266文件夹下面的weather.c中修改85行修改天气api。 在PICTURE文件夹下面的picture.c修改led显示的背景图片。 时间的显示可以使用stm32的实时...获取天气api,获得天气并且显示。
DELPHI 通过WEBSERVICE获取天气预报,可获取全球,全国各省市天气预报详情
在这个项目中,我们将探讨如何利用ESP8266与STM32微控制器(如STM328266)协同工作,从网络获取天气数据并显示在LCD屏幕上。STM32是一款高性能的32位微控制器,适用于各种嵌入式应用,包括控制和数据处理。 首先,...
在本文中,我们将深入探讨如何利用JS获取天气预报信息,这通常涉及到API调用和JSON数据解析。 首先,天气预报信息通常是通过与气象服务提供商的API接口进行交互获取的。API(Application Programming Interface)是...
总结来说,这个"QT获取天气示例程序"涵盖了以下关键知识点: 1. QT5 GUI框架:如何创建窗口,添加控件,以及使用信号和槽机制。 2. QNetworkAccessManager:理解和使用HTTP请求获取远程数据。 3. JSON解析:使用...
在IT行业中,自动获取天气预报系统是一个非常实用的Web应用程序,它允许用户无需手动刷新页面就能获取最新的气象信息。这个系统通常使用Ajax(Asynchronous JavaScript and XML)技术来实现,这是一种提升网页用户...
在代码中,你需要创建一个WeatherService的实例,并调用其提供的方法来获取天气数据。例如,如果Web服务有一个名为`GetWeatherByCityName`的方法,你可以如下调用: ```csharp WeatherService ws = new ...
在中国天气网获取天气数据是一项常见的任务,特别是在开发与气象信息相关的应用程序时。本文将深入探讨如何利用编程技术,特别是Visual Studio 2008(VS2008),来实现这一功能,以及涉及的相关知识点。 首先,我们...
在本文中,我们将深入探讨如何使用C++编程语言获取天气信息。这个项目在Microsoft Visual C++ 6.0(简称VC6.0)环境下开发,并且已经在Windows XP系统上进行了测试,表明它是兼容的。我们将从以下几个方面进行讨论:...