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