package RouterManchong import ( "crypto/md5" "encoding/hex" "errors" "manchong" "time" ) type head struct { VERSION string `json:"VERSION"` TIMESTAMP string `json:"TIMESTAMP"` SEQNO string `json:"SEQNO"` APPID string `json:"APPID"` SECERTKEY string `json:"SECERTKEY"` } func (h *head) check() (string, error) { n := len(h.TIMESTAMP) if n < 15 { return "14", errors.New("TIMESTAMP超过时限") } s := h.TIMESTAMP[:14] + "." + h.TIMESTAMP[14:] t, err := time.ParseInLocation("20060102150405.999999999", s, time.Local) if err != nil { return "99", err } bigt := time.Now().Add(5 * time.Minute) lowt := time.Now().Add(-5 * time.Minute) if t.Before(lowt) || t.After(bigt) { return "14", errors.New("TIMESTAMP超过时限") } appc, ok := manchong.CFG.Users[h.APPID] if !ok { return "09", errors.New("APPID已经失效") } m5 := md5.New() m5.Write([]byte(h.TIMESTAMP + h.SEQNO + h.APPID + appc)) s = hex.EncodeToString(m5.Sum(nil)) if s != h.SECERTKEY { return "08", errors.New("签名验证失败") } return "00", nil } type template struct { HEADER *head `json:"HEADER"` MSGBODY interface{} `json:"MSGBODY"` }