Airport Current Weather Observation
Related product: Airport Weather Data.
Introduction
This document describes the VariFlight Airport Current Weather Observation API, including authentication, request parameters, response fields, JSON examples and error responses. The interface uses UTF-8 encoding.
Authentication
The interface uses both token and IP for concurrent verification.
Token generation algorithm (MD5)
Registration code: Please obtain the registration code from the administrator of VariFlight. It is necessary for verification during the request process by both parties. Please be careful not to disclose it to the public.
Example (PHP):
<?php
function generateToken(array $data, string $appsecurity): string {
unset($data['token']);
ksort($data, SORT_STRING);
$pairs = [];
foreach ($data as $key => $value) {
$pairs[] = $key . '=' . $value;
}
$str = implode('&', $pairs);
return hash('md5', hash('md5', $str . $appsecurity));
}
// 参数值使用 UTF-8 原文;通过 token 参数传入结果,构建 URL 时再编码。
// $data['token'] = generateToken($data, $appsecurity);
// $query = http_build_query($data, '', '&', PHP_QUERY_RFC3986);
Example (Java):
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.stream.Collectors;
import java.security.MessageDigest;
import java.util.HexFormat;
public class TokenExample {
public static String generateToken(
Map<String, String> data, String appsecurity) throws Exception {
String str = data.entrySet().stream()
.filter(entry -> !"token".equals(entry.getKey()))
.sorted(Map.Entry.comparingByKey())
.map(entry -> entry.getKey() + "=" + entry.getValue())
.collect(Collectors.joining("&"));
return digestHex(digestHex(str + appsecurity));
}
private static String digestHex(String value) throws Exception {
byte[] bytes = MessageDigest.getInstance("MD5")
.digest(value.getBytes(StandardCharsets.UTF_8));
return HexFormat.of().formatHex(bytes);
}
}
// 请求 URL 追加 "&token=" + URLEncoder.encode(token, StandardCharsets.UTF_8)。
Example (C#):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
public static class TokenExample {
public static string GenerateToken(
Dictionary<string, string> data, string appsecurity) {
string str = string.Join("&", data
.Where(entry => entry.Key != "token")
.OrderBy(entry => entry.Key, StringComparer.Ordinal)
.Select(entry => entry.Key + "=" + entry.Value));
return DigestHex(DigestHex(str + appsecurity));
}
private static string DigestHex(string value) {
using (var digest = MD5.Create()) {
byte[] result = digest.ComputeHash(Encoding.UTF8.GetBytes(value));
return BitConverter.ToString(result).Replace("-", "").ToLowerInvariant();
}
}
}
// 请求 URL 追加 "&token=" + Uri.EscapeDataString(token)。Query by Airport IATA Code:
Request URL:
https://open-al.variflight.com/api/weather?appid=${appid}&airport=&lang=&token=${token}The parameter part in the URL is:
appid=${appid}&airport=&lang=&token=${token}
Generating the encrypted string:
str = airport=&appid=${appid}&lang=
Step2. The registration code is '${appsecurity}'. Assign this value to the variable $appsecurity.
Append appsecurity (the registration code) directly to str, with no extra separator.
Apply MD5 twice. Each result is a 32-character lowercase hexadecimal string. The second digest takes the UTF-8 bytes of the first Hex string, not its raw digest bytes.
token = md5Hex(md5Hex(str + appsecurity))
Note: $appsecurity=Registration code
API Endpoints
The request URL:
https://open-al.variflight.com/api/weather?The way to request: GET
The format of return: json
Request parameter Details
Airport Current Weather Observation employs an authorized authentication interface. At the beginning of the cooperation, VariFlight will apply on behalf of the third party to allocate user identification codes and registration codes (i.e., appid and appsecurity).
1 Response 1
Inquiry Method: 1: Query by Airport IATA Code
| Request parameter | Description | Example | Required or Optional | Parameter Type |
|---|---|---|---|---|
lang |
No | string |
||
appid |
Required | Yes | string |
|
airport |
Required | Yes | string |
|
token |
Required | Yes | string |
Return Parameter Details
| Request parameter | Description | Example | Parameter Type |
|---|---|---|---|
AirportCity |
Airport City | Hefei | string |
Type |
Weather Type
|
Fog | string |
Temperature |
Temperature |
4 | string |
Visib |
Visibility | 3000 | string |
WindSpeed |
Wind Speed | 3m/s | string |
WindPower |
Wind Power | Light breeze | string |
WindDirection |
Wind Direction | northeastern wind | string |
ReportTime |
Weather Publish Time | 2023-02-24 09:00:00 | string |
PM2.5 |
PM2.5 |
114 | string |
Aqi |
Air Quality Index |
114 | string |
Quality |
Air Quality Category |
lightly polluted | string |
METAR |
Real-Time Weather METAR
|
METAR ZSOF 240100Z 02003MPS 3000 BR BKN009 04/02 Q1030 BECMG TL0200 BKN010= |
string |
TAF |
Short-Term Weather Forecast Report (TAF) |
TAF ZSOF 232102Z 2400/2424 02003MPS 3000 BR BKN008 TX11/2407Z TN02/2423Z BECMG 2401/2402 SCT020= |
string |
NOTAM |
Pilot NOTAM
|
C0887/23 NOTAMNQ)ZSHA/QICCT/I/NBO/A/000/999/3158N11659E005A)ZSOF B)2302240800 C)2302250800 E) RWY15 ILS 0284 0180 3261 6107 , 0008 0668 0169 3938 , 0936 2699 7378 . | string |
CloudHeight |
Cloud Height | 270m | string |
SPECI |
Special Weather Report | string |
Return Parameter Examples
Example 1: Failed return
{
"error_code": 3,
"error": "Lack of parameters or parameter identification failed"
}
Example 2: Successful return
{
"AirportCity" : "Hefei",
"Type" : "Fog",
"Temperature" : "4",
"Visib" : "3000",
"WindSpeed" : "3m/s",
"WindPower" : "Light breeze",
"WindDirection" : "northeastern wind",
"ReportTime" : "2023-02-24 09:00:00",
"PM2.5" : "114",
"Aqi" : "114",
"Quality" : "lightly polluted",
"METAR" : "METAR ZSOF 240100Z 02003MPS 3000 BR BKN009 04/02 Q1030 BECMG TL0200 BKN010=",
"TAF" : "TAF ZSOF 232102Z 2400/2424 02003MPS 3000 BR BKN008 TX11/2407Z TN02/2423Z BECMG 2401/2402 SCT020=",
"NOTAM" : "C0887/23 NOTAMNQ)ZSHA/QICCT/I/NBO/A/000/999/3158N11659E005A)ZSOF B)2302240800 C)2302250800 E) RWY15 ILS 0284 0180 3261 6107 , 0008 0668 0169 3938 , 0936 2699 7378 .",
"CloudHeight" : "270m",
"SPECI" : ""
}Error Responses
| Return parameter | Description | Trigger Scene | Suggestions |
|---|---|---|---|
0 |
No data permissions | ||
2 |
The visiting ip have not been joined in white list | ||
3 |
This request method has no permission temporarily | ||
3 |
Lack of parameters or parameter identification failed | ||
3 |
wrong airport format | ||
3 |
Not find the airport | ||
10 |
No data | ||
5 |
Not find the airport | ||
4 |
The current interface is expired | ||
4 |
The current interface is closed | ||
4 |
No data permissions | ||
1 |
Pending review | ||
11 |
Unknown error | ||
0 |
Invalid user |
