maven
com.xiaomi json-simple1.1.1 com.xiaomi MiPush_SDK_Server2.2.18
java util
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";
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);
}
public static void sendBroadcast(String messagePayload, String title, String description, String ads_type,
String ads_links, List 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);
}
public static void sendMessageToAliases(String messagePayload, String title, String description, String ads_type,
String ads_links, List 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);
}
}
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对考高分网的支持。如果你想了解更多相关内容请查看下面相关链接



