- add callback sign check.
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
package mtpsapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
type MtpsCallbackResponse struct {
|
||||
Code string `json:"code"`
|
||||
Code int `json:"code"`
|
||||
}
|
||||
|
||||
type MtpsCallbackCommon struct {
|
||||
@@ -35,14 +34,21 @@ type MtpsCallbackOrderExceptionMsg struct {
|
||||
}
|
||||
|
||||
var (
|
||||
SuccessResponse = &MtpsCallbackResponse{Code: "0"}
|
||||
SuccessResponse = &MtpsCallbackResponse{Code: 0}
|
||||
SignatureIsNotOk = &MtpsCallbackResponse{Code: -1}
|
||||
)
|
||||
|
||||
func (m *MTPSAPI) CheckRequestValidation(request *http.Request) (callbackResponse *MtpsCallbackResponse) {
|
||||
request.ParseForm()
|
||||
sign := m.signParams(request.PostForm)
|
||||
if sign != request.FormValue(signKey) {
|
||||
return SignatureIsNotOk
|
||||
}
|
||||
|
||||
for _, valueKey := range []string{"delivery_id", "mt_peisong_id", "order_id"} {
|
||||
if request.FormValue(valueKey) == "" {
|
||||
return &MtpsCallbackResponse{
|
||||
Code: fmt.Sprintf("missing param:%s", valueKey),
|
||||
Code: -1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user