作者 yangfu

fix: push only one message to the mobile device

@@ -27,51 +27,59 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ @@ -27,51 +27,59 @@ 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 )
31 - rsp = &protocol.PushInfoResponse{}  
32 - if project, err = repProject.FindOne(map[string]interface{}{"project_slave_key": request.ProjectKey}); err != nil {  
33 - log.Error(err)  
34 - err = protocol.NewCustomMessage(1, fmt.Sprintf("project_key:%v not found", request.ProjectKey))  
35 - return  
36 - }  
37 - if appInfo, err = repApp.FindOne(map[string]interface{}{"project_id": project.Id}); err != nil {  
38 - log.Error(err)  
39 - err = protocol.NewCustomMessage(1, fmt.Sprintf("project_key:%v not found", request.ProjectKey))  
40 - return 32 + if len(request.ProjectKeys) > 0 {
  33 + projectKeys = request.ProjectKeys
41 } 34 }
42 - if deviceList, err = repDevice.Find(  
43 - map[string]interface{}{  
44 - "receivers": request.Receivers, "project_master_key": project.ProjectMasterKey},  
45 - ); err != nil {  
46 - log.Error(err)  
47 - err = nil  
48 - return  
49 - }  
50 - if extInfo, ok := appInfo.GetExtInfo(); ok {  
51 - if len(extInfo.Intent) > 0 {  
52 - requestOriginal.Ext["intent"] = extInfo.Intent 35 + for i := 0; i < len(projectKeys); i++ {
  36 + projectKey := projectKeys[i]
  37 + rsp = &protocol.PushInfoResponse{}
  38 + if project, err = repProject.FindOne(map[string]interface{}{"project_slave_key": projectKey}); err != nil {
  39 + log.Error(err)
  40 + err = protocol.NewCustomMessage(1, fmt.Sprintf("project_key:%v not found", projectKey))
  41 + return
53 } 42 }
54 - if len(extInfo.Sound) > 0 {  
55 - requestOriginal.Ext["sound"] = extInfo.Sound 43 + if appInfo, err = repApp.FindOne(map[string]interface{}{"project_id": project.Id}); err != nil {
  44 + log.Error(err)
  45 + err = protocol.NewCustomMessage(1, fmt.Sprintf("project_key:%v not found", projectKey))
  46 + return
  47 + }
  48 + if deviceList, err = repDevice.Find(
  49 + map[string]interface{}{
  50 + "receivers": request.Receivers, "project_master_key": project.ProjectMasterKey},
  51 + ); err != nil {
  52 + log.Error(err)
  53 + err = nil
  54 + return
  55 + }
  56 + if extInfo, ok := appInfo.GetExtInfo(); ok {
  57 + if len(extInfo.Intent) > 0 {
  58 + requestOriginal.Ext["intent"] = extInfo.Intent
  59 + }
  60 + if len(extInfo.Sound) > 0 {
  61 + requestOriginal.Ext["sound"] = extInfo.Sound
  62 + }
  63 + }
  64 + if len(deviceList) == 0 {
  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
  68 + }
  69 + for i := range deviceList {
  70 + receivers = append(receivers, deviceList[i].ClientId)
  71 + receiverIds = append(receiverIds, deviceList[i].Uid)
  72 + }
  73 + request.ActualReceivers = receiverIds
  74 + requestOriginal.AppKey = appInfo.AppKey
  75 + requestOriginal.AppId = appInfo.AppId
  76 + requestOriginal.Secret = appInfo.AppMasterSecret
  77 + requestOriginal.ClientIdList = receivers
  78 + rsp, err = NotificationOriginal(header, requestOriginal)
  79 + repDevice.SaveLog(request, rsp.ExtData, err)
  80 + if err != nil {
  81 + err = protocol.NewCustomMessage(1, err.Error())
56 } 82 }
57 - }  
58 - if len(deviceList) == 0 {  
59 - err = protocol.NewSuccessWithMessage(fmt.Sprintf("接收人:%v 未查询到注册的设备信息!", request.Receivers))  
60 - return  
61 - }  
62 - for i := range deviceList {  
63 - receivers = append(receivers, deviceList[i].ClientId)  
64 - receiverIds = append(receiverIds, deviceList[i].Uid)  
65 - }  
66 - request.ActualReceivers = receiverIds  
67 - requestOriginal.AppKey = appInfo.AppKey  
68 - requestOriginal.AppId = appInfo.AppId  
69 - requestOriginal.Secret = appInfo.AppMasterSecret  
70 - requestOriginal.ClientIdList = receivers  
71 - rsp, err = NotificationOriginal(header, requestOriginal)  
72 - repDevice.SaveLog(request, rsp.ExtData, err)  
73 - if err != nil {  
74 - err = protocol.NewCustomMessage(1, err.Error())  
75 } 83 }
76 return 84 return
77 } 85 }
@@ -23,13 +23,13 @@ type PushInfoResponse struct { @@ -23,13 +23,13 @@ type PushInfoResponse struct {
23 23
24 /*PushInfo 推送信息*/ 24 /*PushInfo 推送信息*/
25 type PushInfoRequest struct { 25 type PushInfoRequest struct {
26 - Type int `json:"msgType"`  
27 - Receivers []int64 `json:"receivers"` //接受用户id列表  
28 - ProjectKey string `json:"project"` //ability  
29 -  
30 - Title string `json:"title" valid:"Required"`  
31 - Content string `json:"content" valid:"Required"`  
32 - Ext map[string]interface{} `json:"ext"` //key->transData:透传数据 26 + Type int `json:"msgType"`
  27 + Receivers []int64 `json:"receivers"` //接受用户id列表
  28 + ProjectKey string `json:"project"` //ability
  29 + ProjectKeys []string `json:"projects"` //同时推送多个项目的时候 eg:例如能力展示有一些发布了独立的企业版本,需要能同时推送到达
  30 + Title string `json:"title" valid:"Required"`
  31 + Content string `json:"content" valid:"Required"`
  32 + Ext map[string]interface{} `json:"ext"` //key->transData:透传数据
33 33
34 ActualReceivers []int64 `json:"-"` //实际发送的人员id列表 34 ActualReceivers []int64 `json:"-"` //实际发送的人员id列表
35 } 35 }
@@ -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)