- call parseForm explicit for http.Response
This commit is contained in:
@@ -18,7 +18,7 @@ func init() {
|
|||||||
sugarLogger = logger.Sugar()
|
sugarLogger = logger.Sugar()
|
||||||
baseapi.Init(sugarLogger)
|
baseapi.Init(sugarLogger)
|
||||||
|
|
||||||
api = NewWithAgentID(239461075, "ding7ab5687f3784a8db", "ding7iu9cptairtcls0c", "LWrZAFeqUfuVv7n_tc8vPpCAx6PT4CwManx2XCVhJOqGsx2L5XCDuX1sAN_JtvsI")
|
api = NewWithAgentID(241047291, "ding7ab5687f3784a8db", "dingpx4hcf55zb4ubewg", "1zooB4bmEXPesdwb1ElWASVQ1vinOSZM-1XCUFrrSjHsNAId1UuVCT5tmHSmg5_V")
|
||||||
api.RetrieveToken()
|
api.RetrieveToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,8 @@ 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) {
|
||||||
request.ParseForm()
|
err := request.ParseForm()
|
||||||
|
if err == nil {
|
||||||
if callbackResponse = a.CheckCallbackValidation(request); callbackResponse != nil {
|
if callbackResponse = a.CheckCallbackValidation(request); callbackResponse != nil {
|
||||||
return nil, callbackResponse
|
return nil, callbackResponse
|
||||||
}
|
}
|
||||||
@@ -96,3 +97,5 @@ func (a *API) GetCallbackMsg(request *http.Request) (msg *CallbackMsg, callbackR
|
|||||||
msg.Timestamp = utils.Str2Int64(utils.Interface2String(request.FormValue("timestamp")))
|
msg.Timestamp = utils.Str2Int64(utils.Interface2String(request.FormValue("timestamp")))
|
||||||
return msg, nil
|
return msg, nil
|
||||||
}
|
}
|
||||||
|
return nil, a.Err2CallbackResponse("", err, nil)
|
||||||
|
}
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ func Err2CallbackResponse(err error, data string) *CallbackResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) CheckCallbackValidation(request *http.Request) (callbackResponse *CallbackResponse) {
|
func (a *API) CheckCallbackValidation(request *http.Request) (callbackResponse *CallbackResponse) {
|
||||||
request.ParseForm()
|
err := request.ParseForm()
|
||||||
|
if err == nil {
|
||||||
sign := a.signParams(request.PostForm)
|
sign := a.signParams(request.PostForm)
|
||||||
if sign != request.FormValue(signKey) {
|
if sign != request.FormValue(signKey) {
|
||||||
baseapi.SugarLogger.Infof("Signature is not ok, mine:%v, get:%v", sign, request.FormValue(signKey))
|
baseapi.SugarLogger.Infof("Signature is not ok, mine:%v, get:%v", sign, request.FormValue(signKey))
|
||||||
@@ -67,6 +68,8 @@ func (a *API) CheckCallbackValidation(request *http.Request) (callbackResponse *
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
return Err2CallbackResponse(err, "")
|
||||||
|
}
|
||||||
|
|
||||||
func (a *API) GetOrderCallbackMsg(request *http.Request) (orderMsg *CallbackOrderMsg, callbackResponse *CallbackResponse) {
|
func (a *API) GetOrderCallbackMsg(request *http.Request) (orderMsg *CallbackOrderMsg, callbackResponse *CallbackResponse) {
|
||||||
if callbackResponse = a.CheckCallbackValidation(request); callbackResponse != nil {
|
if callbackResponse = a.CheckCallbackValidation(request); callbackResponse != nil {
|
||||||
|
|||||||
@@ -52,14 +52,16 @@ func Err2CallbackResponse(err error, data string) *CallbackResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) GetCallbackMsg(request *http.Request) (msg *CallbackMsg, callbackResponse *CallbackResponse) {
|
func (a *API) GetCallbackMsg(request *http.Request) (msg *CallbackMsg, callbackResponse *CallbackResponse) {
|
||||||
data := utils.URLValues2Map(request.PostForm)
|
err := request.ParseForm()
|
||||||
|
if err == nil {
|
||||||
|
data := utils.URLValues2Map(request.Form)
|
||||||
if dataSign, ok := data[signKey]; ok {
|
if dataSign, ok := data[signKey]; ok {
|
||||||
fullURL := strings.TrimRight(a.callbackURL+request.URL.Path, "/")
|
fullURL := strings.TrimRight(a.callbackURL+request.URL.Path, "/")
|
||||||
sign := a.signParams(fullURL+"?", data)
|
sign := a.signParams(fullURL+"?", data)
|
||||||
if sign != dataSign.(string) {
|
if sign != dataSign.(string) {
|
||||||
baseapi.SugarLogger.Debugf("mtwm GetCallbackMsg my sign:%v, data sign:%v", sign, dataSign.(string))
|
baseapi.SugarLogger.Debugf("mtwm GetCallbackMsg my sign:%v, data sign:%v", sign, dataSign.(string))
|
||||||
return nil, SignatureIsNotOk
|
callbackResponse = SignatureIsNotOk
|
||||||
}
|
} else {
|
||||||
cmd := strings.Trim(request.URL.EscapedPath(), "/")
|
cmd := strings.Trim(request.URL.EscapedPath(), "/")
|
||||||
cmd = cmd[strings.LastIndex(cmd, "/")+1:]
|
cmd = cmd[strings.LastIndex(cmd, "/")+1:]
|
||||||
msg = &CallbackMsg{
|
msg = &CallbackMsg{
|
||||||
@@ -76,7 +78,13 @@ func (a *API) GetCallbackMsg(request *http.Request) (msg *CallbackMsg, callbackR
|
|||||||
}
|
}
|
||||||
msg.Data.Set(k, v.(string))
|
msg.Data.Set(k, v.(string))
|
||||||
}
|
}
|
||||||
return msg, nil
|
|
||||||
}
|
}
|
||||||
return nil, SuccessResponse
|
} else {
|
||||||
|
callbackResponse = SignatureIsNotOk
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
baseapi.SugarLogger.Warnf("mtwm GetCallbackMsg ParseForm failed with error:%v", err)
|
||||||
|
callbackResponse = Err2CallbackResponse(err, "")
|
||||||
|
}
|
||||||
|
return msg, callbackResponse
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user