- 饿百的消息,先QueryUnescape再使用
This commit is contained in:
@@ -113,16 +113,12 @@ func (a *API) unmarshalData(cmd string, data []byte, msg interface{}) (callbackR
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) CheckCallbackValidation(request *http.Request) (callbackResponse *CallbackResponse) {
|
func (a *API) CheckCallbackValidation(cmd string, params url.Values) (callbackResponse *CallbackResponse) {
|
||||||
params := make(url.Values)
|
|
||||||
for k, v := range request.PostForm {
|
|
||||||
params[k] = v
|
|
||||||
}
|
|
||||||
sign := a.signParams(params)
|
sign := a.signParams(params)
|
||||||
if sign != request.FormValue(signKey) {
|
if sign != params.Get(signKey) {
|
||||||
msg := fmt.Sprintf("Signature is not ok, mine:%v, get:%v", sign, request.FormValue(signKey))
|
msg := fmt.Sprintf("Signature is not ok, mine:%v, get:%v", sign, params.Get(signKey))
|
||||||
baseapi.SugarLogger.Info(msg)
|
baseapi.SugarLogger.Info(msg)
|
||||||
return a.Err2CallbackResponse(GetCmd(request), errors.New(msg), nil)
|
return a.Err2CallbackResponse(cmd, errors.New(msg), nil)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -130,15 +126,20 @@ func (a *API) CheckCallbackValidation(request *http.Request) (callbackResponse *
|
|||||||
func (a *API) GetCallbackMsg(request *http.Request) (msg *CallbackMsg, callbackResponse *CallbackResponse) {
|
func (a *API) GetCallbackMsg(request *http.Request) (msg *CallbackMsg, callbackResponse *CallbackResponse) {
|
||||||
err := request.ParseForm()
|
err := request.ParseForm()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if callbackResponse = a.CheckCallbackValidation(request); callbackResponse != nil {
|
params := make(url.Values)
|
||||||
return nil, callbackResponse
|
for k := range request.PostForm {
|
||||||
|
decodedValue, _ := url.QueryUnescape(request.PostFormValue(k))
|
||||||
|
params.Set(k, decodedValue)
|
||||||
}
|
}
|
||||||
msg = new(CallbackMsg)
|
msg = new(CallbackMsg)
|
||||||
if callbackResponse = a.unmarshalData(GetCmd(request), []byte(request.FormValue("body")), &msg.Body); callbackResponse != nil {
|
msg.Cmd = GetCmd(request)
|
||||||
|
if callbackResponse = a.CheckCallbackValidation(msg.Cmd, params); callbackResponse != nil {
|
||||||
return nil, callbackResponse
|
return nil, callbackResponse
|
||||||
}
|
}
|
||||||
msg.Cmd = GetCmd(request)
|
if callbackResponse = a.unmarshalData(msg.Cmd, []byte(params.Get("body")), &msg.Body); callbackResponse != nil {
|
||||||
msg.Timestamp = utils.Str2Int64(utils.Interface2String(request.FormValue("timestamp")))
|
return nil, callbackResponse
|
||||||
|
}
|
||||||
|
msg.Timestamp = utils.Str2Int64(utils.Interface2String(params.Get("timestamp")))
|
||||||
var tmpObj interface{}
|
var tmpObj interface{}
|
||||||
switch msg.Cmd {
|
switch msg.Cmd {
|
||||||
case CmdOrderPartRefund:
|
case CmdOrderPartRefund:
|
||||||
@@ -158,6 +159,7 @@ func (a *API) GetCallbackMsg(request *http.Request) (msg *CallbackMsg, callbackR
|
|||||||
return nil, a.Err2CallbackResponse("", err, nil)
|
return nil, a.Err2CallbackResponse("", err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCmd(request *http.Request) string {
|
func GetCmd(request *http.Request) (cmd string) {
|
||||||
return request.FormValue("cmd")
|
cmd, _ = url.QueryUnescape(request.FormValue("cmd"))
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user