Skip to content

Commit

Permalink
feat(oppo-push): 添加oppo-push
Browse files Browse the repository at this point in the history
  • Loading branch information
am6737 committed Mar 5, 2024
1 parent d22d396 commit 2ab4d78
Show file tree
Hide file tree
Showing 12 changed files with 402 additions and 6 deletions.
31 changes: 31 additions & 0 deletions api/http/v1/dto/dto.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package dto

import (
"github.com/cossim/hipush/internal/notify"
"time"
)

// ClickAction 点击行为
type ClickAction struct {
Url string
Expand Down Expand Up @@ -73,3 +78,29 @@ type VivoPushRequestData struct {
Category string
Data map[string]string
}

type OppoPushRequestData struct {
Foreground bool
Title string
Subtitle string
Message string
// IsTimed 是否限时展示,指示消息是否在特定时间范围内展示
IsTimed bool
// TimedDuration 限时展示时长,单位为秒,消息将在此时长内展示
TimedDuration int
// ValidityPeriod 消息有效时长,即推送服务缓存消息的时长,从消息创建是开始计算,最短为1小时,最长10天
ValidityPeriod int
// IsScheduled false为立即推送 true为定时推送
// 消息会在ScheduledStart-ScheduledEnd的时间段内随机展示
IsScheduled bool
// ScheduledStart 定时推送的开始时间,指定消息推送的开始时间
ScheduledStart time.Time
// ScheduledEnd 定时推送的结束时间,指定消息推送的结束时间
ScheduledEnd time.Time
// Icon 消息图标,用于在通知栏上显示的图标
Icon string
// ClickAction 点击动作
ClickAction notify.OppoClickAction
// 附加的自定义参数
Data map[string]string
}
27 changes: 21 additions & 6 deletions api/http/v1/dto/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,30 @@ package dto

// PushRequest 表示推送请求的结构体
type PushRequest struct {
// 推送平台 consts.Platform
// AppID 应用程序标识
// ios capacitor.config文件中的appId 例如com.hitosea.apptest
AppID string `json:"app_id" binding:"required"`

// Platform 推送平台 consts.Platform
Platform string `json:"platform" binding:"required"`

// 接收推送的设备标识
// Token 接收推送的设备标识
// 例如ios为deviceToken
// vivo、oppo为RegId
Token []string `json:"token" binding:"required"`

// ios capacitor.config文件中的appId 例如com.hitosea.apptest
AppID string `json:"app_id" binding:"required"`
// 推送的消息请求数据,不同平台可能有不同的格式
Data interface{} `json:"data" binding:"required"`

// PushOptions 推送选项
Option PushOption `json:"option,omitempty"`
}

// PushOption 表示推送选项的结构体
type PushOption struct {
// DryRun 只进行数据校验不实际推送,数据校验成功即为成功
DryRun bool `json:"dry_run,omitempty"`

// 自定义的消息数据,不同平台可能有不同的格式
Data interface{} `json:"data"`
// Retry 重试次数
Retry int `json:"retry,omitempty"`
}
8 changes: 8 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ func main() {
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)
})

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

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

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

type AndroidAppConfig struct {
Enabled bool `yaml:"enabled"`
AppID string `yaml:"app_id"`
Expand All @@ -50,6 +58,7 @@ type Config struct {
Huawei []HuaweiAppConfig `yaml:"huawei"`
Android []AndroidAppConfig `yaml:" android"`
Vivo []VivoAppConfig `yaml:"vivo"`
Oppo []OppoAppConfig `yaml:"oppo"`
}

type HTTPConfig struct {
Expand Down
8 changes: 8 additions & 0 deletions config/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,12 @@ vivo:
app_id: ""
app_key: ""
app_secret: ""
max_retry: 5

oppo:
- enabled: true
app_id: ""
app_key: ""
# 这里的secret是oppo的masterSecret,
app_secret: ""
max_retry: 5
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
)

require (
github.com/316014408/oppo-push v0.0.0-20190427030828-462d62e6b171 // 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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/316014408/oppo-push v0.0.0-20190427030828-462d62e6b171 h1:sNH2BQ7ygHDl1y3umbL6qEIu9USkjx7QDMhofZUB0Zw=
github.com/316014408/oppo-push v0.0.0-20190427030828-462d62e6b171/go.mod h1:VePfNGDEjf6phdXfKvYBipPUsF8ObhXXa2eDs6bFsgU=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20201120081800-1786d5ef83d4/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
github.com/appleboy/go-fcm v0.1.6 h1:F3xHY3HxL/aZg2quFq0DaEGeXCjjoq5JWa3NCHkUup8=
Expand Down
9 changes: 9 additions & 0 deletions internal/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ type ClickAction struct {
Content string `json:"content,omitempty"`
}

// PushOption 表示推送选项的结构体
type PushOption struct {
// DryRun 只进行数据校验不实际推送,数据校验成功即为成功
DryRun bool `json:"dry_run,omitempty"`

// Retry 重试次数
Retry int `json:"retry,omitempty"`
}

// D provide string array
type D map[string]interface{}

Expand Down
43 changes: 43 additions & 0 deletions internal/notify/oppo_notify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package notify

type OppoPushNotification struct {
AppID string `json:"app_id,omitempty"`
RequestId string `json:"request_id,omitempty"`
// Tokens 对应regId列表
Tokens []string `json:"tokens" binding:"required"`

Title string `json:"title,omitempty"`
Subtitle string `json:"subtitle,omitempty"`
Message string `json:"message,omitempty"`

// Data 透传数据 客户端自定义键值对 key和Value键值对总长度不能超过1024字符
Data map[string]string `json:"data,omitempty"`

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

// TTL 消息缓存时间,单位是秒,取值至少60秒,最长一天。当值为空时,默认一天
TTL int `json:"ttl,omitempty"`

// PushOptions 推送选项
Option PushOption `json:"option,omitempty"`
}

type OppoClickAction struct {
// Action 点击跳转类型 1:打开APP首页 2:打开链接 3:自定义 4:打开app内指定页面 5:跳转Intentscheme URL 默认值为 0
// 0 启动应用
// 1 打开应用内页(activity的action标签名)
// 2 打开网页
// 4 打开应用内页(activity 全路径类名)
// 5 Intentscheme URL
Action int `json:"action,omitempty"`

// Activity 打开应用内页(activity 的 intent action)
Activity string `json:"activity,omitempty"`

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

// Parameters url跳转后传的参数拼接在url后面
Parameters string `json:"parameters,omitempty"`
Content string `json:"content,omitempty"`
}
Loading

0 comments on commit 2ab4d78

Please sign in to comment.