360 Secure SkillHub
360 安全技能中心

Weather Search

通过环境变量中的高德地图 API Key 调用其天气 Web 服务,查询指定中国城市的实时天气状况、温度、风向、风力与湿度,支持城市名称、城市编码或经纬度;附带 weather.sh 脚本,可用 curl 取数并用 jq 格式化输出 JSON。

george-china
george-china
热度 76.22
最近更新 2026-05-11 17:35:03
分类:生活依赖:代码执行 / 第三方 API应用场景:旅行 / API 集成

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add weather-search
Metadata
name
weather-search
description
Query real-time weather information using Amap (高德地图) Weather API. Use when user asks about weather, temperature, wind, humidity for Chinese cities. Requires AMAP_API_KEY environment variable.
homepage
https://lbs.amap.com/api/javascript-api/guide/services/weather
metadata
{"openclaw":{"emoji":"☔","requires":{"bins":["curl"]}}}

Weather Search Skill

Query real-time weather information using Amap (高德地图) Weather API.

API Documentation

https://lbs.amap.com/api/javascript-api/guide/services/weather

Prerequisites

  1. Get Amap API Key

  2. Set Environment Variable

    export AMAP_API_KEY="your_api_key_here"
    

Usage

Query Weather by City Name

curl -X GET "https://restapi.amap.com/v3/weather/weatherInfo?city=BEIJING&key=YOUR_API_KEY&output=json"

Query Weather by City Code

curl -X GET "https://restapi.amap.com/v3/weather/weatherInfo?city=110000&key=YOUR_API_KEY&output=json"

Query Multiple Cities

curl -X GET "https://restapi.amap.com/v3/weather/weatherInfo?city=BEIJING|SHANGHAI|GUANGZHOU&key=YOUR_API_KEY&output=json"

Query by Coordinates (Latitude, Longitude)

curl -X GET "https://restapi.amap.com/v3/weather/weatherInfo?location=116.40,39.90&key=YOUR_API_KEY&output=json"

API Parameters

Parameter Type Required Description
city String Yes (or location) City name or city code
location String Yes (or city) Format: longitude,latitude
key String Yes Amap API Key
output String No Response format: json or xml (default: json)

Response Example

{
  "status": "1",
  "infocode": "10000",
  "info": "Query Successful",
  "count": "1",
  "lives": [
    {
      "province": "Beijing",
      "city": "Beijing",
      "adcode": "110000",
      "weather": "Clear",
      "temperature": "25",
      "winddirection": "North",
      "windpower": "2",
      "humidity": "45",
      "reporttime": "2024-01-15 12:00:00"
    }
  ]
}

Quick Start Script

Create a weather query script:

#!/bin/bash
# weather.sh

API_KEY="${AMAP_API_KEY:-your_api_key_here}"
CITY="$1"

if [ -z "$CITY" ]; then
    echo "Usage: weather.sh <city_name_or_code>"
    exit 1
fi

curl -s "https://restapi.amap.com/v3/weather/weatherInfo?city=${CITY}&key=${API_KEY}&output=json" | jq '.'

Make it executable:

chmod +x weather.sh
./weather.sh BEIJING

City Code Reference

City Code
Beijing 110000
Shanghai 310000
Guangzhou 440100
Shenzhen 440300
Hangzhou 330100
Chengdu 510100
Wuhan 420100
Xi'an 610100

Notes

  • API Key is required for all requests
  • Free tier: 1000 requests/day
  • Response includes: weather condition, temperature, wind direction, wind power, humidity
  • Supports both Chinese city names and city codes