diff --git a/resp/response.go b/resp/response.go index 2530a0dfa452f8b5eede3f2ae2a729d2c7c2e7e5..e432d1bbdbc04f5a06c37c3c91de84e0b1b1f9c6 100755 --- a/resp/response.go +++ b/resp/response.go @@ -3,6 +3,7 @@ package resp import ( "encoding/json" "git.hilo.cn/hilo-common/mycontext" + "git.hilo.cn/hilo-common/utils" "github.com/gin-gonic/gin" "hilo-user/myerr" "hilo-user/req" @@ -15,6 +16,7 @@ type Response struct { MessageData interface{} `json:"messageData"` // 消息详情 OperationMessage interface{} `json:"operationMessage"` // 操作消息 Data interface{} `json:"data"` // 数据 + Edata interface{} `json:"edata"` // 加密数据 } type GameResponse struct { @@ -36,7 +38,12 @@ func ResponseOk(c *gin.Context, data interface{}) { Code: myerr.GetSuccessCode(), Message: myerr.GetSuccessMsg(), OperationMessage: myerr.GetSuccessMsg(), - Data: data, + } + if _, ok := c.Get(mycontext.InnerEncrypt); ok { + //response.Edata = utils.EncryptionData(data, []byte("484194d4d0f968a7")) + response.Edata = utils.EncryptionData(data, []byte("hilo!@#$%^&*()_+")) + } else { + response.Data = data } printResponseBody(c, &response) @@ -50,15 +57,21 @@ func ResponsePageBaseOk(c *gin.Context, data interface{}, nextPageIndex int, has if data == nil { data = make([]interface{}, 0) } + pageData := req.PageRespBase{ + NextPageIndex: nextPageIndex, + HasNextPage: hasNextPage, + Data: data, + } response := Response{ Code: myerr.GetSuccessCode(), Message: myerr.GetSuccessMsg(), OperationMessage: myerr.GetSuccessMsg(), - Data: req.PageRespBase{ - NextPageIndex: nextPageIndex, - HasNextPage: hasNextPage, - Data: data, - }, + } + if _, ok := c.Get(mycontext.InnerEncrypt); ok { + //response.Edata = utils.EncryptionData(data, []byte("484194d4d0f968a7")) + response.Edata = utils.EncryptionData(pageData, []byte("hilo!@#$%^&*()_+")) + } else { + response.Data = pageData } c.JSON(http.StatusOK, response) } diff --git a/route/middleHandle.go b/route/middleHandle.go index 14425535d53e42b8761d6e1592b664aa7c1056b2..de57538567a480c7b5ae72c8286d31e8360bed77 100755 --- a/route/middleHandle.go +++ b/route/middleHandle.go @@ -5,6 +5,7 @@ import ( "git.hilo.cn/hilo-common/mycontext" "git.hilo.cn/hilo-common/mylogrus" "git.hilo.cn/hilo-common/resource/config" + "git.hilo.cn/hilo-common/utils" "github.com/gin-gonic/gin" "hilo-user/myerr/bizerr" "hilo-user/req" @@ -133,3 +134,15 @@ func LoggerHandle(c *gin.Context) { latency := end.Sub(start) mycontext.CreateMyContext(c.Keys).Log.Infof("request end fullPath:%v,url:%v, method: %v, traceId:%v, latency:%v userId:%v", c.FullPath(), reqUri, method, traceId, latency, userId) } + +// 加密Handle +func EncryptHandle(c *gin.Context) { + header := c.Request.Header + appVersion := header.Get("Appversion") + if len(appVersion) > 0 { + if high, _ := utils.CompareVersion(appVersion, "> 3.9.0"); high { + c.Set(mycontext.InnerEncrypt, true) + } + } + c.Next() +} diff --git a/route/router.go b/route/router.go index b88d04b7ba37f333d1f3968bde1c8406c404f4ad..fb972135486992952ccc87cb32648b9dbd907295 100755 --- a/route/router.go +++ b/route/router.go @@ -28,8 +28,8 @@ func InitRouter() *gin.Engine { { user.GET("/nameplate", wrapper(user_r.UserNameplate)) user.GET("/bag/:resType", wrapper(user_r.UserBag)) - user.GET("/detail", wrapper(user_r.UserDetail)) - user.GET("/detail/:userExternalId", wrapper(user_r.UserDetailByExternalId)) + user.GET("/detail", EncryptHandle, wrapper(user_r.UserDetail)) + user.GET("/detail/:userExternalId", EncryptHandle, wrapper(user_r.UserDetailByExternalId)) } cp := v2.Group("/cp") {