1
|
package push
|
1
|
package push
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
|
|
4
|
+ "encoding/json"
|
4
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
5
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
5
|
"openapi/internal/push"
|
6
|
"openapi/internal/push"
|
6
|
"openapi/internal/push/getui"
|
7
|
"openapi/internal/push/getui"
|
|
@@ -9,24 +10,64 @@ import ( |
|
@@ -9,24 +10,64 @@ import ( |
9
|
)
|
10
|
)
|
10
|
|
11
|
|
11
|
//推送信息
|
12
|
//推送信息
|
12
|
-func PushInfo(header *protocol.RequestHeader, request *protocol.PushInfoRequest) (rsp *protocol.PushInfoResponse, err error) {
|
13
|
+func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequest) (rsp *protocol.PushInfoResponse, err error) {
|
13
|
var (
|
14
|
var (
|
14
|
sendData = make(map[string]interface{})
|
15
|
sendData = make(map[string]interface{})
|
|
|
16
|
+ clientIds []string
|
|
|
17
|
+ fc = func(m json.RawMessage) {
|
|
|
18
|
+ if len(m) == 0 {
|
|
|
19
|
+ return
|
|
|
20
|
+ }
|
|
|
21
|
+ var (
|
|
|
22
|
+ id string
|
|
|
23
|
+ ids []string
|
|
|
24
|
+ )
|
|
|
25
|
+ if e := json.Unmarshal(m, &ids); e == nil {
|
|
|
26
|
+ clientIds = append(clientIds, ids...)
|
|
|
27
|
+ return
|
|
|
28
|
+ }
|
|
|
29
|
+ if e := json.Unmarshal(m, &id); e == nil {
|
|
|
30
|
+ if len(id) == 0 {
|
|
|
31
|
+ return
|
|
|
32
|
+ }
|
|
|
33
|
+ clientIds = append(clientIds, id)
|
|
|
34
|
+ return
|
|
|
35
|
+ }
|
|
|
36
|
+ return
|
|
|
37
|
+ }
|
15
|
options []push.Option = []push.Option{
|
38
|
options []push.Option = []push.Option{
|
16
|
push.DebugModule(true),
|
39
|
push.DebugModule(true),
|
17
|
push.AppId(request.AppId),
|
40
|
push.AppId(request.AppId),
|
18
|
push.AppKey(request.AppKey),
|
41
|
push.AppKey(request.AppKey),
|
19
|
push.AppMasterSecret(request.Secret),
|
42
|
push.AppMasterSecret(request.Secret),
|
20
|
- push.ClientId(request.ClientId),
|
|
|
21
|
-
|
|
|
22
|
push.MsgType(request.Type),
|
43
|
push.MsgType(request.Type),
|
23
|
- push.PushType(push.PushToSingle),
|
|
|
24
|
|
44
|
|
25
|
push.Title(request.Title),
|
45
|
push.Title(request.Title),
|
26
|
push.Content(request.Content),
|
46
|
push.Content(request.Content),
|
27
|
push.TransmissionContent(utils.JsonAssertString(request.Ext)),
|
47
|
push.TransmissionContent(utils.JsonAssertString(request.Ext)),
|
28
|
}
|
48
|
}
|
29
|
)
|
49
|
)
|
|
|
50
|
+
|
|
|
51
|
+ fc(request.ClientId)
|
|
|
52
|
+ fc(request.DeviceToken)
|
|
|
53
|
+ switch len(clientIds) {
|
|
|
54
|
+ case 0:
|
|
|
55
|
+ err = protocol.NewCustomMessage(2, "clientId/deviceToken 不能同时为空.")
|
|
|
56
|
+ return
|
|
|
57
|
+ case 1:
|
|
|
58
|
+ options = append(options,
|
|
|
59
|
+ push.PushType(push.PushToSingle),
|
|
|
60
|
+ push.ClientId(clientIds[0]),
|
|
|
61
|
+ )
|
|
|
62
|
+ break
|
|
|
63
|
+ default:
|
|
|
64
|
+ options = append(options,
|
|
|
65
|
+ push.PushType(push.PushToList),
|
|
|
66
|
+ push.ClientIds(clientIds),
|
|
|
67
|
+ )
|
|
|
68
|
+ break
|
|
|
69
|
+ }
|
|
|
70
|
+
|
30
|
var pushService push.INotification = &getui.GetuiNotification{}
|
71
|
var pushService push.INotification = &getui.GetuiNotification{}
|
31
|
err = pushService.Init(options...)
|
72
|
err = pushService.Init(options...)
|
32
|
if err != nil {
|
73
|
if err != nil {
|