diff --git a/resp/response.go b/resp/response.go index 7a40d78b35fb5c71f35d06a461c4f5bfbb9bc769..1f4966db85ac340859b37f398c987daf424e8bf9 100644 --- a/resp/response.go +++ b/resp/response.go @@ -4,6 +4,7 @@ import ( "encoding/json" "git.hilo.cn/hilo-common/mycontext" "git.hilo.cn/hilo-common/mylogrus" + "git.hilo.cn/hilo-common/utils" "github.com/gin-gonic/gin" "hilo-group/myerr" "net/http" @@ -16,6 +17,7 @@ type Response struct { MessageData interface{} `json:"messageData"` // 消息详情 OperationMessage interface{} `json:"operationMessage"` // 操作消息 Data interface{} `json:"data"` // 数据 + Edata interface{} `json:"edata"` // 数据 } /** @@ -30,7 +32,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) @@ -116,15 +123,21 @@ type Page struct { func ResponsePageOk(c *gin.Context, data interface{}, total uint, index int) { // always return http.StatusOK + pageData := Page{ + Total: total, + Index: index, + Data: data, + } response := Response{ Code: myerr.GetSuccessCode(), Message: myerr.GetSuccessMsg(), OperationMessage: myerr.GetSuccessMsg(), - Data: Page{ - Total: total, - Index: index, - 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 } printResponseBody(c, &response) @@ -149,15 +162,21 @@ func ResponsePageBaseOk(c *gin.Context, data interface{}, nextPageIndex int, has if data == nil { data = make([]interface{}, 0) } + pageData := PageRespBase{ + NextPageIndex: nextPageIndex, + HasNextPage: hasNextPage, + Data: data, + } response := Response{ Code: myerr.GetSuccessCode(), Message: myerr.GetSuccessMsg(), OperationMessage: myerr.GetSuccessMsg(), - Data: 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 112da38ef81acf05a3bb17e57a448890b2430984..e16f1f988f11b86cc461b742d1387230d686c72d 100644 --- a/route/middleHandle.go +++ b/route/middleHandle.go @@ -137,8 +137,10 @@ func LoggerHandle(c *gin.Context) { // 加密Handle func EncryptHandle(c *gin.Context) { - if value, ok := c.Get(mycontext.APP_VERSION); ok { - if high, _ := utils.CompareVersion(value.(string), "> 3.9.0"); high { + 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) } }