admin
2019-07-11 3824cbcaec6e6c67418d5280a53e9c2fedeef6f9
fanli/src/main/java/com/yeshi/fanli/util/factory/IOSPushFactory.java
@@ -12,7 +12,7 @@
   private static JSONObject filterPushContent(JSONObject json) {
      if (json != null)
         try {
            boolean ischange= false;
            boolean ischange = false;
            while (json.toString().getBytes("UTF-8").length > 253) {
               // 首先削减内容,然后削减标题
               String title = json.optJSONObject("aps").optJSONObject("alert").optString("title");
@@ -26,16 +26,17 @@
                  }
               } else {
                  ischange = true;
                  json.optJSONObject("aps").optJSONObject("alert").put("body", body.substring(0, body.length() - 1));
                  json.optJSONObject("aps").optJSONObject("alert").put("body",
                        body.substring(0, body.length() - 1));
                  continue;
               }
            }
            if (ischange) {
               String body = json.optJSONObject("aps").optJSONObject("alert").optString("body");
               json.optJSONObject("aps").optJSONObject("alert").put("body", body + "...");
            }
         } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
         }
@@ -62,6 +63,7 @@
      JSONObject aps = new JSONObject();
      aps.put("alert", alert);
      //aps.put("badge", 1);
      JSONObject json = new JSONObject();
      json.put("aps", aps);
      return filterPushContent(json);
@@ -83,6 +85,7 @@
      alert.put("type", PushController.ZNX);
      JSONObject aps = new JSONObject();
      aps.put("alert", alert);
      //aps.put("badge", 1);
      JSONObject json = new JSONObject();
      json.put("aps", aps);
      return filterPushContent(json);
@@ -108,6 +111,79 @@
      JSONObject aps = new JSONObject();
      aps.put("alert", alert);
      //aps.put("badge", 1);
      JSONObject json = new JSONObject();
      json.put("aps", aps);
      return filterPushContent(json);
   }
   /**
    * WEEX页面推送
    *
    * @param shortUrl
    * @param title
    * @param body
    * @return
    */
   public static JSONObject createWEEXPush(String shortUrl, String title, String body) {
      JSONObject alert = new JSONObject();
      alert.put("title", title);
      alert.put("body", body);
      alert.put("badge", "1");
      alert.put("sound", "default");
      alert.put("type", PushController.WEEX);
      alert.put("url", shortUrl);
      JSONObject aps = new JSONObject();
      aps.put("alert", alert);
      //aps.put("badge", 1);
      JSONObject json = new JSONObject();
      json.put("aps", aps);
      return filterPushContent(json);
   }
   /**
    * 百川网页推送
    *
    * @param shortUrl
    * @param title
    * @param body
    * @return
    */
   public static JSONObject createBaiChuanPush(String shortUrl, String title, String body) {
      JSONObject alert = new JSONObject();
      alert.put("title", title);
      alert.put("body", body);
      alert.put("badge", "1");
      alert.put("sound", "default");
      alert.put("type", PushController.BAICHUAN);
      alert.put("url", shortUrl);
      JSONObject aps = new JSONObject();
      aps.put("alert", alert);
      //aps.put("badge", 1);
      JSONObject json = new JSONObject();
      json.put("aps", aps);
      return filterPushContent(json);
   }
   /**
    * 福利中心推送
    * @param title
    * @param body
    * @return
    */
   public static JSONObject createWelfarePush( String title, String body) {
      JSONObject alert = new JSONObject();
      alert.put("title", title);
      alert.put("body", body);
      alert.put("badge", "1");
      alert.put("sound", "default");
      alert.put("type", PushController.WELFARE_CENTER);
      JSONObject aps = new JSONObject();
      aps.put("alert", alert);
      //aps.put("badge", 1);
      JSONObject json = new JSONObject();
      json.put("aps", aps);
      return filterPushContent(json);