- weimob order and callback
This commit is contained in:
84
platformapi/weimobapi/callback.go
Normal file
84
platformapi/weimobapi/callback.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package weimobapi
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
MsgEventCreateOrder = "createOrder"
|
||||
MsgEventOrderStatusChange = "orderStatusChange"
|
||||
)
|
||||
|
||||
const (
|
||||
ChannelTypeWeixinOpen = 0
|
||||
ChannelTypeWeixinMini = 1
|
||||
ChannelTypeH5 = 2
|
||||
ChannelTypeQQ = 3
|
||||
ChannelTypeWeibo = 4
|
||||
ChannelTypeToutiao = 5
|
||||
ChannelTypeAliPay = 6
|
||||
ChannelTypeOffline = 7
|
||||
)
|
||||
|
||||
type CallbackMsg struct {
|
||||
ID string `json:"id"`
|
||||
MsgEvent string `json:"msgEvent"`
|
||||
PublicAccountID int64 `json:"public_account_id"`
|
||||
OrderNo int64 `json:"orderNo"`
|
||||
StatusTime time.Time `json:"statusTime"`
|
||||
ChannelType int `json:"channelType"`
|
||||
}
|
||||
|
||||
type ErrorInfo struct {
|
||||
ErrCode int `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
}
|
||||
type CallbackResponse struct {
|
||||
Code ErrorInfo `json:"code"`
|
||||
}
|
||||
|
||||
var (
|
||||
SuccessResponse = &CallbackResponse{
|
||||
Code: ErrorInfo{},
|
||||
}
|
||||
)
|
||||
|
||||
func Err2CallbackResponse(err error, data string) *CallbackResponse {
|
||||
if err == nil {
|
||||
return SuccessResponse
|
||||
}
|
||||
if data == "" {
|
||||
data = err.Error()
|
||||
}
|
||||
return &CallbackResponse{
|
||||
Code: ErrorInfo{
|
||||
ErrCode: -1,
|
||||
ErrMsg: data,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (a *API) GetCallbackMsg(body []byte) (msg *CallbackMsg, callbackResponse *CallbackResponse) {
|
||||
var mapMsg map[string]interface{}
|
||||
err := utils.UnmarshalUseNumber(body, &mapMsg)
|
||||
if err != nil {
|
||||
return nil, Err2CallbackResponse(err, "")
|
||||
}
|
||||
msgBody := mapMsg["msg_body"].(map[string]interface{})
|
||||
msg = &CallbackMsg{
|
||||
ID: utils.Interface2String(mapMsg["id"]),
|
||||
MsgEvent: utils.Interface2String(mapMsg["event"]),
|
||||
PublicAccountID: utils.MustInterface2Int64(mapMsg["public_account_id"]),
|
||||
OrderNo: utils.MustInterface2Int64(msgBody["orderNo"]),
|
||||
}
|
||||
|
||||
if msg.MsgEvent == MsgEventCreateOrder {
|
||||
// msg.StatusTime = msgBody["createTime"]
|
||||
msg.ChannelType = int(utils.MustInterface2Int64(msgBody["channelType"]))
|
||||
} else {
|
||||
msg.StatusTime = time.Now()
|
||||
}
|
||||
return nil, SuccessResponse
|
||||
}
|
||||
Reference in New Issue
Block a user