更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -12,16 +12,10 @@ import (
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// BackendWeatherController 天气实时数据代理。
|
||||
//
|
||||
// 数据源:中国天气网 d1.weather.com.cn(国内真实数据)。
|
||||
// 该接口有防盗链,浏览器直连会被 Referer 校验拦掉、也会跨域,
|
||||
// 因此由服务端带 Referer 抓取后统一返回 JSON。
|
||||
type BackendWeatherController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// 常用城市编码(中国天气网 citycode),未命中时按入参 code 直取
|
||||
var weatherCityCodes = map[string]string{
|
||||
"连云港": "101191001",
|
||||
"南京": "101190101",
|
||||
@@ -45,7 +39,6 @@ var weatherCityCodes = map[string]string{
|
||||
|
||||
const defaultWeatherCity = "连云港"
|
||||
|
||||
// Now GET /backend/weather/now?city=连云港 或 ?code=101191201
|
||||
func (c *BackendWeatherController) Now() {
|
||||
city := strings.TrimSpace(c.GetString("city"))
|
||||
code := strings.TrimSpace(c.GetString("code"))
|
||||
@@ -61,12 +54,10 @@ func (c *BackendWeatherController) Now() {
|
||||
ts := strconv.FormatInt(time.Now().UnixMilli(), 10)
|
||||
referer := "https://www.weather.com.cn/weather1d/" + code + ".shtml"
|
||||
|
||||
// 主数据源:dingzhi(含天气现象 + 气温)。中国天气网已拒绝 http 明文连接,必须走 https。
|
||||
info := weatherFetchJSON(client, "https://d1.weather.com.cn/dingzhi/"+code+".html?_="+ts, referer)
|
||||
if wi, ok := info["weatherinfo"].(map[string]interface{}); ok {
|
||||
info = wi
|
||||
}
|
||||
// 兜底:sk_2d(实况气温,无天气现象)
|
||||
if len(info) == 0 {
|
||||
info = weatherFetchJSON(client, "https://d1.weather.com.cn/sk_2d/"+code+".html?_="+ts, referer)
|
||||
}
|
||||
@@ -99,7 +90,6 @@ func (c *BackendWeatherController) Now() {
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
// weatherFetchJSON 带 Referer/UA 抓取中国天气网页面并解析其中的 JSON 对象
|
||||
func weatherFetchJSON(client *http.Client, url, referer string) map[string]interface{} {
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
@@ -120,8 +110,6 @@ func weatherFetchJSON(client *http.Client, url, referer string) map[string]inter
|
||||
return nil
|
||||
}
|
||||
|
||||
// 返回体形如:var cityDZ101191001 ={"weatherinfo":{...}};var alarmDZ101191001 ={"w":[]}
|
||||
// 从第一个 '{' 起用 json.Decoder 只解出第一个完整对象(正则贪婪匹配会跨越多个对象导致解析失败)
|
||||
idx := bytes.IndexByte(body, '{')
|
||||
if idx < 0 {
|
||||
return nil
|
||||
@@ -133,7 +121,6 @@ func weatherFetchJSON(client *http.Client, url, referer string) map[string]inter
|
||||
return out
|
||||
}
|
||||
|
||||
// weatherStr 按候选字段顺序取第一个非空字符串值
|
||||
func weatherStr(m map[string]interface{}, keys ...string) string {
|
||||
for _, k := range keys {
|
||||
if v, ok := m[k]; ok {
|
||||
|
||||
Reference in new issue
Block a user