mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-06-04 23:09:34 +08:00
push
This commit is contained in:
parent
b08936c27e
commit
07c300f35f
@ -59,24 +59,32 @@ type TaskResp struct {
|
|||||||
TaskID string `json:"taskID"`
|
TaskID string `json:"taskID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Settings struct {
|
||||||
|
TTL *int64 `json:"ttl"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Audience struct {
|
||||||
|
Alias []string `json:"alias"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PushMessage struct {
|
||||||
|
Notification *Notification `json:"notification,omitempty"`
|
||||||
|
Transmission *string `json:"transmission,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PushChannel struct {
|
||||||
|
Ios *Ios `json:"ios"`
|
||||||
|
Android *Android `json:"android"`
|
||||||
|
}
|
||||||
|
|
||||||
type PushReq struct {
|
type PushReq struct {
|
||||||
RequestID *string `json:"request_id"`
|
RequestID *string `json:"request_id"`
|
||||||
Settings struct {
|
Settings *Settings `json:"settings"`
|
||||||
TTL *int64 `json:"ttl"`
|
Audience *Audience `json:"audience"`
|
||||||
} `json:"settings"`
|
PushMessage *PushMessage `json:"push_message"`
|
||||||
Audience struct {
|
PushChannel *PushChannel `json:"push_channel"`
|
||||||
Alias []string `json:"alias"`
|
IsAsync *bool `json:"is_async"`
|
||||||
} `json:"audience"`
|
Taskid *string `json:"taskid"`
|
||||||
PushMessage struct {
|
|
||||||
Notification *Notification `json:"notification,omitempty"`
|
|
||||||
Transmission *string `json:"transmission,omitempty"`
|
|
||||||
} `json:"push_message"`
|
|
||||||
PushChannel struct {
|
|
||||||
Ios *Ios `json:"ios"`
|
|
||||||
Android *Android `json:"android"`
|
|
||||||
} `json:"push_channel"`
|
|
||||||
IsAsync *bool `json:"is_async"`
|
|
||||||
Taskid *string `json:"taskid"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Ios struct {
|
type Ios struct {
|
||||||
@ -142,15 +150,14 @@ func (g *Getui) Push(userIDList []string, title, detailContent, operationID stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var pushReq PushReq
|
pushReq := PushReq{PushMessage: &PushMessage{Notification: &Notification{
|
||||||
pushResp := PushResp{}
|
|
||||||
pushReq.PushMessage.Notification = &Notification{
|
|
||||||
Title: title,
|
Title: title,
|
||||||
Body: detailContent,
|
Body: detailContent,
|
||||||
ClickType: "startapp",
|
ClickType: "startapp",
|
||||||
ChannelID: config.Config.Push.Getui.ChannelID,
|
ChannelID: config.Config.Push.Getui.ChannelID,
|
||||||
ChannelName: config.Config.Push.Getui.ChannelName,
|
ChannelName: config.Config.Push.Getui.ChannelName,
|
||||||
}
|
}}}
|
||||||
|
pushResp := PushResp{}
|
||||||
if len(userIDList) > 1 {
|
if len(userIDList) > 1 {
|
||||||
taskID, err := g.GetTaskID(operationID, token, pushReq)
|
taskID, err := g.GetTaskID(operationID, token, pushReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -161,17 +168,12 @@ func (g *Getui) Push(userIDList []string, title, detailContent, operationID stri
|
|||||||
pushReq.Taskid = &taskID
|
pushReq.Taskid = &taskID
|
||||||
pushReq.PushMessage.Notification = nil
|
pushReq.PushMessage.Notification = nil
|
||||||
pushReq.PushMessage.Transmission = nil
|
pushReq.PushMessage.Transmission = nil
|
||||||
pushReq.Audience = struct {
|
pushReq.Audience = &Audience{Alias: userIDList}
|
||||||
Alias []string `json:"alias"`
|
|
||||||
}{Alias: userIDList}
|
|
||||||
err = g.request(BatchPushURL, pushReq, token, &pushResp, operationID)
|
err = g.request(BatchPushURL, pushReq, token, &pushResp, operationID)
|
||||||
} else {
|
} else {
|
||||||
reqID := utils.OperationIDGenerator()
|
reqID := utils.OperationIDGenerator()
|
||||||
pushReq.RequestID = &reqID
|
pushReq.RequestID = &reqID
|
||||||
pushReq.Audience = struct {
|
pushReq.Audience = &Audience{Alias: []string{userIDList[0]}}
|
||||||
Alias []string `json:"alias"`
|
|
||||||
}{Alias: []string{userIDList[0]}}
|
|
||||||
|
|
||||||
pushReq.PushChannel.Ios = &Ios{}
|
pushReq.PushChannel.Ios = &Ios{}
|
||||||
pushReq.PushChannel.Ios.Aps.Sound = "default"
|
pushReq.PushChannel.Ios.Aps.Sound = "default"
|
||||||
pushReq.PushChannel.Ios.Aps.Alert = Alert{
|
pushReq.PushChannel.Ios.Aps.Alert = Alert{
|
||||||
@ -242,6 +244,8 @@ func (g *Getui) Auth(operationID string, timeStamp int64) (token string, expireT
|
|||||||
|
|
||||||
func (g *Getui) GetTaskID(operationID, token string, pushReq PushReq) (string, error) {
|
func (g *Getui) GetTaskID(operationID, token string, pushReq PushReq) (string, error) {
|
||||||
respTask := TaskResp{}
|
respTask := TaskResp{}
|
||||||
|
ttl := int64(1000 * 60 * 5)
|
||||||
|
pushReq.Settings = &Settings{TTL: &ttl}
|
||||||
err := g.request(TaskURL, pushReq, token, &respTask, operationID)
|
err := g.request(TaskURL, pushReq, token, &respTask, operationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", utils.Wrap(err, "")
|
return "", utils.Wrap(err, "")
|
||||||
@ -300,7 +304,7 @@ func (g *Getui) getTokenAndSave2Redis(operationID string) (token string, err err
|
|||||||
|
|
||||||
func (g *Getui) GetTaskIDAndSave2Redis(operationID, token string, pushReq PushReq) (taskID string, err error) {
|
func (g *Getui) GetTaskIDAndSave2Redis(operationID, token string, pushReq PushReq) (taskID string, err error) {
|
||||||
ttl := int64(1000 * 60 * 60 * 24)
|
ttl := int64(1000 * 60 * 60 * 24)
|
||||||
pushReq.Settings.TTL = &ttl
|
pushReq.Settings = &Settings{TTL: &ttl}
|
||||||
taskID, err = g.GetTaskID(operationID, token, pushReq)
|
taskID, err = g.GetTaskID(operationID, token, pushReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", utils.Wrap(err, "GetTaskIDAndSave2Redis failed")
|
return "", utils.Wrap(err, "GetTaskIDAndSave2Redis failed")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user