Files
jx-callback/business/partner/purchase/jx/phpjx/callback.go
2019-11-06 18:20:34 +08:00

56 lines
1.2 KiB
Go

package phpjx
import (
"fmt"
"time"
"git.rosy.net.cn/baseapi/utils"
)
const (
appKey = "4A86853D-E4B6-454E-940A-B68ECDA2B73E"
MsgTypeOrder = "order"
MsgTypeAfsOrder = "afsOrder"
)
type CallbackResponse struct {
Code int `json:"code"`
Data string `json:"data"`
}
type CallbackMsg struct {
AppKey string `json:"appKey"`
MsgType string `json:"msgType"`
SubMsgType string `json:"subMsgType"`
ThingID string `json:"thingID"`
ThingID2 string `json:"thingID2"`
Data string `json:"data"`
Timestamp int64 `json:"timestamp"`
}
func OnCallbackMsg(msg *CallbackMsg) (retVal, errCode string, err error) {
if msg.AppKey != appKey {
return retVal, errCode, fmt.Errorf("无效的AppKey:%s", msg.AppKey)
}
if msg.MsgType == MsgTypeOrder {
retVal, errCode, err = OnOrderMsg(msg)
} else if msg.MsgType == MsgTypeAfsOrder {
err = OnAfsOrderMsg(msg)
}
return retVal, errCode, err
}
func postFakeMsg(orderNo string, status int) {
msg := &CallbackMsg{
AppKey: appKey,
MsgType: MsgTypeOrder,
SubMsgType: utils.Int2Str(status),
ThingID: orderNo,
Timestamp: time.Now().Unix(),
}
utils.CallFuncAsync(func() {
OnCallbackMsg(msg)
})
}