|
|
|
@ -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
|
|
|
|
|
}
|
|
|
|
|