10
10
import cn .jiguang .sdk .bean .push .PushSendResult ;
11
11
import cn .jiguang .sdk .bean .push .audience .Audience ;
12
12
import cn .jiguang .sdk .bean .push .message .notification .NotificationMessage ;
13
+ import cn .jiguang .sdk .bean .push .options .Options ;
13
14
import cn .jiguang .sdk .bean .push .other .CidGetResult ;
14
15
import cn .jiguang .sdk .bean .push .other .QuotaGetResult ;
15
16
import cn .jiguang .sdk .constants .ApiConstants ;
16
17
import cn .jiguang .sdk .enums .platform .Platform ;
18
+ import com .fasterxml .jackson .databind .ObjectMapper ;
17
19
import lombok .extern .slf4j .Slf4j ;
18
20
import org .junit .Test ;
19
21
import org .junit .runner .RunWith ;
23
25
24
26
import java .io .File ;
25
27
import java .util .Arrays ;
28
+ import java .util .HashMap ;
29
+ import java .util .Map ;
26
30
27
31
@ Slf4j
28
32
@ SpringBootTest ()
@@ -32,6 +36,9 @@ public class PushApiTest {
32
36
@ Autowired
33
37
private PushApi pushApi ;
34
38
39
+ @ Autowired
40
+ private ObjectMapper objectMapper ;
41
+
35
42
@ Test
36
43
public void getCidForPush () {
37
44
CidGetResult result = pushApi .getCidForPush (10 );
@@ -45,18 +52,35 @@ public void send() {
45
52
NotificationMessage .Android android = new NotificationMessage .Android ();
46
53
android .setAlert ("this is android alert" );
47
54
android .setTitle ("this is android title" );
55
+
56
+ NotificationMessage .IOS iOS = new NotificationMessage .IOS ();
57
+ Map <String , String > iOSAlert = new HashMap <>();
58
+ iOSAlert .put ("title" , "this is iOS title" );
59
+ iOSAlert .put ("subtitle" , "this is iOS subtitle" );
60
+ iOS .setAlert (iOSAlert );
61
+
62
+ Map <String , Object > extrasMap = new HashMap <>();
63
+ Map <String , Object > extrasParamMap = new HashMap <>();
64
+ extrasParamMap .put ("key1" , "value1" );
65
+ extrasParamMap .put ("key2" , "value2" );
66
+ extrasMap .put ("params" , extrasParamMap );
67
+ android .setExtras (extrasMap );
68
+ iOS .setExtras (extrasMap );
69
+
48
70
NotificationMessage notificationMessage = new NotificationMessage ();
49
71
notificationMessage .setAlert ("this is alert" );
50
72
notificationMessage .setAndroid (android );
73
+ notificationMessage .setIos (iOS );
51
74
param .setNotification (notificationMessage );
52
75
53
76
// 目标人群
54
77
Audience audience = new Audience ();
55
78
audience .setRegistrationIdList (Arrays .asList ("1104a89793af2cfc030" , "1104a89793af2cfc030" ));
56
79
// 指定目标
57
- param .setAudience (audience );
80
+ // param.setAudience(audience);
81
+
58
82
// 或者发送所有人
59
- // param.setAudience(ApiConstants.Audience.ALL);
83
+ param .setAudience (ApiConstants .Audience .ALL );
60
84
61
85
// 指定平台
62
86
param .setPlatform (Arrays .asList (Platform .android , Platform .ios ));
@@ -72,6 +96,17 @@ public void send() {
72
96
// 回调
73
97
// param.setCallback();
74
98
99
+ // options
100
+ Options options = new Options ();
101
+ Map <String , Object > thirdPartyMap = new HashMap <>();
102
+ Map <String , Object > huaweiMap = new HashMap <>();
103
+ huaweiMap .put ("distribution" , "first_ospush" );
104
+ huaweiMap .put ("importance" , "NORMAL" );
105
+ huaweiMap .put ("category" , "MARKETING" );
106
+ thirdPartyMap .put ("huawei" , huaweiMap );
107
+ options .setThirdPartyChannel (thirdPartyMap );
108
+ param .setOptions (options );
109
+
75
110
// 发送
76
111
PushSendResult result = pushApi .send (param );
77
112
log .info ("result:{}" , result );
0 commit comments