maven
1
2
3
4
5
6
7
8
9
10
|
<dependency> <groupid>com.xiaomi</groupid> <artifactid>json-simple</artifactid> <version> 1.1 . 1 </version> </dependency> <dependency> <groupid>com.xiaomi</groupid> <artifactid>mipush_sdk_server</artifactid> <version> 2.2 . 18 </version> </dependency> |
java util
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
package com.tjg99.commons.util; import com.xiaomi.xmpush.server.constants; import com.xiaomi.xmpush.server.message; import com.xiaomi.xmpush.server.sender; import com.xiaomi.xmpush.server.sender.broadcast_topic_op; import net.sf.json.jsonobject; import org.json.simple.parser.parseexception; import java.io.ioexception; import java.util.hashmap; import java.util.list; import java.util.map; /** * 小米推送工具类 **/ public class mipushutil { private static string app_secret_key_android = "asdasdasdasdasdasd" ; private static string app_secret_key_ios = "asdasdasdasdasd==" ; private static string my_package_name = "com.tjg99" ; /** * 向所有设备发送推送 * @param messagepayload 消息 * @param title 消息标题 * @param description 消息描述 * @param ads_type 消息类型 * @param ads_links 消息链接 * @throws ioexception * @throws parseexception **/ public static void sendallbroadcast(string messagepayload, string title, string description, string ads_type, string ads_links) throws ioexception, parseexception { constants.useofficial(); map map = new hashmap(); map.put( "ads_type" , ads_type); map.put( "ads_links" , ads_links); message message = new message.builder().title(title).description(description).payload(messagepayload) .extra( "data" , jsonobject.fromobject(map).tostring()).restrictedpackagename(my_package_name) .notifytype( 1 ).passthrough( 0 ) // 使用默认提示音提示 .build(); //安卓推送 sender sender_android = new sender(app_secret_key_android); // 根据topiclist做并集运算, 发送消息到指定一组设备上 sender_android.broadcastall(message, 3 ); //ios推送 sender sender_ios = new sender(app_secret_key_ios); // 根据topiclist做并集运算, 发送消息到指定一组设备上 sender_ios.broadcastall(message, 3 ); } /** * 指定标签推送(推送指定类型用户) * @param messagepayload 消息 * @param title 消息标题 * @param description 消息描述 * @param ads_type 消息类型 * @param ads_links 消息链接 * @param topiclist 指定推送类型 * @throws ioexception * @throws parseexception **/ public static void sendbroadcast(string messagepayload, string title, string description, string ads_type, string ads_links, list<string> topiclist) throws ioexception, parseexception { constants.useofficial(); map map = new hashmap(); map.put( "ads_type" , ads_type); map.put( "ads_links" , ads_links); message message = new message.builder().title(title).description(description).payload(messagepayload) .extra( "data" , jsonobject.fromobject(map).tostring()).restrictedpackagename(my_package_name) .notifytype( 1 ).passthrough( 0 ) // 使用默认提示音提示 .build(); // 安卓推送 sender sender_android = new sender(app_secret_key_android); // 根据topiclist做并集运算, 发送消息到指定一组设备上 sender_android.multitopicbroadcast(message, topiclist, broadcast_topic_op.union, 3 ); // ios推送 //constants.usesandbox(); sender sender_ios = new sender(app_secret_key_ios); // 根据topiclist做并集运算, 发送消息到指定一组设备上 sender_ios.multitopicbroadcast(message, topiclist, broadcast_topic_op.union, 3 ); } /** * 指定alias推送(单个或多个) * @param messagepayload 消息 * @param title 消息标题 * @param description 消息描述 * @param ads_type 消息类型 * @param ads_links 消息链接 * @param aliaslist 指定alias * @throws ioexception * @throws parseexception **/ public static void sendmessagetoaliases(string messagepayload, string title, string description, string ads_type, string ads_links, list<string> aliaslist) throws ioexception, parseexception { constants.useofficial(); map map = new hashmap(); map.put( "ads_type" , ads_type); map.put( "ads_links" , ads_links); message message = new message.builder().title(title).description(description).payload(messagepayload) .extra( "data" , jsonobject.fromobject(map).tostring()).restrictedpackagename(my_package_name) .notifytype( 1 ).passthrough( 0 ) // 使用默认提示音提示 .build(); //安卓推送 sender sender_android = new sender(app_secret_key_android); sender_android.sendtoalias(message, aliaslist, 3 ); //ios推送 //constants.usesandbox(); sender sender_ios = new sender(app_secret_key_ios); sender_ios.sendtoalias(message, aliaslist, 3 ); } } |
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对服务器之家的支持。如果你想了解更多相关内容请查看下面相关链接
原文链接:https://blog.csdn.net/qq_36473199/article/details/79562075