China Meteorological Network meteorological data open Platform API use Method (Android)

Source: Internet
Author: User

In order to do a weather application, we need to find a weather API. The internet was searched for the next few, and the basic is outdated. Baidu has a weather API, but it seems to 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 only think about his documents (it feels like nobody is maintaining it.) )。

After a few difficult difficulties stuck, finally adjusted. Now share to everyone.


1. Apply for Keys

First register the account, then fill in the information and other audit (also need ID card ...) , saying that 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. At present, 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 only 0/year, conventional meteorological data interface to take home: P.


3. Reading the API documentation

Java sample code can be referenced, mainly contains key encryption content, 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 and Private_key, and as key This parameter is passed together.

The delivery URL format is as follows:

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

Parameter description:

areaid: City area code, official form available, can be considered with 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: This is a pit, this formal request, with the AppID of the top six, I stuck here for a long time ... Only use the full AppID as a public_key, and the rear will say

key: To this complex thing, this piece uses three things to complete, first:

Private_key: The key that was applied to

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

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

Then there are two, using Standardurlencoder (Public_key,private_key) in the provided Java sample code to combine the public key and the private key as the key parameter

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


4. Interpreting Weather Information

The JSON information returned is not much to say, the official documents provided by the corresponding explanation, is the parameters are C1,C2...FA,FB,FC and the like, too impersonal.

In this encounter the main problem is that the return of the man garbled ....

It is estimated that it is possible to use a different encoding than the server side, 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 methods decoding is finally reverted to Chinese characters, the method is as follows:

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 is actually iso-8859-1? (Please correct me if you understand something wrong here.) Well, it's a wonderful experience--!


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

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


China Meteorological Network meteorological data open Platform API use Method (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.