Skip to content

Commit

Permalink
feat(meizu-push): 添加meizu-push
Browse files Browse the repository at this point in the history
  • Loading branch information
am6737 committed Mar 6, 2024
1 parent 8b7c70a commit ad7aa17
Show file tree
Hide file tree
Showing 11 changed files with 416 additions and 2 deletions.
28 changes: 27 additions & 1 deletion api/http/v1/dto/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,32 @@ type XiaomiPushRequestData struct {
Data map[string]string `json:"data,omitempty"`
}

type MeizuPushRequestData struct {
Title string `json:"title,omitempty" binding:"required"`
Content string `json:"content,omitempty" binding:"required"`

// TTL 如果用户离线,设置消息在服务器保存的时间,单位:ms,服务器默认最长保留两周。
TTL int `json:"ttl,omitempty"`

NotifyType int `json:"notify_type,omitempty" json:"notify_type,omitempty"`

// Foreground 是否前台显示通知
Foreground bool `json:"foreground,omitempty"`

// IsScheduled 是否定时推送
IsScheduled bool `json:"scheduled,omitempty"`
// ScheduledStartTime 定时展示开始时间(yyyy-MM-dd HH:mm:ss)
ScheduledStartTime string `json:"scheduled_start_time"`
// ScheduledEndTime 定时展示结束时间(yyyy-MM-dd HH:mm:ss)
ScheduledEndTime string `json:"scheduled_end_time"`

// ClickAction 点击动作
ClickAction ClickAction `json:"click_action"`

// 附加的自定义参数
Data map[string]string `json:"data,omitempty"`
}

type ClickAction struct {
// Action 点击行为
// 不同的厂商有不同的定义
Expand All @@ -140,5 +166,5 @@ type ClickAction struct {
Url string `json:"url,omitempty"`

// Parameters url跳转后传的参数拼接在url后面
Parameters string `json:"parameters,omitempty"`
Parameters map[string]interface{} `json:"parameters,omitempty"`
}
8 changes: 8 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ func main() {
return adapter.NewPushServiceAdapter(svc)
})

pushServiceFactory.Register(consts.PlatformMeizu.String(), func() push.PushService {
svc, err := push.NewMeizuService(cfg)
if err != nil {
panic(err)
}
return adapter.NewPushServiceAdapter(svc)
})

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ type XiaomiAppConfig struct {
MaxRetry int `yaml:"max_retry"`
}

type MeizuAppConfig struct {
Enabled bool `yaml:"enabled"`
AppID string `yaml:"app_id"`
AppKey string `yaml:"app_key"`
MaxRetry int `yaml:"max_retry"`
}

