作者 yangfu

fix: push only one message to the mobile device

... ... @@ -27,16 +27,22 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ
Content: request.Content,
Ext: request.Ext,
}
projectKeys []string = []string{request.ProjectKey}
)
if len(request.ProjectKeys) > 0 {
projectKeys = request.ProjectKeys
}
for i := 0; i < len(projectKeys); i++ {
projectKey := projectKeys[i]
rsp = &protocol.PushInfoResponse{}
if project, err = repProject.FindOne(map[string]interface{}{"project_slave_key": request.ProjectKey}); err != nil {
if project, err = repProject.FindOne(map[string]interface{}{"project_slave_key": projectKey}); err != nil {
log.Error(err)
err = protocol.NewCustomMessage(1, fmt.Sprintf("project_key:%v not found", request.ProjectKey))
err = protocol.NewCustomMessage(1, fmt.Sprintf("project_key:%v not found", projectKey))
return
}
if appInfo, err = repApp.FindOne(map[string]interface{}{"project_id": project.Id}); err != nil {
log.Error(err)
err = protocol.NewCustomMessage(1, fmt.Sprintf("project_key:%v not found", request.ProjectKey))
err = protocol.NewCustomMessage(1, fmt.Sprintf("project_key:%v not found", projectKey))
return
}
if deviceList, err = repDevice.Find(
... ... @@ -56,8 +62,9 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ
}
}
if len(deviceList) == 0 {
err = protocol.NewSuccessWithMessage(fmt.Sprintf("接收人:%v 未查询到注册的设备信息!", request.Receivers))
return
//e := protocol.NewSuccessWithMessage(fmt.Sprintf("Project:%v 接收人:%v 未查询到注册的设备信息!",projectKey, request.Receivers))
log.Error(fmt.Sprintf("【个推】 Project:%v 接收人:%v 未查询到注册的设备信息!", projectKey, request.Receivers))
continue
}
for i := range deviceList {
receivers = append(receivers, deviceList[i].ClientId)
... ... @@ -73,6 +80,7 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ
if err != nil {
err = protocol.NewCustomMessage(1, err.Error())
}
}
return
}
... ...
... ... @@ -26,7 +26,7 @@ type PushInfoRequest struct {
Type int `json:"msgType"`
Receivers []int64 `json:"receivers"` //接受用户id列表
ProjectKey string `json:"project"` //ability
ProjectKeys []string `json:"projects"` //同时推送多个项目的时候 eg:例如能力展示有一些发布了独立的企业版本,需要能同时推送到达
Title string `json:"title" valid:"Required"`
Content string `json:"content" valid:"Required"`
Ext map[string]interface{} `json:"ext"` //key->transData:透传数据
... ...
... ... @@ -78,7 +78,7 @@ func (this *PushController) UpdateDevice() {
msg = m
return
}
if request.ProjectKey == "" {
if request.ProjectKey == "" || request.ProjectKey == "mmm.boss.pad" || request.ProjectKey == "mmm.boss" {
request.ProjectKey = "mmm.ability" //默认能力展示项目
}
header := controllers.GetRequestHeader(this.Ctx)
... ...