This commit is contained in:
wangchuxiao 2022-12-21 18:03:39 +08:00
parent fa5be03fc3
commit 7445b84756

View File

@ -60,23 +60,23 @@ type TaskResp struct {
} }
type PushReq struct { type PushReq struct {
RequestID string `json:"request_id"` RequestID *string `json:"request_id"`
Settings struct { Settings struct {
TTL int32 `json:"ttl"` TTL *int64 `json:"ttl"`
} `json:"settings"` } `json:"settings"`
Audience struct { Audience struct {
Alias []string `json:"alias"` Alias []string `json:"alias"`
} `json:"audience"` } `json:"audience"`
PushMessage struct { PushMessage struct {
Notification Notification `json:"notification,omitempty"` Notification *Notification `json:"notification,omitempty"`
Transmission string `json:"transmission,omitempty"` Transmission *string `json:"transmission,omitempty"`
} `json:"push_message"` } `json:"push_message"`
PushChannel struct { PushChannel struct {
Ios Ios `json:"ios"` Ios *Ios `json:"ios"`
Android Android `json:"android"` Android *Android `json:"android"`
} `json:"push_channel"` } `json:"push_channel"`
IsAsync bool `json:"is_async"` IsAsync *bool `json:"is_async"`
Taskid string `json:"taskid"` Taskid *string `json:"taskid"`
} }
type Ios struct { type Ios struct {
@ -144,7 +144,7 @@ func (g *Getui) Push(userIDList []string, title, detailContent, operationID stri
var pushReq PushReq var pushReq PushReq
pushResp := PushResp{} pushResp := PushResp{}
pushReq.PushMessage.Notification = Notification{ pushReq.PushMessage.Notification = &Notification{
Title: title, Title: title,
Body: detailContent, Body: detailContent,
ClickType: "startapp", ClickType: "startapp",
@ -153,9 +153,10 @@ func (g *Getui) Push(userIDList []string, title, detailContent, operationID stri
} }
if len(userIDList) > 1 { if len(userIDList) > 1 {
taskID, err := db.DB.GetGetuiTaskID() taskID, err := db.DB.GetGetuiTaskID()
log.NewDebug(operationID, utils.GetSelfFuncName(), "taskID", taskID)
if err != nil { if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), "GetGetuiTaskID failed", err.Error()) log.NewError(operationID, utils.GetSelfFuncName(), "GetGetuiTaskID failed", err.Error())
} else {
log.NewDebug(operationID, utils.GetSelfFuncName(), "taskID", taskID)
} }
if taskID == "" || err != nil { if taskID == "" || err != nil {
taskID, err = g.GetTaskIDAndSave2Redis(operationID, token, pushReq) taskID, err = g.GetTaskIDAndSave2Redis(operationID, token, pushReq)
@ -164,12 +165,14 @@ func (g *Getui) Push(userIDList []string, title, detailContent, operationID stri
return "", utils.Wrap(err, "") return "", utils.Wrap(err, "")
} }
} }
pushReq.IsAsync = true var IsAsync = true
pushReq.Taskid = taskID pushReq.IsAsync = &IsAsync
pushReq.Taskid = &taskID
err = g.request(BatchPushURL, pushReq, token, &pushResp, operationID) err = g.request(BatchPushURL, pushReq, token, &pushResp, operationID)
} else { } else {
reqID := utils.OperationIDGenerator()
pushReq := PushReq{ pushReq := PushReq{
RequestID: utils.OperationIDGenerator(), RequestID: &reqID,
Audience: struct { Audience: struct {
Alias []string `json:"alias"` Alias []string `json:"alias"`
}{Alias: []string{userIDList[0]}}, }{Alias: []string{userIDList[0]}},
@ -299,7 +302,8 @@ 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) {
pushReq.Settings.TTL = 1000 * 60 * 60 * 24 ttl := int64(1000 * 60 * 60 * 24)
pushReq.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")