|
1 | 1 | package cn.jpush.example; |
| 2 | +import java.util.HashMap; |
| 3 | +import java.util.Map; |
| 4 | + |
2 | 5 | import cn.jpush.api.ErrorCodeEnum; |
3 | 6 | import cn.jpush.api.IOSExtra; |
4 | 7 | import cn.jpush.api.JPushClient; |
5 | 8 | import cn.jpush.api.MessageResult; |
6 | 9 |
|
7 | 10 | public class JpushClientExample { |
8 | 11 |
|
9 | | - private static final String appKey = "47b9ef19d4be5de08df12aa0";//必填,例如466f7032ac604e02fb7bda89 |
10 | | - |
11 | | - private static final String masterSecret ="8cc138f8dc04cbf16240daa92d8d50e2" ; //必填,每个应用都对应一个masterSecret(1f0e3dad99908345f7439f8ffabdffc4) |
12 | | - |
13 | | - |
| 12 | + private static final String appKey = "57b9ef19d4be5de08df12aa0";//必填,例如466f7032ac604e02fb7bda89 |
| 13 | + private static final String masterSecret ="9cc138f8dc04cbf16240daa92d8d50e2" ; //必填,每个应用都对应一个masterSecret(1f0e3dad99908345f7439f8ffabdffc4) |
14 | 14 | private static JPushClient jpush = null; |
| 15 | + |
15 | 16 | /* |
16 | 17 | * 保存离线的时长。秒为单位。最多支持10天(864000秒)。 |
17 | 18 | * 0 表示该消息不保存离线。即:用户在线马上发出,当前不在线用户将不会收到此消息。 |
@@ -43,31 +44,37 @@ public static void main(String[] args) { |
43 | 44 | * Example: |
44 | 45 | * jpush.setEnableSSL(true); |
45 | 46 | */ |
46 | | - |
47 | | - |
| 47 | + |
| 48 | + |
48 | 49 | //测试发送消息或者通知 |
49 | | - testSend(); |
| 50 | + testSend(); |
50 | 51 | } |
51 | 52 |
|
52 | 53 | private static void testSend() { |
53 | 54 |
|
54 | 55 | int sendNo = 103; |
55 | | - String msgTitle = "标题+++"; |
56 | | - String msgContent = "+/通#知?内&容%<可>;====="; |
| 56 | + String msgTitle = "IOS标题"; |
| 57 | + String msgContent = "+/通#知?内&容%<可>;="; |
57 | 58 |
|
58 | | - /* String alias = "alias"; |
59 | | - String tag = "tag"; |
60 | | - HashMap hashMap = new HashMap(); |
61 | | - //IOS扩展参数, |
62 | | - IOSExtra iosExtra = new IOSExtra(2); |
| 59 | + /* |
| 60 | + String alias = "alias"; |
| 61 | + |
63 | 62 | */ |
| 63 | + String tag = "tag"; |
| 64 | + //IOS 扩展参数,Badge,sound |
| 65 | + IOSExtra iosExtra = new IOSExtra(2,"message.wav"); |
| 66 | + //自定义消息 android/ios |
| 67 | + Map<String, Object> map = new HashMap<String, Object>(); |
| 68 | + map.put("hey", "test"); |
| 69 | + map.put("you", "test"); |
| 70 | + |
| 71 | + MessageResult msgResult = //jpush.sendNotificationWithAppKey(sendNo,msgTitle,msgContent,0,map,iosExtra); |
64 | 72 |
|
65 | | - MessageResult msgResult =jpush.sendNotificationWithAppKey(sendNo,msgTitle,msgContent,0,null,new IOSExtra(20,"happy")); |
66 | | - |
67 | | - // jpush.sendNotificationWithAlias(sendNo, alias, msgTitle, msgContent,1,null,new IOSExtra(3)); |
68 | | - // jpush.sendNotificationWithTag(sendNo, tag, msgTitle, msgContent); |
| 73 | + // jpush.sendNotificationWithAlias(sendNo, alias, msgTitle, msgContent,1,null,new IOSExtra(3)); |
| 74 | + jpush.sendNotificationWithTag(sendNo, tag, msgTitle, msgContent); |
69 | 75 | // jpush.sendNotificationWithAlias(sendNo, tag, msgTitle, msgContent); |
70 | 76 |
|
| 77 | + |
71 | 78 | if (null != msgResult) { |
72 | 79 | System.out.println("服务器返回数据: " + msgResult.toString()); |
73 | 80 | if (msgResult.getErrcode() == ErrorCodeEnum.NOERROR.value()) { |
|
0 commit comments