Skip to content

Commit

Permalink
feat: 更新优化fcm推送
Browse files Browse the repository at this point in the history
  • Loading branch information
am6737 committed Mar 6, 2024
1 parent ad7aa17 commit 99bc552
Show file tree
Hide file tree
Showing 10 changed files with 466 additions and 93 deletions.
26 changes: 26 additions & 0 deletions api/http/v1/dto/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,32 @@ type MeizuPushRequestData struct {
Data map[string]string `json:"data,omitempty"`
}

type AndroidPushRequestData 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 Down
78 changes: 39 additions & 39 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,45 +57,45 @@ func main() {
return adapter.NewPushServiceAdapter(svc)
})

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

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

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

pushServiceFactory.Register(consts.PlatformXiaomi.String(), func() push.PushService {
svc, err := push.NewXiaomiService(cfg)
if err != nil {
panic(err)
}
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)
})
//pushServiceFactory.Register(consts.PlatformHuawei.String(), func() push.PushService {
// svc, err := push.NewHMSService(cfg)
// if err != nil {
// panic(err)
// }
// return adapter.NewPushServiceAdapter(svc)
//})
//
//pushServiceFactory.Register(consts.PlatformVivo.String(), func() push.PushService {
// svc, err := push.NewVivoService(cfg)
// if err != nil {
// panic(err)
// }
// return adapter.NewPushServiceAdapter(svc)
//})
//
//pushServiceFactory.Register(consts.PlatformOppo.String(), func() push.PushService {
// svc, err := push.NewOppoService(cfg)
// if err != nil {
// panic(err)
// }
// return adapter.NewPushServiceAdapter(svc)
//})
//
//pushServiceFactory.Register(consts.PlatformXiaomi.String(), func() push.PushService {
// svc, err := push.NewXiaomiService(cfg)
// if err != nil {
// panic(err)
// }
// 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
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type AndroidAppConfig struct {
Enabled bool `yaml:"enabled"`
AppID string `yaml:"app_id"`
AppKey string `yaml:"app_key"`
KeyPath string `yaml:"key_path"`
MaxRetry int `yaml:"max_retry"`
}

Expand All @@ -71,7 +72,7 @@ type Config struct {
GRPC GRPCConfig `yaml:"grpc"`
IOS []iOSAppConfig `yaml:"ios"`
Huawei []HuaweiAppConfig `yaml:"huawei"`
Android []AndroidAppConfig `yaml:" android"`
Android []AndroidAppConfig `yaml:"android"`
Vivo []VivoAppConfig `yaml:"vivo"`
Oppo []OppoAppConfig `yaml:"oppo"`
Xiaomi []XiaomiAppConfig `yaml:"xiaomi"`
Expand Down
10 changes: 10 additions & 0 deletions config/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ ios:
key_id: ""
team_id: ""

android:
- enabled: true

appid: ""

# Firebase Admin SDK AccountKey.json
key_path: ""

max_retry: 0

huawei:
- enabled: true
app_id: huawei-appid-1
Expand Down
35 changes: 31 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/cossim/hipush
go 1.22.0

require (
firebase.google.com/go v3.13.0+incompatible
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
Expand All @@ -17,24 +18,39 @@ require (
github.com/sideshow/apns2 v0.23.0
github.com/yilee/xiaomi-push v0.0.0-20170213073944-562fbb07388e
go.uber.org/zap v1.27.0
golang.org/x/net v0.21.0
google.golang.org/api v0.168.0
google.golang.org/grpc v1.62.0
google.golang.org/protobuf v1.32.0
gopkg.in/yaml.v3 v3.0.1
)

require (
cloud.google.com/go v0.112.1 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/firestore v1.15.0 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/longrunning v0.5.5 // indirect
cloud.google.com/go/storage v1.39.0 // indirect
github.com/bitly/go-simplejson v0.5.1 // indirect
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/felixge/httpsnoop v1.0.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang-jwt/jwt/v4 v4.4.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/kr/pretty v0.3.1 // indirect
Expand All @@ -46,11 +62,22 @@ require (
github.com/satori/go.uuid v1.2.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240304161311-37d4d3c04a78 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240304161311-37d4d3c04a78 // indirect
)
Loading

0 comments on commit 99bc552

Please sign in to comment.