2025-01-02 22:57:51 +08:00
|
|
|
package qweather
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 获取天气
|
2025-01-05 23:12:05 +08:00
|
|
|
func Get(location_id int, weather_type_name string, dev bool) (json.RawMessage, error) {
|
2025-01-02 22:57:51 +08:00
|
|
|
// 生成url
|
2025-01-05 23:12:05 +08:00
|
|
|
url, err := makeURL(dev, location_id, weather_type_name)
|
2025-01-02 22:57:51 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// 发送请求, 获取数据
|
|
|
|
resp, err := http.Get(url)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
// 读取数据
|
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// 返回数据
|
|
|
|
return body, nil
|
|
|
|
}
|