fix(push): push content with jpush (#2844)

* fix(push): push content with jpush

* docs: fix push enable example value

* fix(push): jpush error response
pull/2861/head
yoyoIU 2 days ago committed by GitHub
parent e0284724b5
commit 8471a0ef3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -13,7 +13,7 @@ prometheus:
ports: [ 12170, 12171, 12172, 12173, 12174, 12175, 12176, 12177, 12178, 12179, 12180, 12182, 12183, 12184, 12185, 12186 ]
maxConcurrentWorkers: 3
#Use geTui for offline push notifications, or choose fcm or jpns; corresponding configuration settings must be specified.
#Use geTui for offline push notifications, or choose fcm or jpush; corresponding configuration settings must be specified.
enable: geTui
geTui:
pushUrl: https://restapi.getui.com/v2/$appId

@ -15,6 +15,7 @@
package body
import (
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
)
@ -26,32 +27,38 @@ type Notification struct {
type Android struct {
Alert string `json:"alert,omitempty"`
Title string `json:"title,omitempty"`
Intent struct {
URL string `json:"url,omitempty"`
} `json:"intent,omitempty"`
Extras Extras `json:"extras"`
Extras map[string]string `json:"extras,omitempty"`
}
type Ios struct {
Alert string `json:"alert,omitempty"`
Sound string `json:"sound,omitempty"`
Badge string `json:"badge,omitempty"`
Extras Extras `json:"extras"`
MutableContent bool `json:"mutable-content"`
Alert IosAlert `json:"alert,omitempty"`
Sound string `json:"sound,omitempty"`
Badge string `json:"badge,omitempty"`
Extras map[string]string `json:"extras,omitempty"`
MutableContent bool `json:"mutable-content"`
}
type Extras struct {
ClientMsgID string `json:"clientMsgID"`
type IosAlert struct {
Title string `json:"title,omitempty"`
Body string `json:"body,omitempty"`
}
func (n *Notification) SetAlert(alert string) {
func (n *Notification) SetAlert(alert string, title string, opts *options.Opts) {
n.Alert = alert
n.Android.Alert = alert
n.IOS.Alert = alert
n.IOS.Sound = "default"
n.IOS.Badge = "+1"
n.Android.Title = title
n.IOS.Alert.Body = alert
n.IOS.Alert.Title = title
n.IOS.Sound = opts.IOSPushSound
if opts.IOSBadgeCount {
n.IOS.Badge = "+1"
}
}
func (n *Notification) SetExtras(extras Extras) {
func (n *Notification) SetExtras(extras map[string]string) {
n.IOS.Extras = extras
n.Android.Extras = extras
}

@ -18,9 +18,9 @@ import (
"context"
"encoding/base64"
"fmt"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/jpush/body"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/openimsdk/tools/utils/httputil"
)
@ -57,17 +57,23 @@ func (j *JPush) Push(ctx context.Context, userIDs []string, title, content strin
var au body.Audience
au.SetAlias(userIDs)
var no body.Notification
var extras body.Extras
extras := make(map[string]string)
extras["ex"] = opts.Ex
if opts.Signal.ClientMsgID != "" {
extras.ClientMsgID = opts.Signal.ClientMsgID
extras["ClientMsgID"] = opts.Signal.ClientMsgID
}
no.IOSEnableMutableContent()
no.SetExtras(extras)
no.SetAlert(title)
no.SetAlert(content, title, opts)
no.SetAndroidIntent(j.pushConf)
var msg body.Message
msg.SetMsgContent(content)
msg.SetTitle(title)
if opts.Signal.ClientMsgID != "" {
msg.SetExtras("ClientMsgID", opts.Signal.ClientMsgID)
}
msg.SetExtras("ex", opts.Ex)
var opt body.Options
opt.SetApnsProduction(j.pushConf.IOSPush.Production)
var pushObj body.PushObj
@ -76,12 +82,12 @@ func (j *JPush) Push(ctx context.Context, userIDs []string, title, content strin
pushObj.SetNotification(&no)
pushObj.SetMessage(&msg)
pushObj.SetOptions(&opt)
var resp any
return j.request(ctx, pushObj, resp, 5)
var resp map[string]any
return j.request(ctx, pushObj, &resp, 5)
}
func (j *JPush) request(ctx context.Context, po body.PushObj, resp any, timeout int) error {
return j.httpClient.PostReturn(
func (j *JPush) request(ctx context.Context, po body.PushObj, resp *map[string]any, timeout int) error {
err := j.httpClient.PostReturn(
ctx,
j.pushConf.JPNS.PushURL,
map[string]string{
@ -91,4 +97,11 @@ func (j *JPush) request(ctx context.Context, po body.PushObj, resp any, timeout
resp,
timeout,
)
if err != nil {
return err
}
if (*resp)["sendno"] != "0" {
return fmt.Errorf("jpush push failed %v", resp)
}
return nil
}

@ -73,7 +73,7 @@ func (o *OfflinePushConsumerHandler) getOfflinePushInfos(msg *sdkws.MsgData) (ti
IsAtSelf bool `json:"isAtSelf"`
}
opts = &options.Opts{Signal: &options.Signal{}}
opts = &options.Opts{Signal: &options.Signal{ClientMsgID: msg.ClientMsgID}}
if msg.OfflinePushInfo != nil {
opts.IOSBadgeCount = msg.OfflinePushInfo.IOSBadgeCount
opts.IOSPushSound = msg.OfflinePushInfo.IOSPushSound

@ -4,6 +4,10 @@ import (
"context"
"encoding/json"
"math/rand"
"strconv"
"time"
"github.com/IBM/sarama"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
@ -27,9 +31,6 @@ import (
"github.com/openimsdk/tools/utils/timeutil"
"github.com/redis/go-redis/v9"
"google.golang.org/protobuf/proto"
"math/rand"
"strconv"
"time"
)
type ConsumerHandler struct {
@ -335,6 +336,7 @@ func (c *ConsumerHandler) groupMessagesHandler(ctx context.Context, groupID stri
func (c *ConsumerHandler) offlinePushMsg(ctx context.Context, msg *sdkws.MsgData, offlinePushUserIDs []string) error {
title, content, opts, err := c.getOfflinePushInfos(msg)
if err != nil {
log.ZError(ctx, "getOfflinePushInfos failed", err, "msg", msg)
return err
}
err = c.offlinePusher.Push(ctx, offlinePushUserIDs, title, content, opts)
@ -364,7 +366,7 @@ func (c *ConsumerHandler) getOfflinePushInfos(msg *sdkws.MsgData) (title, conten
IsAtSelf bool `json:"isAtSelf"`
}
opts = &options.Opts{Signal: &options.Signal{}}
opts = &options.Opts{Signal: &options.Signal{ClientMsgID: msg.ClientMsgID}}
if msg.OfflinePushInfo != nil {
opts.IOSBadgeCount = msg.OfflinePushInfo.IOSBadgeCount
opts.IOSPushSound = msg.OfflinePushInfo.IOSPushSound

Loading…
Cancel
Save