12345678910111213141516171819202122232425262728293031323334353637383940 |
- package RouterManchong
- import (
- "crypto/md5"
- "encoding/hex"
- "errors"
- "fmt"
- "manchong"
- "strconv"
- "time"
- )
- type reqBody struct {
- CONTENT struct {
- SIGN string `json:"SIGN"`
- TIMESTAMP string `json:"TIMESTAMP"`
- } `json:"CONTENT"`
- }
- func (r *reqBody) check(appid string) (string, error) {
- t, err := strconv.ParseInt(r.CONTENT.TIMESTAMP, 10, 0)
- if err != nil {
- return "11", err
- }
- now := time.Now().UnixNano() / 1e6
- if t > now+5*60*1000 || t < now-5*60*1000 {
- return "14", errors.New("MsgBody Check TIMESTAMP超过时限")
- }
- appc, ok := manchong.CFG.Users[appid]
- if !ok {
- return "09", errors.New("MsgBody Check APPID已经失效")
- }
- m5 := md5.New()
- m5.Write([]byte(fmt.Sprintf("%s%s", appc, r.CONTENT.TIMESTAMP)))
- str := hex.EncodeToString(m5.Sum(nil))
- if str != r.CONTENT.SIGN {
- return "08", errors.New("MsgBody Check 签名验证失败")
- }
- return "00", nil
- }
|