...
|
...
|
@@ -5,21 +5,44 @@ import ( |
|
|
"openapi/internal/push"
|
|
|
)
|
|
|
|
|
|
type Template struct {
|
|
|
ClientId string `json:"cid,omitempty"`
|
|
|
RequestId string `json:"requestid,omitempty"`
|
|
|
Message *Message `json:"message"`
|
|
|
}
|
|
|
|
|
|
//1.消息模板
|
|
|
type NotificationTemplate struct {
|
|
|
*Template
|
|
|
Notification *Notification `json:"notification"`
|
|
|
}
|
|
|
|
|
|
//1.新建通知模板
|
|
|
func NewNotificationTemplate(options *push.Options) *NotificationTemplate {
|
|
|
return &NotificationTemplate{
|
|
|
Template: NewTemplate(options),
|
|
|
Notification: &Notification{
|
|
|
Style: (&Style{}).SetStyle0(options),
|
|
|
Transmission: NewTransmission(options),
|
|
|
},
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//2.透传模板
|
|
|
type TransmissionTemplate struct{}
|
|
|
type TransmissionTemplate struct {
|
|
|
*Template
|
|
|
Transmission *Transmission `json:"transmission"`
|
|
|
PushInfo *PushInfo `json:"push_info"`
|
|
|
}
|
|
|
|
|
|
//2.新建透传模板
|
|
|
func NewTransmissionTemplate(options *push.Options) *TransmissionTemplate {
|
|
|
return &TransmissionTemplate{
|
|
|
Template: NewTemplate(options),
|
|
|
Transmission: NewTransmission(options),
|
|
|
PushInfo: NewPushInfo(options),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
type Template struct {
|
|
|
ClientId string `json:"cid,omitempty"`
|
|
|
RequestId string `json:"requestid,omitempty"`
|
|
|
Message *Message `json:"message"`
|
|
|
}
|
|
|
type Notification struct {
|
|
|
Style *Style `json:"style"`
|
|
|
*Transmission
|
...
|
...
|
@@ -29,9 +52,11 @@ type Message struct { |
|
|
IsOffline bool `json:"is_offline"`
|
|
|
MsgType string `json:"msgtype"`
|
|
|
}
|
|
|
|
|
|
//透传
|
|
|
type Transmission struct {
|
|
|
TransmissionType bool `json:"transmission_type"`
|
|
|
TransmissionContent string `json:"transmission_content,omitempty"`
|
|
|
TransmissionType bool `json:"transmission_type"` //收到消息是否立即启动应用,true为立即启动,false则广播等待启动,默认是否
|
|
|
TransmissionContent string `json:"transmission_content,omitempty"` //透传内容
|
|
|
DurationBegin string `json:"duration_begin,omitempty"`
|
|
|
DurationEnd string `json:"duration_end,omitempty"`
|
|
|
}
|
...
|
...
|
@@ -47,16 +72,6 @@ func (o *Transmission) SetDuration(begin, end string) { |
|
|
o.DurationEnd = end
|
|
|
}
|
|
|
|
|
|
//1.新建单推
|
|
|
func NewNotificationTemplate(options *push.Options) *NotificationTemplate {
|
|
|
return &NotificationTemplate{
|
|
|
Template: NewTemplate(options),
|
|
|
Notification: &Notification{
|
|
|
Style: (&Style{}).SetStyle0(options),
|
|
|
Transmission: NewTransmission(options),
|
|
|
},
|
|
|
}
|
|
|
}
|
|
|
func NewTemplate(options *push.Options) *Template {
|
|
|
return &Template{
|
|
|
Message: NewMessage(options),
|
...
|
...
|
@@ -67,10 +82,10 @@ func NewTemplate(options *push.Options) *Template { |
|
|
func NewTransmission(options *push.Options) *Transmission {
|
|
|
t := &Transmission{}
|
|
|
if len(options.TransmissionContent) == 0 {
|
|
|
t.SetTransmissionType(false)
|
|
|
//t.SetTransmissionType(false)
|
|
|
return t
|
|
|
}
|
|
|
t.SetTransmissionType(true)
|
|
|
t.SetTransmissionType(false)
|
|
|
t.SetTransmissionContent(options.TransmissionContent)
|
|
|
return t
|
|
|
}
|
...
|
...
|
@@ -89,7 +104,8 @@ func resolveMsgType(msgType int) string { |
|
|
switch msgType {
|
|
|
case push.SystemNotification:
|
|
|
return "notification"
|
|
|
|
|
|
case push.Transmission:
|
|
|
return "transmission"
|
|
|
}
|
|
|
return "notification"
|
|
|
}
|
...
|
...
|
@@ -105,13 +121,16 @@ type Style struct { |
|
|
Logo string `json:"logo,omitempty"` //通知的图标名称,包含后缀名(需要在客户端开发时嵌入),如“push.png”
|
|
|
//IsRing bool `json:"is_ring"` //收到通知是否响铃:true响铃,false不响铃。默认响铃
|
|
|
//IsVibrate bool `json:"is_vibrate"` //收到通知是否振动:true振动,false不振动。默认振动
|
|
|
NotifyId int `json:"notify_id"` //需要被覆盖的消息已经增加了notifyId字段,用于实现下发消息的覆盖。新的消息使用相同的notifyId下发。
|
|
|
}
|
|
|
|
|
|
//设置默认样式 0
|
|
|
func (s *Style) SetStyle0(options *push.Options) *Style {
|
|
|
s.Type = 0
|
|
|
s.Title = options.Title
|
|
|
s.Text = options.Content
|
|
|
s.Logo = "push.png" //TODO:设置Logo地址
|
|
|
s.NotifyId = 1
|
|
|
return s
|
|
|
}
|
|
|
|
...
|
...
|
@@ -126,9 +145,47 @@ type AuthSignResponse struct { |
|
|
AuthToken string `json:"auth_token"`
|
|
|
}
|
|
|
|
|
|
//应答结果
|
|
|
type Result struct {
|
|
|
Result string `json:"result"`
|
|
|
TaskId string `json:"taskid"`
|
|
|
Status string `json:"status"`
|
|
|
Desc string `json:"desc"`
|
|
|
}
|
|
|
|
|
|
//透传附加的推送信息
|
|
|
func NewPushInfo(options *push.Options) (v *PushInfo) {
|
|
|
v = &PushInfo{
|
|
|
Aps: NewAps(options),
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
func NewAps(options *push.Options) (v *Aps) {
|
|
|
v = &Aps{
|
|
|
Alert: NewAlert(options),
|
|
|
AutoBadge: "+1",
|
|
|
ContentAvailable: 1,
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
func NewAlert(options *push.Options) (v *Alert) {
|
|
|
v = &Alert{
|
|
|
Title: options.Title,
|
|
|
Body: options.Content,
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
type PushInfo struct {
|
|
|
Aps *Aps `json:"aps"`
|
|
|
}
|
|
|
type Aps struct {
|
|
|
Alert *Alert `json:"alert"`
|
|
|
AutoBadge string `json:"autoBadge"` //用于计算应用上面未读数字
|
|
|
ContentAvailable int `json:"content-available"` //推送直接带有透传数据 0:有通知栏消息 1:无通知栏消息
|
|
|
Payload string `json:"payload,omitempty"`
|
|
|
}
|
|
|
type Alert struct {
|
|
|
Title string `json:"title"`
|
|
|
Body string `json:"body"`
|
|
|
} |
...
|
...
|
|