Files
baseapi/platformapi/dadaapi/notify.go
gazebo c978ca1b44 up
2019-12-20 15:09:23 +08:00

59 lines
1.5 KiB
Go

package dadaapi
import "git.rosy.net.cn/baseapi/utils"
const (
MessageTypeRidderCancel = 1
)
type RidderCancelNotify struct {
OrderID string `json:"orderId"`
DadaOrderID int64 `json:"dadaOrderId"`
CancelReason string `json:"cancelReason"`
}
type RidderCancelConfirm struct {
OrderID string `json:"orderId"`
DadaOrderID int64 `json:"dadaOrderId"`
IsConfirm int `json:"isConfirm"`
}
type NotifyMsg struct {
MessageType int `json:"messageType"`
MessageBody string `json:"messageBody"`
CreateTime int64 `json:"createTime"`
MessageObj *RidderCancelNotify `json:"messageObj"`
}
type NotifyResponse struct {
Status string `json:"status"`
}
var (
SuccessNotifyResponse = &NotifyResponse{Status: "ok"}
FailedNotifyResponse = &NotifyResponse{Status: "fail"}
)
func (a *API) GetNotifyMsg(data []byte) (msg *NotifyMsg, notifyResponse *NotifyResponse) {
err := utils.UnmarshalUseNumber(data, &msg)
if err == nil && msg.MessageBody != "" {
err = utils.UnmarshalUseNumber([]byte(msg.MessageBody), &msg.MessageObj)
}
if err != nil {
notifyResponse = FailedNotifyResponse
}
return msg, notifyResponse
}
// 消息确认
// http://newopen.imdada.cn/#/development/file/merchantConfirm?_k=gqkja3
func (a *API) ConfirmRidderCancel(orderID string, dadaOrderID int64, isConfirm bool) (err error) {
_, err = a.AccessAPI("message/confirm", utils.Struct2FlatMap(&RidderCancelConfirm{
OrderID: orderID,
DadaOrderID: dadaOrderID,
IsConfirm: utils.Bool2Int(isConfirm),
}))
return err
}