Przeglądaj źródła

加入更多的日志

hebinlong 4 lat temu
rodzic
commit
d67df3e655

+ 6 - 0
router/RouterManchong/handler.go

@@ -2,6 +2,7 @@ package RouterManchong
 
 import (
 	"github.com/gin-gonic/gin"
+	"manchong/utils"
 )
 
 func Handler(ctx *gin.Context) {
@@ -19,6 +20,11 @@ func Handler(ctx *gin.Context) {
 		MSGBODY: req,
 	}
 	err := ctx.BindJSON(&temp)
+
+	defer func() {
+		utils.DefaultLogger().Infof("Header:%#v Requests:%#v Response:%#v", header, req, resp)
+	}()
+
 	temp.MSGBODY = resp
 	if err != nil {
 		resp.RESP.RCODE = "306"

+ 3 - 3
router/RouterManchong/req.go

@@ -24,17 +24,17 @@ func (r *reqBody) check(appid string) (string, error) {
 	}
 	now := time.Now().UnixNano() / 1e6
 	if t > now+5*60*1000 || t < now-5*60*1000 {
-		return "14", errors.New("TIMESTAMP超过时限")
+		return "14", errors.New("MsgBody Check TIMESTAMP超过时限")
 	}
 	appc, ok := manchong.CFG.Users[appid]
 	if !ok {
-		return "09", errors.New("APPID已经失效")
+		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("签名验证失败")
+		return "08", errors.New("MsgBody Check 签名验证失败")
 	}
 	return "00", nil
 }

+ 2 - 0
router/RouterManchong/resp.go

@@ -38,6 +38,7 @@ func (r *respBody) getData() {
 	if err != nil {
 		r.RESP.RCODE = "99"
 		r.RESP.RMSG = err.Error()
+		utils.DefaultLogger().Errorf("Response getData Error:%s", err.Error())
 		return
 	}
 	for result.Next() {
@@ -46,6 +47,7 @@ func (r *respBody) getData() {
 		if err != nil {
 			r.RESP.RCODE = "99"
 			r.RESP.RMSG = err.Error()
+			utils.DefaultLogger().Errorf("Response getData Error:%s", err.Error())
 			return
 		}
 		r.CONTENT = append(r.CONTENT, par)

+ 4 - 4
router/RouterManchong/template.go

@@ -19,7 +19,7 @@ type head struct {
 func (h *head) check() (string, error) {
 	n := len(h.TIMESTAMP)
 	if n < 15 {
-		return "14", errors.New("TIMESTAMP超过时限")
+		return "14", errors.New("Header Check TIMESTAMP超过时限 ")
 	}
 	s := h.TIMESTAMP[:14] + "." + h.TIMESTAMP[14:]
 	t, err := time.ParseInLocation("20060102150405.999999999", s, time.Local)
@@ -30,17 +30,17 @@ func (h *head) check() (string, error) {
 	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超过时限")
+		return "14", errors.New("Header Check TIMESTAMP超过时限 ")
 	}
 	appc, ok := manchong.CFG.Users[h.APPID]
 	if !ok {
-		return "09", errors.New("APPID已经失效")
+		return "09", errors.New("Header Check 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 "08", errors.New("Header Check 签名验证失败 ")
 	}
 	return "00", nil
 }