作者 yangfu

fix: push only one message to the mobile device

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