maven
<dependency> <groupId></groupId> <artifactId>json-simple</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId></groupId> <artifactId>MiPush_SDK_Server</artifactId> <version>2.2.18</version> </dependency>
java util
package com.; import ; import ; import ; import .BROADCAST_TOPIC_OP; import ; import ; import ; import ; import ; import ; /** * Xiaomi push tool category **/ 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"; /** * Send push to all devices * @param messagePayload message * @param title message title * @param description Message description * @param ads_type Message type * @param ads_links message link * @throws IOException * @throws ParseException **/ public static void sendAllBroadcast(String messagePayload, String title, String description, String ads_type, String ads_links) throws IOException, ParseException { (); Map map = new HashMap(); ("ads_type", ads_type); ("ads_links", ads_links); Message message = new ().title(title).description(description).payload(messagePayload) .extra("data", (map).toString()).restrictedPackageName(MY_PACKAGE_NAME) .notifyType(1).passThrough(0) // Use default prompts .build(); //Android push Sender sender_android = new Sender(APP_SECRET_KEY_ANDROID); // Concatenate the union operation according to topicList and send a message to the specified group of devices sender_android.broadcastAll(message, 3); //ios push Sender sender_ios = new Sender(APP_SECRET_KEY_IOS); // Concatenate the union operation according to topicList and send a message to the specified group of devices sender_ios.broadcastAll(message, 3); } /** * Specify tag push (push the specified type of user) * @param messagePayload message * @param title message title * @param description Message description * @param ads_type Message type * @param ads_links message link * @param topicList Specify the push type * @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 { (); Map map = new HashMap(); ("ads_type", ads_type); ("ads_links", ads_links); Message message = new ().title(title).description(description).payload(messagePayload) .extra("data", (map).toString()).restrictedPackageName(MY_PACKAGE_NAME) .notifyType(1).passThrough(0) // Use default prompts .build(); // Android push Sender sender_android = new Sender(APP_SECRET_KEY_ANDROID); // Concatenate the union operation according to topicList and send a message to the specified group of devices sender_android.multiTopicBroadcast(message, topicList, BROADCAST_TOPIC_OP.UNION, 3); // ios push //(); Sender sender_ios = new Sender(APP_SECRET_KEY_IOS); // Concatenate the union operation according to topicList and send a message to the specified group of devices sender_ios.multiTopicBroadcast(message, topicList, BROADCAST_TOPIC_OP.UNION, 3); } /** * Specify alias push (single or multiple) * @param messagePayload message * @param title message title * @param description Message description * @param ads_type Message type * @param ads_links message link * @param aliasList Specify 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 { (); Map map = new HashMap(); ("ads_type", ads_type); ("ads_links", ads_links); Message message = new ().title(title).description(description).payload(messagePayload) .extra("data", (map).toString()).restrictedPackageName(MY_PACKAGE_NAME) .notifyType(1).passThrough(0) // Use default prompts .build(); //Android push Sender sender_android = new Sender(APP_SECRET_KEY_ANDROID); sender_android.sendToAlias(message, aliasList, 3); //ios push //(); Sender sender_ios = new Sender(APP_SECRET_KEY_IOS); sender_ios.sendToAlias(message, aliasList, 3); } }
Summarize
The above is the entire content of this article. I hope that the content of this article has certain reference value for your study or work. Thank you for your support. If you want to know more about it, please see the following links