mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
push update
This commit is contained in:
parent
d670356388
commit
6449c4a53d
@ -98,7 +98,7 @@ func newGetuiClient() *Getui {
|
|||||||
return &Getui{}
|
return &Getui{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operationID string) (resp string, err error) {
|
func (g *Getui) Push(userIDList []string, alert, detailContent, operationID string) (resp string, err error) {
|
||||||
token, err := db.DB.GetGetuiToken()
|
token, err := db.DB.GetGetuiToken()
|
||||||
log.NewDebug(operationID, utils.GetSelfFuncName(), "token:", token)
|
log.NewDebug(operationID, utils.GetSelfFuncName(), "token:", token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -32,13 +32,13 @@ func (j *JPush) SetAlias(cid, alias string) (resp string, err error) {
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *JPush) Push(accounts []string, alert, detailContent, platform, operationID string) (string, error) {
|
func (j *JPush) Push(accounts []string, alert, detailContent, operationID string) (string, error) {
|
||||||
var pf requestBody.Platform
|
var pf requestBody.Platform
|
||||||
_ = pf.SetPlatform(platform)
|
pf.SetAll()
|
||||||
var au requestBody.Audience
|
var au requestBody.Audience
|
||||||
au.SetAlias(accounts)
|
au.SetAlias(accounts)
|
||||||
var no requestBody.Notification
|
var no requestBody.Notification
|
||||||
no.SetAlert(alert, platform)
|
no.SetAlert(alert)
|
||||||
var me requestBody.Message
|
var me requestBody.Message
|
||||||
me.SetMsgContent(detailContent)
|
me.SetMsgContent(detailContent)
|
||||||
var o requestBody.Options
|
var o requestBody.Options
|
||||||
|
@ -2,7 +2,6 @@ package requestBody
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/constant"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Notification struct {
|
type Notification struct {
|
||||||
@ -23,18 +22,14 @@ type Ios struct {
|
|||||||
Badge string `json:"badge,omitempty"`
|
Badge string `json:"badge,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notification) SetAlert(alert, platform string) {
|
func (n *Notification) SetAlert(alert string) {
|
||||||
n.Alert = alert
|
n.Alert = alert
|
||||||
switch platform {
|
n.Android.Alert = alert
|
||||||
case constant.AndroidPlatformStr:
|
n.SetAndroidIntent()
|
||||||
n.Android.Alert = alert
|
n.IOS.Alert = alert
|
||||||
n.SetAndroidIntent()
|
n.IOS.Sound = "default"
|
||||||
case constant.IOSPlatformStr:
|
n.IOS.Badge = "+1"
|
||||||
n.IOS.Alert = alert
|
|
||||||
n.IOS.Sound = "default"
|
|
||||||
n.IOS.Badge = "+1"
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
func (n *Notification) SetAndroidIntent() {
|
func (n *Notification) SetAndroidIntent() {
|
||||||
n.Android.Intent.URL = config.Config.Push.Jpns.PushIntent
|
n.Android.Intent.URL = config.Config.Push.Jpns.PushIntent
|
||||||
|
@ -8,25 +8,23 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/constant"
|
|
||||||
"Open_IM/pkg/common/kafka"
|
"Open_IM/pkg/common/kafka"
|
||||||
"Open_IM/pkg/statistics"
|
"Open_IM/pkg/statistics"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
rpcServer RPCServer
|
rpcServer RPCServer
|
||||||
pushCh PushConsumerHandler
|
pushCh PushConsumerHandler
|
||||||
pushTerminal []int32
|
producer *kafka.Producer
|
||||||
producer *kafka.Producer
|
count uint64
|
||||||
count uint64
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init(rpcPort int) {
|
func Init(rpcPort int) {
|
||||||
|
|
||||||
rpcServer.Init(rpcPort)
|
rpcServer.Init(rpcPort)
|
||||||
pushCh.Init()
|
pushCh.Init()
|
||||||
pushTerminal = []int32{constant.IOSPlatformID, constant.AndroidPlatformID}
|
|
||||||
}
|
}
|
||||||
func init() {
|
func init() {
|
||||||
producer = kafka.NewKafkaProducer(config.Config.Kafka.Ws2mschat.Addr, config.Config.Kafka.Ws2mschat.Topic)
|
producer = kafka.NewKafkaProducer(config.Config.Kafka.Ws2mschat.Addr, config.Config.Kafka.Ws2mschat.Topic)
|
||||||
|
@ -59,68 +59,63 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
|
|||||||
if v.ResultCode == 0 {
|
if v.ResultCode == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
//supported terminal
|
//Use offline push messaging
|
||||||
for _, t := range pushTerminal {
|
var UIDList []string
|
||||||
if v.RecvPlatFormID == t {
|
UIDList = append(UIDList, v.RecvID)
|
||||||
//Use offline push messaging
|
customContent := OpenIMContent{
|
||||||
var UIDList []string
|
SessionType: int(pushMsg.MsgData.SessionType),
|
||||||
UIDList = append(UIDList, v.RecvID)
|
From: pushMsg.MsgData.SendID,
|
||||||
customContent := OpenIMContent{
|
To: pushMsg.MsgData.RecvID,
|
||||||
SessionType: int(pushMsg.MsgData.SessionType),
|
Seq: pushMsg.MsgData.Seq,
|
||||||
From: pushMsg.MsgData.SendID,
|
}
|
||||||
To: pushMsg.MsgData.RecvID,
|
bCustomContent, _ := json.Marshal(customContent)
|
||||||
Seq: pushMsg.MsgData.Seq,
|
jsonCustomContent := string(bCustomContent)
|
||||||
}
|
var content string
|
||||||
bCustomContent, _ := json.Marshal(customContent)
|
if pushMsg.MsgData.OfflinePushInfo != nil {
|
||||||
jsonCustomContent := string(bCustomContent)
|
content = pushMsg.MsgData.OfflinePushInfo.Title
|
||||||
var content string
|
|
||||||
if pushMsg.MsgData.OfflinePushInfo != nil {
|
|
||||||
content = pushMsg.MsgData.OfflinePushInfo.Title
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
switch pushMsg.MsgData.ContentType {
|
||||||
|
case constant.Text:
|
||||||
|
content = constant.ContentType2PushContent[constant.Text]
|
||||||
|
case constant.Picture:
|
||||||
|
content = constant.ContentType2PushContent[constant.Picture]
|
||||||
|
case constant.Voice:
|
||||||
|
content = constant.ContentType2PushContent[constant.Voice]
|
||||||
|
case constant.Video:
|
||||||
|
content = constant.ContentType2PushContent[constant.Video]
|
||||||
|
case constant.File:
|
||||||
|
content = constant.ContentType2PushContent[constant.File]
|
||||||
|
case constant.AtText:
|
||||||
|
a := AtContent{}
|
||||||
|
_ = utils.JsonStringToStruct(string(pushMsg.MsgData.Content), &a)
|
||||||
|
if utils.IsContain(v.RecvID, a.AtUserList) {
|
||||||
|
content = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common]
|
||||||
} else {
|
} else {
|
||||||
switch pushMsg.MsgData.ContentType {
|
content = constant.ContentType2PushContent[constant.GroupMsg]
|
||||||
case constant.Text:
|
|
||||||
content = constant.ContentType2PushContent[constant.Text]
|
|
||||||
case constant.Picture:
|
|
||||||
content = constant.ContentType2PushContent[constant.Picture]
|
|
||||||
case constant.Voice:
|
|
||||||
content = constant.ContentType2PushContent[constant.Voice]
|
|
||||||
case constant.Video:
|
|
||||||
content = constant.ContentType2PushContent[constant.Video]
|
|
||||||
case constant.File:
|
|
||||||
content = constant.ContentType2PushContent[constant.File]
|
|
||||||
case constant.AtText:
|
|
||||||
a := AtContent{}
|
|
||||||
_ = utils.JsonStringToStruct(string(pushMsg.MsgData.Content), &a)
|
|
||||||
if utils.IsContain(v.RecvID, a.AtUserList) {
|
|
||||||
content = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common]
|
|
||||||
} else {
|
|
||||||
content = constant.ContentType2PushContent[constant.GroupMsg]
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
content = constant.ContentType2PushContent[constant.Common]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var offlinePusher pusher.OfflinePusher
|
default:
|
||||||
if config.Config.Push.Getui.Enable {
|
content = constant.ContentType2PushContent[constant.Common]
|
||||||
log.NewInfo(pushMsg.OperationID, utils.GetSelfFuncName(), config.Config.Push.Getui)
|
|
||||||
offlinePusher = getui.GetuiClient
|
|
||||||
}
|
|
||||||
if config.Config.Push.Jpns.Enable {
|
|
||||||
offlinePusher = jpush.JPushClient
|
|
||||||
}
|
|
||||||
if offlinePusher == nil {
|
|
||||||
offlinePusher = jpush.JPushClient
|
|
||||||
}
|
|
||||||
pushResult, err := offlinePusher.Push(UIDList, content, jsonCustomContent, constant.PlatformIDToName(t), pushMsg.OperationID)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error(), constant.PlatformIDToName(t))
|
|
||||||
} else {
|
|
||||||
log.NewDebug(pushMsg.OperationID, "offline push return result is ", pushResult, pushMsg.MsgData, constant.PlatformIDToName(t))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var offlinePusher pusher.OfflinePusher
|
||||||
|
if config.Config.Push.Getui.Enable {
|
||||||
|
log.NewInfo(pushMsg.OperationID, utils.GetSelfFuncName(), config.Config.Push.Getui)
|
||||||
|
offlinePusher = getui.GetuiClient
|
||||||
|
}
|
||||||
|
if config.Config.Push.Jpns.Enable {
|
||||||
|
offlinePusher = jpush.JPushClient
|
||||||
|
}
|
||||||
|
if offlinePusher == nil {
|
||||||
|
offlinePusher = jpush.JPushClient
|
||||||
|
}
|
||||||
|
pushResult, err := offlinePusher.Push(UIDList, content, jsonCustomContent, pushMsg.OperationID)
|
||||||
|
if err != nil {
|
||||||
|
log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error())
|
||||||
|
} else {
|
||||||
|
log.NewDebug(pushMsg.OperationID, "offline push return result is ", pushResult, pushMsg.MsgData)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package push
|
package push
|
||||||
|
|
||||||
type OfflinePusher interface {
|
type OfflinePusher interface {
|
||||||
Push(userIDList []string, alert, detailContent, platform, operationID string) (resp string, err error)
|
Push(userIDList []string, alert, detailContent, operationID string) (resp string, err error)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user