From 88b54772dbcf5ecab1e2316e4e4626ac901b8908 Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期二, 22 一月 2019 15:58:24 +0800
Subject: [PATCH] 邀请码添加返回状态

---
 fanli/src/main/java/com/yeshi/fanli/util/factory/IOSPushFactory.java |   87 +++++++++++++++++++++++++++++++++++++------
 1 files changed, 75 insertions(+), 12 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/factory/IOSPushFactory.java b/fanli/src/main/java/com/yeshi/fanli/util/factory/IOSPushFactory.java
index 13d5789..08e33d1 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/factory/IOSPushFactory.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/factory/IOSPushFactory.java
@@ -1,5 +1,7 @@
 package com.yeshi.fanli.util.factory;
 
+import java.io.UnsupportedEncodingException;
+
 import com.yeshi.fanli.controller.admin.PushController;
 import com.yeshi.fanli.util.StringUtil;
 
@@ -9,21 +11,34 @@
 
 	private static JSONObject filterPushContent(JSONObject json) {
 		if (json != null)
-			while (json.toString().getBytes().length > 256) {
-				// 棣栧厛鍓婂噺鍐呭锛岀劧鍚庡墛鍑忔爣棰�
-				String title = json.optJSONObject("aps").optJSONObject("alert").optString("title");
-				String body = json.optJSONObject("aps").optJSONObject("alert").optString("body");
-				if (StringUtil.isNullOrEmpty(body) || body.length() < 4) {
-					// 鍓婂噺鏍囬
-					if (!StringUtil.isNullOrEmpty(title) && body.length() > 6) {
-						json.optJSONObject("aps").optJSONObject("alert").put("title",
-								title.substring(0, title.length() - 1));
+			try {
+				boolean ischange = false;
+				while (json.toString().getBytes("UTF-8").length > 253) {
+					// 棣栧厛鍓婂噺鍐呭锛岀劧鍚庡墛鍑忔爣棰�
+					String title = json.optJSONObject("aps").optJSONObject("alert").optString("title");
+					String body = json.optJSONObject("aps").optJSONObject("alert").optString("body");
+					if (StringUtil.isNullOrEmpty(body) || body.length() < 4) {
+						// 鍓婂噺鏍囬
+						if (!StringUtil.isNullOrEmpty(title) && title.length() > 6) {
+							json.optJSONObject("aps").optJSONObject("alert").put("title",
+									title.substring(0, title.length() - 1));
+							continue;
+						}
+					} else {
+						ischange = true;
+						json.optJSONObject("aps").optJSONObject("alert").put("body",
+								body.substring(0, body.length() - 1));
 						continue;
 					}
-				} else {
-					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();
 			}
 		return json;
 	}
@@ -99,4 +114,52 @@
 		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);
+		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);
+		JSONObject json = new JSONObject();
+		json.put("aps", aps);
+		return filterPushContent(json);
+	}
+
 }

--
Gitblit v1.8.0