- add callback sign check.

This commit is contained in:
gazebo
2018-06-19 18:41:58 +08:00
parent 143a929c8c
commit 27919a36fc
11 changed files with 324 additions and 95 deletions

View File

@@ -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,
}
}
}