type Config struct {
HTTP HTTPConfig `yaml:"http"`
GRPC GRPCConfig `yaml:"grpc"`
Expand All @@ -68,6 +75,7 @@ type Config struct {
Vivo []VivoAppConfig `yaml:"vivo"`
Oppo []OppoAppConfig `yaml:"oppo"`
Xiaomi []XiaomiAppConfig `yaml:"xiaomi"`
Meizu []MeizuAppConfig `yaml:"meizu"`
}

type HTTPConfig struct {
Expand Down
7 changes: 7 additions & 0 deletions config/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,11 @@ xiaomi:
package:
- xxx.xx.xx
app_secret: ""
max_retry: 5

meizu:
- enabled: true
app_id: "2882303761520159644"
package: ""
app_key: ""
max_retry: 5
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module github.com/cossim/hipush

go 1.20
go 1.22.0

require (
github.com/316014408/oppo-push v0.0.0-20190427030828-462d62e6b171
github.com/appleboy/go-fcm v0.1.6
github.com/cossim/go-hms-push v0.0.0-20240301034220-38310a1d80e5
github.com/cossim/go-meizu-push-sdk v0.0.0-20240306071207-456c3a8650c6
github.com/cossim/vivo-push v0.0.0-20240301025332-148acd987861
github.com/gin-gonic/gin v1.9.1
github.com/go-logr/logr v1.4.1
Expand All @@ -26,6 +27,7 @@ require (
github.com/bytedance/sonic v1.10.0-rc // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/ddliu/go-httpclient v0.7.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
github.com/cossim/go-hms-push v0.0.0-20240301034220-38310a1d80e5 h1:AGXSM5ClpfmtNEFQvJUncqHDbnxp9ZzcpymKKvSpHIY=
github.com/cossim/go-hms-push v0.0.0-20240301034220-38310a1d80e5/go.mod h1:QqZK9q8Ecb/frr2gWxb4+wz4MAFRzlVelNCr1VFRZrQ=
github.com/cossim/go-meizu-push-sdk v0.0.0-20240306071207-456c3a8650c6 h1:6/X78DqpAbBkcTtg4UZWfqFOYCd+CiELdDomTulLJBk=
github.com/cossim/go-meizu-push-sdk v0.0.0-20240306071207-456c3a8650c6/go.mod h1:DVwayap9H6AjUZ0a79Of0W9mdgksF54uPlAX1LwIhQk=
github.com/cossim/vivo-push v0.0.0-20240301025332-148acd987861 h1:7VkgDgzr3C38pLkyDjhKRqOIrlhb1nVz8JL+0lSi4Xw=
github.com/cossim/vivo-push v0.0.0-20240301025332-148acd987861/go.mod h1:PHaZK+wOOXEZR4B8pt2MYWpV1o+jGZ1CcAh4858IvTg=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ddliu/go-httpclient v0.7.1 h1:COWYBalfbaFNe6e0eQU38++vCD5kzLh1H1RFs3xcn9g=
github.com/ddliu/go-httpclient v0.7.1/go.mod h1:uwipe9x9SYGk4JhBemO7+dD87QbiY224y0DLB9OY0Ik=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
Expand All @@ -34,6 +38,7 @@ github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ4
github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ=
github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
Expand All @@ -49,6 +54,7 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down Expand Up @@ -96,13 +102,15 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/yilee/xiaomi-push v0.0.0-20170213073944-562fbb07388e h1:9jcm/cOPXIx7MMS2ooZroJK977BHj0i7CxCFX9mPZ9k=
github.com/yilee/xiaomi-push v0.0.0-20170213073944-562fbb07388e/go.mod h1:fAhsEz37mtLkTw+JbnsLKmGdr/+P0f1Ru0qvH7Saz1M=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
Expand Down Expand Up @@ -139,6 +147,7 @@ google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHh
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
5 changes: 5 additions & 0 deletions internal/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const (

// PlatformOppo 表示 Oppo 平台
PlatformOppo Platform = "oppo"

// PlatformMeizu 表示魅族平台
PlatformMeizu Platform = "meizu"
)

// String converts the enum value to its string representation.
Expand All @@ -41,6 +44,8 @@ func (p Platform) String() string {
return "vivo"
case PlatformOppo:
return "oppo"
case PlatformMeizu:
return "meizu"
default:
return "unknown"
}
Expand Down
54 changes: 54 additions & 0 deletions internal/notify/meizu_notify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package notify

// MeizuPushNotification
// https://github.com/MEIZUPUSH/PushAPI/blob/master/README.md
type MeizuPushNotification struct {
AppID string `json:"app_id,omitempty"`

// Tokens 对应pushId列表
Tokens []string `json:"tokens" binding:"required"`

Title string `json:"title,omitempty"`
Content string `json:"message,omitempty"`

// NotifyType
// DEFAULT_ALL = -1;
// DEFAULT_SOUND = 0; 使用默认提示音提示
// DEFAULT_VIBRATE = 1; 使用默认振动提示
// DEFAULT_LIGHTS = 2; 使用默认呼吸灯提示。
NotifyType int `json:"notify_type,omitempty"`

ClickAction *MeizuClickAction `json:"click_action,omitempty"`

// TTL 如果用户离线,设置消息在服务器保存的时间,有效时长 (1 -72 小时内的正整数)
TTL int `json:"time_to_live,omitempty"`

OffLine bool `json:"offline,omitempty"`

IsShowNotify bool `json:"is_show_notify,omitempty"`

// IsScheduled 是否定时推送
IsScheduled bool
// ScheduledStartTime 定时展示开始时间(yyyy-MM-dd HH:mm:ss)
ScheduledStartTime string
// ScheduledEndTime 定时展示结束时间(yyyy-MM-dd HH:mm:ss)
ScheduledEndTime string
}

type MeizuClickAction struct {
// Action 点击跳转类型
// 0 打开应用
// 1 打开应用内页(activity的action标签名)
// 2 打开H5地址(应用本地的URI)
Action int `json:"action,omitempty"`

// Activity 打开应用内页(activity 的 intent action)
// 格式 pkg.activity eg: com.meizu.upspushdemo.TestActivity
Activity string `json:"activity,omitempty"`

// Url 打开网页的地址
Url string `json:"url,omitempty"`

// Parameters url跳转后传的参数拼接在url后面
Parameters map[string]interface{} `json:"parameters,omitempty"`
}
Loading

0 comments on commit ad7aa17

Please sign in to comment.