weather/qweather/url.go

51 lines
977 B
Go
Raw Normal View History

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
func makeURL(dev bool, location_id, weather_type_id int) (rv string, rer error) {
// 获取位置信息
localtion := model.Localtion{ID: location_id}
err := localtion.GetLocaltionByID()
if err != nil {
return "", err
}
// 获取天气类型
weatherType := model.WeatherType{Id: weather_type_id}
err = weatherType.GetWeatherTypeByID()
if err != nil {
return "", err
}
if dev {
rv = c_DEVURL
} else {
rv = c_PROURL
}
rv += c_VERSION
rv += weatherType.Name
rv += "?key="
if dev {
rv += c_DEVKEY
} else {
rv += c_PROKEY
}
rv += "&location="
rv += localtion.Code
return
}