JPushTest.java
2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.sl.ms.base.jpush;
import cn.jiguang.sdk.api.PushApi;
import cn.jiguang.sdk.bean.push.PushSendParam;
import cn.jiguang.sdk.bean.push.PushSendResult;
import cn.jiguang.sdk.bean.push.audience.Audience;
import cn.jiguang.sdk.bean.push.message.notification.NotificationMessage;
import cn.jiguang.sdk.constants.ApiConstants;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@SpringBootTest
public class JPushTest {
@Autowired
private PushApi pushApi;
@Test
public void send() {
PushSendParam param = new PushSendParam();
// 通知内容
NotificationMessage.Android android = new NotificationMessage.Android();
android.setAlert("this is android alert");
android.setTitle("this is android title");
NotificationMessage.IOS iOS = new NotificationMessage.IOS();
Map<String, String> iOSAlert = new HashMap<>();
iOSAlert.put("title", "this is iOS title");
iOSAlert.put("subtitle", "this is iOS subtitle");
iOS.setAlert(iOSAlert);
Map<String, Object> extrasMap = new HashMap<>();
Map<String, Object> extrasParamMap = new HashMap<>();
extrasParamMap.put("key1", "value1");
extrasParamMap.put("key2", "value2");
extrasMap.put("params", extrasParamMap);
android.setExtras(extrasMap);
iOS.setExtras(extrasMap);
NotificationMessage notificationMessage = new NotificationMessage();
notificationMessage.setAlert("this is alert");
notificationMessage.setAndroid(android);
notificationMessage.setIos(iOS);
param.setNotification(notificationMessage);
// 目标人群
Audience audience = new Audience();
audience.setRegistrationIdList(Arrays.asList("170976fa8ba46cae79f", "170976fa8ba46cae79f"));
// 指定目标
param.setAudience(audience);
// 或者发送所有人
// param.setAudience(ApiConstants.Audience.ALL);
// 或者发送所有平台
param.setPlatform(ApiConstants.Platform.ALL);
// 短信补充
// param.setSmsMessage();
// 回调
// param.setCallback();
// 发送
PushSendResult result = pushApi.send(param);
log.info("result:{}", result);
}
}