|
@@ -2,6 +2,7 @@ package controllers
|
|
|
|
|
|
import (
|
|
import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
|
+ "fmt"
|
|
"net/http"
|
|
"net/http"
|
|
"net/url"
|
|
"net/url"
|
|
"strings"
|
|
"strings"
|
|
@@ -26,8 +27,8 @@ func (this *BaseCommonController) Prepare() {
|
|
} else {
|
|
} else {
|
|
requestBody, _ = url.QueryUnescape(string(this.Ctx.Input.RequestBody))
|
|
requestBody, _ = url.QueryUnescape(string(this.Ctx.Input.RequestBody))
|
|
}
|
|
}
|
|
- ip := this.Ctx.Input.IP()
|
|
|
|
- apiLog.Println("请求地址:", this.Ctx.Input.URI(), "RequestBody:", requestBody, "IP:", ip)
|
|
|
|
|
|
+ //ip := this.Ctx.Input.IP()
|
|
|
|
+ //apiLog.Println("请求地址:", this.Ctx.Input.URI(), "RequestBody:", requestBody, "IP:", ip)
|
|
|
|
|
|
authorization := this.Ctx.Input.Header("Authorization")
|
|
authorization := this.Ctx.Input.Header("Authorization")
|
|
if authorization == "" {
|
|
if authorization == "" {
|
|
@@ -40,41 +41,8 @@ func (this *BaseCommonController) Prepare() {
|
|
if strings.Contains(uri, "/api/wechat/login") {
|
|
if strings.Contains(uri, "/api/wechat/login") {
|
|
authorization = ""
|
|
authorization = ""
|
|
}
|
|
}
|
|
- if authorization != "" {
|
|
|
|
- //session, err := models.GetSessionByToken(authorization)
|
|
|
|
- //if err != nil {
|
|
|
|
- // if err.Error() == utils.ErrNoRow() {
|
|
|
|
- // this.JSON(models.BaseResponse{Ret: 408, Msg: "信息已变更,请重新登陆!", ErrMsg: "Token 信息已变更:Token: " + authorization}, false, false)
|
|
|
|
- // this.StopRun()
|
|
|
|
- // return
|
|
|
|
- // }
|
|
|
|
- // this.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "获取用户信息异常,Eerr:" + err.Error()}, false, false)
|
|
|
|
- // this.StopRun()
|
|
|
|
- // return
|
|
|
|
- //}
|
|
|
|
- //if session == nil {
|
|
|
|
- // this.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "sesson is empty "}, false, false)
|
|
|
|
- // this.StopRun()
|
|
|
|
- // return
|
|
|
|
- //}
|
|
|
|
- //wxUser, err := models.GetWxUserItemByUserId(session.UserId)
|
|
|
|
- //if err != nil {
|
|
|
|
- // if err.Error() == utils.ErrNoRow() {
|
|
|
|
- // this.JSON(models.BaseResponse{Ret: 408, Msg: "信息已变更,请重新登陆!", ErrMsg: "获取admin 信息失败 " + strconv.Itoa(session.UserId)}, false, false)
|
|
|
|
- // this.StopRun()
|
|
|
|
- // return
|
|
|
|
- // }
|
|
|
|
- // this.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "获取wx_user信息异常,Eerr:" + err.Error()}, false, false)
|
|
|
|
- // this.StopRun()
|
|
|
|
- // return
|
|
|
|
- //}
|
|
|
|
- //if wxUser == nil {
|
|
|
|
- // this.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "admin is empty "}, false, false)
|
|
|
|
- // this.StopRun()
|
|
|
|
- // return
|
|
|
|
- //}
|
|
|
|
- //this.User = wxUser
|
|
|
|
- }
|
|
|
|
|
|
+ ip := this.Ctx.Input.IP()
|
|
|
|
+ utils.ApiLog.Info("uri:%s, requestBody:%s, responseBody:%s, ip:%s", this.Ctx.Input.URI(), requestBody, ip)
|
|
//this.Token = authorization
|
|
//this.Token = authorization
|
|
}
|
|
}
|
|
|
|
|
|
@@ -115,10 +83,53 @@ func (c *BaseCommonController) JSON(data interface{}, hasIndent bool, coding boo
|
|
}
|
|
}
|
|
ip := c.Ctx.Input.IP()
|
|
ip := c.Ctx.Input.IP()
|
|
requestBody, _ := url.QueryUnescape(string(c.Ctx.Input.RequestBody))
|
|
requestBody, _ := url.QueryUnescape(string(c.Ctx.Input.RequestBody))
|
|
- apiLog.Println("请求地址:", c.Ctx.Input.URI(), "Authorization:", c.Ctx.Input.Header("Authorization"), "RequestBody:", requestBody, "ResponseBody", string(content), "IP:", ip)
|
|
|
|
|
|
+ c.logUri(content, requestBody, ip)
|
|
|
|
+ //apiLog.Println("请求地址:", c.Ctx.Input.URI(), "Authorization:", c.Ctx.Input.Header("Authorization"), "RequestBody:", requestBody, "ResponseBody", string(content), "IP:", ip)
|
|
|
|
|
|
if coding {
|
|
if coding {
|
|
content = []byte(utils.StringsToJSON(string(content)))
|
|
content = []byte(utils.StringsToJSON(string(content)))
|
|
}
|
|
}
|
|
return c.Ctx.Output.Body(content)
|
|
return c.Ctx.Output.Body(content)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func (c *BaseCommonController) logUri(respContent []byte, requestBody, ip string) {
|
|
|
|
+ authorization := ""
|
|
|
|
+ method := c.Ctx.Input.Method()
|
|
|
|
+ uri := c.Ctx.Input.URI()
|
|
|
|
+ //fmt.Println("Url:", uri)
|
|
|
|
+ if method != "HEAD" {
|
|
|
|
+ if method == "POST" || method == "GET" {
|
|
|
|
+ authorization = c.Ctx.Input.Header("authorization")
|
|
|
|
+ if authorization == "" {
|
|
|
|
+ authorization = c.Ctx.Input.Header("Authorization")
|
|
|
|
+ }
|
|
|
|
+ if authorization == "" {
|
|
|
|
+ newAuthorization := c.GetString("authorization")
|
|
|
|
+ if newAuthorization != `` {
|
|
|
|
+ authorization = "authorization=" + newAuthorization
|
|
|
|
+ } else {
|
|
|
|
+ newAuthorization = c.GetString("Authorization")
|
|
|
|
+ authorization = "authorization=" + newAuthorization
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if strings.Contains(authorization, ";") {
|
|
|
|
+ authorization = strings.Replace(authorization, ";", "$", 1)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if authorization == "" {
|
|
|
|
+ strArr := strings.Split(uri, "?")
|
|
|
|
+ for k, v := range strArr {
|
|
|
|
+ fmt.Println(k, v)
|
|
|
|
+ }
|
|
|
|
+ if len(strArr) > 1 {
|
|
|
|
+ authorization = strArr[1]
|
|
|
|
+ authorization = strings.Replace(authorization, "Authorization", "authorization", -1)
|
|
|
|
+ fmt.Println(authorization)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ utils.ApiLog.Info("uri:%s, authorization:%s, requestBody:%s, responseBody:%s, ip:%s", c.Ctx.Input.URI(), authorization, requestBody, respContent, ip)
|
|
|
|
+ return
|
|
|
|
+}
|