admin
2020-05-06 24a8d17e007545f7426c48352109aa1a9c6587ee
fanli/src/main/java/com/yeshi/fanli/util/push/XiaoMiPushUtil.java
@@ -76,6 +76,7 @@
      Message message = null; // 做循环传来的key
      Builder builder = new Message.Builder().restrictedPackageName(PackageName).title(title).payload(payload)
            .notifyId((int) (Math.random() * Integer.MAX_VALUE))
            .description(description).passThrough(0) // 设置消息是否通过透传方式至App,
                                             // 1表示透传,0表示通知栏消息(默认)
            .notifyType(1); // 设置通知类型, type类型(1-默认提示音, 2-使用默认震动提示,
@@ -129,6 +130,7 @@
      Message message = null; // 做循环传来的key
      Builder builder = new Message.Builder().restrictedPackageName(PackageName).title(title).payload(payload)
            .notifyId((int) (Math.random() * Integer.MAX_VALUE))
            .description(description).passThrough(0) // 设置消息是否通过透传方式至App,
                                             // 1表示透传,0表示通知栏消息(默认)
            .notifyType(1); // 设置通知类型, type类型(1-默认提示音, 2-使用默认震动提示,
@@ -161,7 +163,8 @@
    * @param system
    * @return
    */
   public static String singlePushAndroidForXM(MessageInfo info, Map<String, Object> map, System system) {
   public static String singlePushAndroidForXM(MessageInfo info, Map<String, Object> map, List<String> regIds,
         System system) {
      String name = info.getPackageName();
      if (!Constant.systemCommonConfig.getAndroidPackageName().equalsIgnoreCase(name)
            && !Constant.systemCommonConfig.getIosBundleId().equalsIgnoreCase(name)) {
@@ -177,8 +180,10 @@
      Message message = null; // 做循环传来的key
      Builder builder = new Message.Builder().restrictedPackageName(PackageName).title(title).description(content)
            .passThrough(0) // 设置消息是否通过透传方式至App, 1表示透传,0表示通知栏消息(默认)
            .notifyType(1); // 设置通知类型, type类型(1-默认提示音, 2-使用默认震动提示,
                        // 3-使用默认led灯光提示)
            .notifyId((int) (Math.random() * Integer.MAX_VALUE)).notifyType(1); // 设置通知类型,
                                                               // type类型(1-默认提示音,
                                                               // 2-使用默认震动提示,
      // 3-使用默认led灯光提示)
      // 将extra放入MessageInfo对象中, 循环遍历extra中的key 和 value
      if (map != null) {
         for (String key : map.keySet()) {
@@ -187,7 +192,8 @@
      }
      message = builder.build();
      try {
         Result result = sender.sendToAlias(message, uId, 3);
         Result result = sender.send(message, regIds, 3); // sender.sendToAlias(message,
                                                // uId, 3);
         PushLogHelper.xmInfo("推送结果:" + result.getReason());
         return result.getMessageId();
      } catch (IOException e) {
@@ -205,14 +211,13 @@
    * @author mawurui createTime 2018年3月8日 上午9:55:14
    * @param info
    */
   public static void pushByHongBao(String alias, System system) {
   public static void pushByHongBao(List<String> regIds, System system) {
      MessageInfo info = new MessageInfo();
      info.setAlias(alias);
      info.setTitle("新到红包");
      info.setDescription("红包到来了...");
      JSONObject jsonObject = new JSONObject();
      jsonObject.put("type", "hongbao");
      XiaoMiPushUtil.singlePushAndroidForXM(info, JsonUtil.parseData(jsonObject), system);
      XiaoMiPushUtil.singlePushAndroidForXM(info, JsonUtil.parseData(jsonObject), regIds, system);
   }
   /**
@@ -222,14 +227,13 @@
    * @author mawurui createTime 2018年3月8日 上午10:00:16
    * @param info
    */
   public static void pushByApply(String alias, System system) {
   public static void pushByApply(List<String> regIds, System system) {
      MessageInfo info = new MessageInfo();
      info.setAlias(alias);
      info.setTitle("提现申请");
      info.setDescription("提现审核中...");
      JSONObject jsonObject = new JSONObject();
      jsonObject.put("type", "cash");
      XiaoMiPushUtil.singlePushAndroidForXM(info, JsonUtil.parseData(jsonObject), system);
      XiaoMiPushUtil.singlePushAndroidForXM(info, JsonUtil.parseData(jsonObject), regIds, system);
   }
   /**
@@ -241,9 +245,8 @@
    * @param state
    * @param system
    */
   public static void pushByExtract(String alias, int state, System system) {
   public static void pushByExtract(List<String> regIds, int state, System system) {
      MessageInfo info = new MessageInfo();
      info.setAlias(alias);
      if (state == 0) {
         info.setTitle("提现成功");
         info.setDescription("您有一笔交易,已提现成功!");
@@ -256,7 +259,7 @@
      }
      JSONObject jsonObject = new JSONObject();
      jsonObject.put("type", "cash");
      XiaoMiPushUtil.singlePushAndroidForXM(info, JsonUtil.parseData(jsonObject), system);
      XiaoMiPushUtil.singlePushAndroidForXM(info, JsonUtil.parseData(jsonObject), regIds, system);
   }
   /**
@@ -279,12 +282,11 @@
      }
   }
   public static void pushZNX(Long uid, String title, String content, String msgId) {
   public static void pushZNX(List<String> regIds, String title, String content, String msgId) {
      // 小米开始推送
      MessageInfo info = new MessageInfo();
      info.setActivty(
            String.format("%s.ui.BrowserActivity", Constant.systemCommonConfig.getAndroidBaseactivityName()));
      info.setAlias(uid + "");
      info.setTitle(title);
      info.setContent(content);
      info.setPackageName(Constant.systemCommonConfig.getAndroidPackageName());
@@ -301,7 +303,7 @@
      contentJson.put("createTime", java.lang.System.currentTimeMillis());
      json.put("content", contentJson);
      JSONObject mapXm = JSONObject.fromObject(json);
      XiaoMiPushUtil.singlePushAndroidForXM(info, mapXm, null);
      XiaoMiPushUtil.singlePushAndroidForXM(info, mapXm, regIds, null);
   }
}