|
@@ -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
|
}
|