From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 25 二月 2025 16:41:22 +0800
Subject: [PATCH] 淘宝转链接口更新

---
 fanli/src/main/java/com/yeshi/fanli/util/factory/IOSPushFactory.java |  293 +++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 215 insertions(+), 78 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 99ac5c5..e84c5e3 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,78 +1,215 @@
-package com.yeshi.fanli.util.factory;
-
-import com.yeshi.fanli.controller.admin.PushController;
-
-import net.sf.json.JSONObject;
-
-public class IOSPushFactory {
-	/**
-	 * IOS鍟嗗搧鎺ㄩ��    杩斿洖JSON鐨勫瓧绗︿覆闀垮害灏忎簬绛変簬256
-	 * 
-	 * @param auctionId
-	 *            娣樺疂鍟嗗搧ID
-	 * @param title
-	 * @param body
-	 * @return
-	 */
-	public static JSONObject createGoodsPush(Long auctionId, 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("url", "http://id=" + auctionId);
-		alert.put("type", PushController.GOODS);
-		JSONObject aps = new JSONObject();
-		aps.put("alert", alert);
-		JSONObject json = new JSONObject();
-		json.put("aps", aps);
-		return json;
-	}
-
-	/**
-	 * IOS绔欏唴淇℃帹閫�    杩斿洖JSON鐨勫瓧绗︿覆闀垮害灏忎簬绛変簬256
-	 * 
-	 * @param title
-	 * @param body
-	 * @return
-	 */
-	public static JSONObject createZNXPush(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.ZNX);
-		JSONObject aps = new JSONObject();
-		aps.put("alert", alert);
-		JSONObject json = new JSONObject();
-		json.put("aps", aps);
-		return json;
-	}
-
-	/**
-	 * IOS閾炬帴鎺ㄩ��    杩斿洖JSON鐨勫瓧绗︿覆闀垮害灏忎簬绛変簬256
-	 * 
-	 * @param shortUrl
-	 *            鐭摼
-	 * @param title
-	 * @param body
-	 * @return
-	 */
-	public static JSONObject createURLPush(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.URL);
-		alert.put("url", shortUrl);
-
-		JSONObject aps = new JSONObject();
-		aps.put("alert", alert);
-		JSONObject json = new JSONObject();
-		json.put("aps", aps);
-		return json;
-	}
-
-}
+package com.yeshi.fanli.util.factory;
+
+import java.io.UnsupportedEncodingException;
+
+import com.yeshi.fanli.dto.push.PushTypeEnum;
+import com.yeshi.fanli.util.StringUtil;
+
+import net.sf.json.JSONObject;
+
+public class IOSPushFactory {
+
+	private static JSONObject filterPushContent(JSONObject json) {
+		if (json != null)
+			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;
+					}
+				}
+
+				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;
+	}
+
+	/**
+	 * IOS鍟嗗搧鎺ㄩ�� 杩斿洖JSON鐨勫瓧绗︿覆闀垮害灏忎簬绛変簬256
+	 * 
+	 * @param auctionId
+	 *            娣樺疂鍟嗗搧ID
+	 * @param title
+	 * @param body
+	 * @return
+	 */
+	public static JSONObject createGoodsPush(String auctionId, 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("url", "http://id=" + auctionId);
+		alert.put("type",PushTypeEnum.goodsdetail.getCode());
+
+		JSONObject aps = new JSONObject();
+		aps.put("alert", alert);
+		//aps.put("badge", 1);
+		JSONObject json = new JSONObject();
+		json.put("aps", aps);
+		return filterPushContent(json);
+	}
+
+	/**
+	 * IOS绔欏唴淇℃帹閫� 杩斿洖JSON鐨勫瓧绗︿覆闀垮害灏忎簬绛変簬256
+	 * 
+	 * @param title
+	 * @param body
+	 * @return
+	 */
+	public static JSONObject createZNXPush(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", PushTypeEnum.ZNX.getCode());
+		JSONObject aps = new JSONObject();
+		aps.put("alert", alert);
+		//aps.put("badge", 1);
+		JSONObject json = new JSONObject();
+		json.put("aps", aps);
+		return filterPushContent(json);
+	}
+
+	/**
+	 * IOS閾炬帴鎺ㄩ�� 杩斿洖JSON鐨勫瓧绗︿覆闀垮害灏忎簬绛変簬256
+	 * 
+	 * @param shortUrl
+	 *            鐭摼
+	 * @param title
+	 * @param body
+	 * @return
+	 */
+	public static JSONObject createURLPush(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",PushTypeEnum.url.getCode());
+		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);
+	}
+
+	/**
+	 * 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", PushTypeEnum.weex.getCode());
+		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", PushTypeEnum.baichuan.getCode());
+		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", PushTypeEnum.welfare.getCode());
+
+		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 createUserSignInPush( 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", PushTypeEnum.signin.getCode());
+
+		JSONObject aps = new JSONObject();
+		aps.put("alert", alert);
+		//aps.put("badge", 1);
+		JSONObject json = new JSONObject();
+		json.put("aps", aps);
+		return filterPushContent(json);
+	}
+	
+}

--
Gitblit v1.8.0