1 Star 0 Fork 0

kingwebasp / openpdd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
message.go 1.95 KB
一键复制 编辑 原始数据 按行查看 历史
bububa 提交于 2022-04-27 18:51 . feat(pmc): add 消息A P I
package pmc
import (
"encoding/json"
"errors"
"fmt"
)
type CommandType string
const (
CommandType_COMMON CommandType = "Common"
CommandType_FAIL CommandType = "Fail"
)
type EventType string
const (
EventType_TradeModifiedEvent EventType = "pdd_ddjb_TradeModified"
)
// Command pmc record
type Command struct {
ID uint64 `json:"id,omitempty"`
CommandType CommandType `json:"commandType,omitempty"`
Time int64 `json:"time,omitempty"`
SendTime int64 `json:"sendTime,omitempty"`
Message Message `json:"message,omitempty"`
}
func (c Command) IsError() bool {
return c.CommandType == CommandType_FAIL
}
func (c Command) Error() string {
return c.Message.Content
}
func (c Command) Event() (Event, error) {
if c.IsError() {
return nil, c
}
switch c.Message.Type {
case EventType_TradeModifiedEvent:
var ev TradeModifiedEvent
if err := json.Unmarshal([]byte(c.Message.Content), &ev); err != nil {
fmt.Println(c.Message.Content)
return nil, err
}
return &ev, nil
}
return nil, errors.New("unknown event")
}
type Message struct {
// Type event type
Type EventType `json:"type,omitempty"`
// Content
Content string `json:"content,omitempty"`
}
// Event pmc event
type Event interface {
Type() EventType
}
// TradeModifiedEvent 多多进宝订单状态变更
type TradeModifiedEvent struct {
// Tid 订单号
Tid string `json:"tid,omitempty"`
// Status 订单状态:0-已支付;1-已成团;2-确认收货;3-审核成功;4-审核失败(不可提现);5-已经结算 ;10-已处罚
Status int `json:"status,omitempty"`
// Pid 推广位ID
Pid string `json:"pid,omitempty"`
// CustomParameters 代理身份自定义参数
CustomParameters string `json:"custom_parameters,omitempty"`
// ModifyTime 最后更新时间
ModifyTime int64 `json:"modify_time,omitempty"`
}
// Type implement Event interface
func (m TradeModifiedEvent) Type() EventType {
return EventType_TradeModifiedEvent
}
1
https://gitee.com/kingwebasp/openpdd.git
git@gitee.com:kingwebasp/openpdd.git
kingwebasp
openpdd
openpdd
v1.0.13

搜索帮助