- callback sign.

This commit is contained in:
gazebo
2018-09-27 21:00:02 +08:00
parent a59d8a105e
commit 8b2b29d69d
3 changed files with 29 additions and 3 deletions

View File

@@ -15,6 +15,7 @@ type CallbackResponse struct {
Sign string `json:"sign"`
Source string `json:"source"`
Ticket string `json:"ticket"`
Encrypt string `json:"encrypt"`
Timestamp int64 `json:"timestamp"`
Version int `json:"version"`
Body *ResponseResult `json:"body"`
@@ -54,6 +55,8 @@ func (a *API) Err2CallbackResponse(cmd string, err error, data interface{}) *Cal
"ticket": []string{response.Ticket},
"source": []string{response.Source},
"body": []string{string(utils.MustMarshal(response.Body))},
secretKey: []string{a.secret},
"encrypt": []string{""},
}
response.Sign = a.signParams(params)
return response
@@ -68,7 +71,12 @@ func (a *API) unmarshalData(cmd string, data []byte, msg interface{}) (callbackR
}
func (a *API) CheckCallbackValidation(request *http.Request) (callbackResponse *CallbackResponse) {
sign := a.signParams(request.PostForm)
params := make(url.Values)
for k, v := range request.PostForm {
params[k] = v
}
params[secretKey] = []string{a.secret}
sign := a.signParams(params)
if sign != request.FormValue(signKey) {
msg := fmt.Sprintf("Signature is not ok, mine:%v, get:%v", sign, request.FormValue(signKey))
baseapi.SugarLogger.Info(msg)