diff --git a/api/http/v1/dto/dto.go b/api/http/v1/dto/dto.go index 9a08523..aae187e 100644 --- a/api/http/v1/dto/dto.go +++ b/api/http/v1/dto/dto.go @@ -20,7 +20,6 @@ const ( ) type HuaweiPushRequestData struct { - DryRun bool `json:"dry_run,omitempty"` Foreground bool `json:"foreground,omitempty"` TTL string `json:"ttl,omitempty"` Type string `json:"type,omitempty"` @@ -71,14 +70,16 @@ type Sound struct { } type VivoPushRequestData struct { - DryRun bool - Foreground bool - TTL int - Type string - Title string - Message string - Category string - Data map[string]string + Foreground bool `json:"foreground,omitempty"` + TTL int `json:"ttl,omitempty"` + // NotifyType 通知类型 1:无,2:响铃,3:振动,4:响铃和振动 + NotifyType int `json:"notify_type,omitempty"` + NotifyID string `json:"notify_id,omitempty"` + Title string `json:"title"` + Content string `json:"content"` + Category string `json:"category,omitempty"` + Data map[string]string `json:"data,omitempty"` + ClickAction ClickAction `json:"click_action,omitempty"` } type OppoPushRequestData struct { diff --git a/internal/server/http/vivo.go b/internal/server/http/vivo.go index f712605..ddde202 100644 --- a/internal/server/http/vivo.go +++ b/internal/server/http/vivo.go @@ -7,7 +7,6 @@ import ( "github.com/cossim/hipush/pkg/notify" "github.com/cossim/hipush/pkg/push" "github.com/gin-gonic/gin" - "github.com/google/uuid" "net/http" ) @@ -34,20 +33,24 @@ func (h *Handler) handleVivoPush(c *gin.Context, req *dto.PushRequest) error { h.logger.Info("Handling push request", "platform", req.Platform, "appID", req.AppID, "tokens", req.Token, "req", r) rr := ¬ify.VivoPushNotification{ - AppID: req.AppID, - RequestId: uuid.New().String(), - Tokens: req.Token, - Title: r.Title, - Message: r.Message, - Category: r.Category, - Data: r.Data, - ClickAction: nil, - NotifyType: 0, + AppID: req.AppID, + RequestId: r.NotifyID, + Tokens: req.Token, + Title: r.Title, + Message: r.Content, + Category: r.Category, + Data: r.Data, + ClickAction: ¬ify.VivoClickAction{ + Action: r.ClickAction.Action, + Url: r.ClickAction.Url, + Activity: r.ClickAction.Activity, + }, + NotifyType: r.NotifyType, TTL: r.TTL, Retry: 0, SendOnline: false, Foreground: r.Foreground, - Development: true, + Development: req.Option.Development, } if err := service.Send(c, rr, &push.SendOptions{ DryRun: req.Option.DryRun, diff --git a/pkg/notify/vivo_notify.go b/pkg/notify/vivo_notify.go index fcb594d..7ed5a22 100644 --- a/pkg/notify/vivo_notify.go +++ b/pkg/notify/vivo_notify.go @@ -38,6 +38,11 @@ type VivoPushNotification struct { type VivoClickAction struct { // Action 点击跳转类型 1:打开APP首页 2:打开链接 3:自定义 4:打开app内指定页面 - Action int `json:"action,omitempty"` - Content string `json:"content,omitempty"` + Action int `json:"action,omitempty"` + + // Activity 打开应用内页(activity 的 intent action) + Activity string `json:"activity,omitempty"` + + // Url 打开网页的地址 + Url string `json:"url,omitempty"` } diff --git a/pkg/push/honor_push.go b/pkg/push/honor_push.go index 541245b..35535b6 100644 --- a/pkg/push/honor_push.go +++ b/pkg/push/honor_push.go @@ -145,7 +145,7 @@ func (h *HonorService) send(ctx context.Context, appid string, token string, not // res, err := client.SendMessage(ctx, appid, notification) // if err != nil || (res != nil && res.Code != 200) { // if err == nil { - // err = errors.New(res.Message) + // err = errors.New(res.Content) // } else { // es = append(es, err) // } @@ -160,7 +160,7 @@ func (h *HonorService) send(ctx context.Context, appid string, token string, not // h.status.AddHonorFailed(1) // // } else { - // log.Printf("honor send success: %s", res.Message) + // log.Printf("honor send success: %s", res.Content) // h.status.AddHonorSuccess(1) // } // }(notification, token) diff --git a/pkg/push/vivo_push.go b/pkg/push/vivo_push.go index 677e5ac..be84af9 100644 --- a/pkg/push/vivo_push.go +++ b/pkg/push/vivo_push.go @@ -10,6 +10,7 @@ import ( vp "github.com/cossim/vivo-push" "github.com/go-logr/logr" "log" + "net/url" "strings" ) @@ -143,8 +144,7 @@ func (v *VivoService) buildNotification(req *notify.VivoPushNotification) (*vp.M // 设置默认的 ClickAction defaultClickAction := ¬ify.VivoClickAction{ - Action: 1, - Content: "", + Action: 1, } // 检查 ClickAction 是否为空,为空则使用默认值 @@ -153,6 +153,14 @@ func (v *VivoService) buildNotification(req *notify.VivoPushNotification) (*vp.M clickAction = defaultClickAction } + // 检查 URL 是否为合法 URL + if clickAction.Action == 2 { + _, err := url.Parse(clickAction.Url) + if err != nil { + return nil, err + } + } + // 检查 NotifyType 是否为有效值 if req.NotifyType != 0 && req.NotifyType < 1 || req.NotifyType > 4 { return nil, errors.New("invalid notify type") @@ -178,7 +186,7 @@ func (v *VivoService) buildNotification(req *notify.VivoPushNotification) (*vp.M Content: req.Message, TimeToLive: int64(req.TTL), SkipType: clickAction.Action, - SkipContent: clickAction.Content, + SkipContent: clickAction.Url, NetworkType: -1, ClientCustomMap: req.Data, //Extra: req.Data.ExtraMap(),