- refactor platform apis.
This commit is contained in:
82
platform/mtpsapi/callback.go
Normal file
82
platform/mtpsapi/callback.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package mtpsapi
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
type MtpsCallbackResponse struct {
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type MtpsCallbackCommon struct {
|
||||
AppKey string
|
||||
Timestamp int64
|
||||
Sign string
|
||||
}
|
||||
|
||||
type MtpsCallbackOrderMsg struct {
|
||||
MtpsOrderInfoCommon
|
||||
MtpsCallbackCommon
|
||||
Status int
|
||||
CancelReasonId int
|
||||
CancelReason string
|
||||
}
|
||||
|
||||
type MtpsCallbackOrderExceptionMsg struct {
|
||||
MtpsOrderInfoCommon
|
||||
MtpsCallbackCommon
|
||||
ExceptionId int64
|
||||
ExceptionCode int
|
||||
ExceptionDescr string
|
||||
ExceptionTime int64
|
||||
}
|
||||
|
||||
var (
|
||||
SuccessResponse = &MtpsCallbackResponse{Code: "0"}
|
||||
)
|
||||
|
||||
func (m *MTPSAPI) GetOrderCallbackMsg(request *http.Request) (orderMsg *MtpsCallbackOrderMsg, callbackResponse *MtpsCallbackResponse) {
|
||||
orderMsg = &MtpsCallbackOrderMsg{
|
||||
MtpsOrderInfoCommon: MtpsOrderInfoCommon{
|
||||
DeliveryId: utils.Str2Int64(request.FormValue("delivery_id")),
|
||||
MtPeisongId: request.FormValue("mt_peisong_id"),
|
||||
OrderId: request.FormValue("order_id"),
|
||||
CourierName: request.FormValue("courier_name"),
|
||||
CourierPhone: request.FormValue("courier_phone"),
|
||||
},
|
||||
MtpsCallbackCommon: MtpsCallbackCommon{
|
||||
AppKey: request.FormValue("appkey"),
|
||||
Timestamp: utils.Str2Int64(request.FormValue("timestamp")),
|
||||
Sign: request.FormValue("sign"),
|
||||
},
|
||||
Status: int(utils.Str2Int64(request.FormValue("status"))),
|
||||
CancelReasonId: int(utils.Str2Int64(request.FormValue("cancel_reason_id"))),
|
||||
CancelReason: request.FormValue("cancel_reason"),
|
||||
}
|
||||
return orderMsg, nil
|
||||
}
|
||||
|
||||
func (m *MTPSAPI) GetOrderExceptionCallbackMsg(request *http.Request) (orderMsg *MtpsCallbackOrderExceptionMsg, callbackResponse *MtpsCallbackResponse) {
|
||||
orderMsg = &MtpsCallbackOrderExceptionMsg{
|
||||
MtpsOrderInfoCommon: MtpsOrderInfoCommon{
|
||||
DeliveryId: utils.Str2Int64(request.FormValue("delivery_id")),
|
||||
MtPeisongId: request.FormValue("mt_peisong_id"),
|
||||
OrderId: request.FormValue("order_id"),
|
||||
CourierName: request.FormValue("courier_name"),
|
||||
CourierPhone: request.FormValue("courier_phone"),
|
||||
},
|
||||
MtpsCallbackCommon: MtpsCallbackCommon{
|
||||
AppKey: request.FormValue("appkey"),
|
||||
Timestamp: utils.Str2Int64(request.FormValue("timestamp")),
|
||||
Sign: request.FormValue("sign"),
|
||||
},
|
||||
ExceptionId: utils.Str2Int64(request.FormValue("exception_id")),
|
||||
ExceptionCode: int(utils.Str2Int64(request.FormValue("exception_code"))),
|
||||
ExceptionDescr: request.FormValue("exception_descr"),
|
||||
ExceptionTime: utils.Str2Int64(request.FormValue("exception_time")),
|
||||
}
|
||||
|
||||
return orderMsg, nil
|
||||
}
|
||||
@@ -32,6 +32,22 @@ const (
|
||||
mtpsStatusMissingBusinessParams = 3
|
||||
)
|
||||
|
||||
type MtpsOrderInfoCommon struct {
|
||||
DeliveryId int64
|
||||
MtPeisongId string
|
||||
OrderId string
|
||||
CourierName string
|
||||
CourierPhone string
|
||||
}
|
||||
|
||||
type MtpsOrderInfo struct {
|
||||
MtpsOrderInfoCommon
|
||||
Status int
|
||||
OperateTime int
|
||||
CancelReasonId int
|
||||
CancelReason string
|
||||
}
|
||||
|
||||
type MTPSResult struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
@@ -45,18 +61,6 @@ type MTPSAPI struct {
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
// type MTPSOderStatus struct {
|
||||
// DeliveryId int64 `json:"delivery_id"`
|
||||
// MtPeiSongId string `json:"mt_peisong_id"`
|
||||
// OrderId string `json:"order_id"`
|
||||
// Status int `json:"status"`
|
||||
// OperateTime int `json:"operate_time"`
|
||||
// CourierName string `json:"courier_name"`
|
||||
// CourierPhone string `json:"courier_phone"`
|
||||
// CancelReasonId int `json:"cancel_reason_id"`
|
||||
// CancelReason string `json:"cancel_reason"`
|
||||
// }
|
||||
|
||||
func NewMTPSAPI(appKey, secret string, sugarLogger *zap.SugaredLogger) *MTPSAPI {
|
||||
api := &MTPSAPI{
|
||||
appKey: appKey,
|
||||
|
||||
Reference in New Issue
Block a user