- add callback sign check.
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
package jdapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platform/common"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
type JDCallbackResponse struct {
|
||||
@@ -43,7 +43,7 @@ var (
|
||||
)
|
||||
|
||||
func (j *JDAPI) unmarshalData(strData string, msg interface{}) (callbackResponse *JDCallbackResponse) {
|
||||
err := json.Unmarshal([]byte(strData), msg)
|
||||
err := utils.UnmarshalUseNumber([]byte(strData), msg)
|
||||
if err != nil {
|
||||
return &JDCallbackResponse{
|
||||
Code: JDerrorCodeAbnormalParam,
|
||||
@@ -54,7 +54,32 @@ func (j *JDAPI) unmarshalData(strData string, msg interface{}) (callbackResponse
|
||||
return nil
|
||||
}
|
||||
|
||||
func (j *JDAPI) CheckRequestValidation(request *http.Request) (callbackResponse *JDCallbackResponse) {
|
||||
mapData := make(map[string]string)
|
||||
mapData["token"] = request.FormValue("token")
|
||||
mapData["app_key"] = request.FormValue("app_key")
|
||||
mapData["timestamp"] = request.FormValue("timestamp")
|
||||
mapData["format"] = request.FormValue("format")
|
||||
mapData["app_secret"] = j.appSecret
|
||||
mapData["v"] = request.FormValue("token")
|
||||
mapData[JD_PARAM_JSON] = request.FormValue(JD_PARAM_JSON)
|
||||
|
||||
sign := j.signParams(mapData)
|
||||
if sign != request.FormValue(signKey) {
|
||||
return &JDCallbackResponse{
|
||||
Code: JDerrorCodeInvalidSign,
|
||||
Msg: "signature is invalid",
|
||||
Data: string(utils.MustMarshal(mapData)),
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (j *JDAPI) GetOrderMsg(request *http.Request) (msg *JDOrderMsg, callbackResponse *JDCallbackResponse) {
|
||||
if callbackResponse = j.CheckRequestValidation(request); callbackResponse != nil {
|
||||
return nil, callbackResponse
|
||||
}
|
||||
|
||||
msg = new(JDOrderMsg)
|
||||
jdParamJSON := request.FormValue(JD_PARAM_JSON)
|
||||
callbackResponse = j.unmarshalData(jdParamJSON, msg)
|
||||
@@ -65,8 +90,11 @@ func (j *JDAPI) GetOrderMsg(request *http.Request) (msg *JDOrderMsg, callbackRes
|
||||
}
|
||||
|
||||
func (j *JDAPI) GetOrderDeliveryMsg(request *http.Request) (msg *JDDeliveryStatusMsg, callbackResponse *JDCallbackResponse) {
|
||||
msg = new(JDDeliveryStatusMsg)
|
||||
if callbackResponse = j.CheckRequestValidation(request); callbackResponse != nil {
|
||||
return nil, callbackResponse
|
||||
}
|
||||
|
||||
msg = new(JDDeliveryStatusMsg)
|
||||
jdParamJSON := request.FormValue(JD_PARAM_JSON)
|
||||
jdParamJSON2, err := url.QueryUnescape(jdParamJSON)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user