China Meteorological Network meteorological data open Platform API usage (Android)

Source: Internet
Author: User

Because it's going to be a weather application. Need to find a weather API. The internet was searched for the next few, and the basic is outdated. Baidu has a weather API, just seemingly can only provide the day. The internet refers to the Chinese meteorological interface of the article, most used when the old API, some were sealed, and some forever stopped in March 2014 24 not updated.

Later found a new interface for China's weather, has been upgraded to a meteorological data open platform http://openweather.weather.com.cn/. Without a developer community or forum, you can just figure out his documentation (it feels like nobody's maintaining it.) )。

After a few difficult difficulties stuck. It's finally been tuned.

Now share to everyone.


1. Apply for Keys

First, register your account. Then fill in the information and other audit (also need ID card.

。。 )。 The audit is really slow, I waited one weeks before the audit passed, then have their own key, this request for weather data will be used.


2. Application Service

After the approval, you can go to the Product center that application interface. Now there are two kinds of interfaces: conventional meteorological data interface and basic meteorological data interface.

The difference is that the conventional is more than the base of the city. As for the price, do not 300/year, not 30/year, now the big discount just 0/year, conventional meteorological data interface to take home: P.


3. Reading the API documentation

There are examples of Java demo code that can be included, mainly including the content of key encryption. Can be used directly, other requests, etc. need to write their own.

Request with GET, parsing with JSON, there is no difficulty, mainly encrypted this ...

This encryption before too much to look at, the result looked dizzy, card a lot of time.

The primary encryption is combined by Public_key with Private_key, which is passed as key.

The delivery URL format is as follows:

Http://open.weather.com.cn/data/?areaid= "Areaid" &type= "type" &date= "date" &appid= "Appid_six" &key = "Key"

Introduction to the number of references:

areaid: City area code, official form available. can consider using 101010100 (Beijing)

Type: Types of request data: Index: Index_f (Base interface), Index_v (General Interface), 3-Day Forecast: Forecast_f (Basic interface), Forecast_v (General interface); I use the forecast_v.

Date: Current time format yyyymmddhhmm such as 201506051423

AppID: It's a pit. This formal request, with the AppID of the top six, I stuck here for a very long time.

。 Just use the full appid as a public_key, and the back will say

Key: It's a complicated thing. This piece uses three things to finish, first:

Private_key: The key that was applied to

Public_key: The format is as follows. Similar but different from the URL passed, one is that there is no key parameter, and the second is that AppID is using the full AppID. It's very important.

Http://open.weather.com.cn/data/?areaid= "Areaid" &type= "type" &date= "date" &appid= "Appid_full"

Then there's a couple of these two, using the provided Java Demo sample code in Standardurlencoder (Public_key. Private_key), combining the public and private keys as key parameters

After that, you will be able to receive the returned weather information basically.


4. Interpreting Weather Information

The JSON information returned is not much to say, the official document provided by the corresponding explanation, is that the number of C1,C2...FA,FB,FC and the like, too impersonal.

The main problem encountered here is. Returned the man garbled.

。。

It is expected that, because it differs from the encoding used by the server side, it is not utf-8.

。。。

And the official didn't say anything .....

No way, I can only bitter force of a coding attempt, with a good number of ways to decode is finally reduced to Chinese characters. Methods such as the following:

byte[] Converttobytes = weather.city.getBytes ("iso-8859-1"); string S1 = new String (converttobytes); System.out.println (s1); weather.city = S1;

after testing, the Chinese character format came from Iso-8859-1? (Please correct me if you understand something wrong here.) It feels very wonderful--!


All the basic can be smoothly transferred to this, I believe that the small partners are no problem

Project Address: Https://github.com/rsy210/MyWeather

Reprint please indicate the source ha http://blog.csdn.net/lqc1992/article/details/46375567


China Meteorological Network meteorological data open Platform API usage (Android)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.