2025-01-02 22:57:51 +08:00
|
|
|
package qweather
|
|
|
|
|
|
|
|
import (
|
|
|
|
"cc/db/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// 开发者密钥
|
|
|
|
c_DEVKEY = "ecac5888fd314a5d883c0f9126145969"
|
|
|
|
// 生产环境密钥
|
|
|
|
c_PROKEY = "ecac5888fd314a5d883c0f9126145969"
|
|
|
|
// 开发环境url
|
|
|
|
c_DEVURL = "https://devapi.qweather.com/"
|
|
|
|
// 生产环境url
|
|
|
|
c_PROURL = "https://api.qweather.com/"
|
|
|
|
// 版本号
|
|
|
|
c_VERSION = "v7/weather/"
|
|
|
|
)
|
|
|
|
|
|
|
|
// makeURL 生成url
|
2025-01-05 23:12:05 +08:00
|
|
|
func makeURL(dev bool, location_id int, weather_type_name string) (rv string, rer error) {
|
2025-01-02 22:57:51 +08:00
|
|
|
// 获取位置信息
|
|
|
|
localtion := model.Localtion{ID: location_id}
|
|
|
|
err := localtion.GetLocaltionByID()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
if dev {
|
|
|
|
rv = c_DEVURL
|
|
|
|
} else {
|
|
|
|
rv = c_PROURL
|
|
|
|
}
|
|
|
|
rv += c_VERSION
|
2025-01-05 23:12:05 +08:00
|
|
|
rv += weather_type_name
|
2025-01-02 22:57:51 +08:00
|
|
|
rv += "?key="
|
|
|
|
if dev {
|
|
|
|
rv += c_DEVKEY
|
|
|
|
} else {
|
|
|
|
rv += c_PROKEY
|
|
|
|
}
|
|
|
|
rv += "&location="
|
|
|
|
rv += localtion.Code
|
|
|
|
return
|
|
|
|
}
|