| | |
| | | "car-service/extend/code" |
| | | "car-service/extend/util" |
| | | "encoding/json" |
| | | "fmt" |
| | | "github.com/astaxie/beego" |
| | | "net/http" |
| | | "github.com/robfig/cron" |
| | |
| | | beego.Controller |
| | | } |
| | | |
| | | func init() { |
| | | getRestrictionInfo() |
| | | } |
| | | |
| | | // @Title 查询限行尾号 |
| | | // @Description 查询限行尾号 |
| | | // @Success 200 {object} controllers.RestrictionResult |
| | | // @Failure 403 {string} json "" |
| | | // @router /spaceNo [get] |
| | | // @router /restriction [get] |
| | | func (c *RestrictionController) Restriction() { |
| | | resp := code.Code{} |
| | | if todayRes !=nil { |
| | |
| | | } else { |
| | | resp.Success= false |
| | | resp.Status= http.StatusBadRequest |
| | | resp.Data= nil |
| | | resp.Data= "数据请求失败,请稍后重试" |
| | | } |
| | | c.Data["json"] = resp |
| | | c.ServeJSON() |
| | |
| | | |
| | | func Schedule() { |
| | | c := cron.New() |
| | | //每小时监测一次是否过期 |
| | | c.AddFunc("0 0 * * * ?", func() { |
| | | //每天凌晨5点执行一次,获取当日数据 |
| | | c.AddFunc("0 0 1 * * ?", func() { |
| | | todayRes = nil |
| | | getRestrictionInfo() |
| | | }) |
| | |
| | | Date string `json:"date"` |
| | | Week string `json:"week"` |
| | | CityName string `json:"cityName"` |
| | | IsXianXing int `json:"isxianxing"` |
| | | XxWeiHao []int `json:"xxWeiHao"` |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | func getRestrictionInfo() { |
| | | juHeAppKey := "" |
| | | juHeAppKey := beego.AppConfig.String("juheweihaokey") |
| | | url := "http://v.juhe.cn/xianxing/index?key="+ juHeAppKey +"&city=beijing&type=1" |
| | | b, err := util.DoPostRequest(url, util.CONTENT_TYPE_JSON, nil, nil, nil) |
| | | if err != nil { |
| | | fmt.Println("err:", err) |
| | | return |
| | | } |
| | | var result JuHeResult |
| | | err = json.Unmarshal(b, &result) |
| | | if err != nil { |
| | | fmt.Println("unmarshal err:", err) |
| | | return |
| | | } |
| | | if result.ErrorCode == 0 { |
| | |
| | | Date: result.Result.Date, |
| | | Week: result.Result.Week, |
| | | CityName: result.Result.CityName, |
| | | IsXianXing: result.Result.IsXianXing, |
| | | XxWeiHao: result.Result.XXWeiHao, |
| | | } |
| | | } |