From 573c491b4a1ba60e12a5678a01c1546c0077c1ee Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 30 七月 2019 09:07:42 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 fanli/src/main/java/com/yeshi/fanli/util/push/IOSPushUtil.java |   67 ++++++++++++++++++++++++---------
 1 files changed, 48 insertions(+), 19 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/push/IOSPushUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/push/IOSPushUtil.java
index 5a7afed..507261a 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/push/IOSPushUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/push/IOSPushUtil.java
@@ -8,19 +8,18 @@
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.yeshi.utils.HttpUtil;
 
 import com.google.gson.Gson;
 import com.yeshi.fanli.controller.admin.PushController;
-import com.yeshi.fanli.entity.system.System;
 import com.yeshi.fanli.entity.xinge.MessageInfo;
 import com.yeshi.fanli.entity.xinge.PushRecord;
 import com.yeshi.fanli.log.LogHelper;
 import com.yeshi.fanli.log.PushLogHelper;
-import com.yeshi.fanli.service.inter.config.SystemService;
+import com.yeshi.fanli.service.inter.config.BusinessSystemService;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.factory.IOSPushFactory;
-import org.yeshi.utils.HttpUtil;
 
 import javapns.devices.Device;
 import javapns.devices.implementations.basic.BasicDevice;
@@ -36,12 +35,12 @@
 	private static IOSPushUtil iosPushUtil;
 
 	@Autowired
-	private SystemService systemService;
+	private BusinessSystemService businessSystemService;
 
 	@PostConstruct
 	public void init() {
 		iosPushUtil = this;
-		iosPushUtil.systemService = this.systemService;
+		iosPushUtil.businessSystemService = this.businessSystemService;
 	}
 
 	/**
@@ -57,6 +56,9 @@
 	 */
 	public static String allPushIOS(List<String> deviceTokenList, MessageInfo info, String url, int type)
 			throws Exception {
+
+		if (Constant.IS_TEST)
+			return null;
 
 		Gson gson = new Gson();
 		PushLogHelper.iosInfo("IOS鎺ㄩ�佽澶囨暟涓�:" + deviceTokenList.size());
@@ -88,9 +90,24 @@
 			json = IOSPushFactory.createURLPush(shortUrl, info.getTitle(), info.getContent());
 		} else if (type == PushController.ZNX) {
 			json = IOSPushFactory.createZNXPush(info.getTitle(), info.getContent());
+		} else if (type == PushController.WEEX) {
+			String shortUrl = HttpUtil.getShortLink(url);
+			if (StringUtil.isNullOrEmpty(shortUrl))
+				throw new Exception("鑾峰彇鐭摼鍑洪敊");
+			json = IOSPushFactory.createWEEXPush(shortUrl, info.getTitle(), info.getContent());
+		} else if (type == PushController.BAICHUAN) {
+			String shortUrl = HttpUtil.getShortLink(url);
+			if (StringUtil.isNullOrEmpty(shortUrl))
+				throw new Exception("鑾峰彇鐭摼鍑洪敊");
+			json = IOSPushFactory.createBaiChuanPush(shortUrl, info.getTitle(), info.getContent());
+		} else if (type == PushController.WELFARE_CENTER) {
+			json = IOSPushFactory.createWelfarePush(info.getTitle(), info.getContent());
 		}
 		// 鍒嗙粍鎺ㄩ�� 姣�50涓澶囦负涓�缁�
 
+		InputStream certificate = IOSPushUtil.class.getClassLoader()
+				.getResourceAsStream("certificate/pushCertificate.p12"); // 璇诲彇.p12鏂囦欢
+		String certificatePassword = Constant.systemCommonConfig.getIosPushCertificatePwd();
 		if (tokenList != null && tokenList.size() > 0) {
 			int pageSize = 50;
 			int page = tokenList.size() % pageSize == 0 ? tokenList.size() / pageSize : tokenList.size() / pageSize + 1;
@@ -99,7 +116,7 @@
 				int end = start + pageSize;
 				if (end > tokenList.size())
 					end = tokenList.size();
-				pushIOS(tokenList.subList(start, end), json);
+				pushIOS(tokenList.subList(start, end), json, certificate, certificatePassword);
 			}
 
 		}
@@ -107,14 +124,12 @@
 		return null;
 	}
 
-	private static String pushIOS(List<String> deviceTokenList, JSONObject json) throws Exception {
+	public static String pushIOS(List<String> deviceTokenList, JSONObject json, InputStream certificate,
+			String certificatePWD) throws Exception {
 		List<String> tokenList = new ArrayList<String>();
 		for (String deviceToken : deviceTokenList) {
 			tokenList.add(deviceToken);
 		}
-		InputStream certificate = IOSPushUtil.class.getClassLoader()
-				.getResourceAsStream("certificate/pushCertificate.p12"); // 璇诲彇.p12鏂囦欢
-		String certificatePassword = Constant.systemCommonConfig.getIosPushCertificatePwd();// 姝ゅ娉ㄦ剰瀵煎嚭鐨勮瘉涔﹀瘑鐮佷笉鑳戒负绌哄洜涓虹┖瀵嗙爜浼氭姤閿�
 		while (json.toString().getBytes().length > 256) {
 			// 棣栧厛鍓婂噺鍐呭锛岀劧鍚庡墛鍑忔爣棰�
 			String title = json.optJSONObject("aps").optJSONObject("alert").optString("title");
@@ -138,7 +153,10 @@
 
 		PushNotificationManager pushManager = new PushNotificationManager();
 		// true锛氳〃绀虹殑鏄骇鍝佺嚎涓婂彂甯冩帹閫佹湇鍔� false锛氳〃绀虹殑鏄骇鍝佹祴璇曟帹閫佹湇鍔�
-		pushManager.initializeConnection(new AppleNotificationServerBasicImpl(certificate, certificatePassword, true));
+		if (Constant.IS_TEST)
+			pushManager.initializeConnection(new AppleNotificationServerBasicImpl(certificate, certificatePWD, false));
+		else
+			pushManager.initializeConnection(new AppleNotificationServerBasicImpl(certificate, certificatePWD, true));
 
 		List<Device> deviceList = new ArrayList<Device>();
 		for (String token : tokenList) {
@@ -193,19 +211,21 @@
 			return 4;
 		}
 	}
-	
-	
+
 	/**
 	 * 鎵ц鎺ㄩ��
+	 * 
 	 * @param tokenList
 	 * @param json
 	 * @throws Exception
 	 */
-	public static void executePushIOS(List<String> tokenList, JSONObject json) throws Exception{
-		pushIOS(tokenList, json);
+	public static void executePushIOS(List<String> tokenList, JSONObject json) throws Exception {
+		InputStream certificate = IOSPushUtil.class.getClassLoader()
+				.getResourceAsStream("certificate/pushCertificate.p12"); // 璇诲彇.p12鏂囦欢
+		String certificatePassword = Constant.systemCommonConfig.getIosPushCertificatePwd();
+		pushIOS(tokenList, json, certificate, certificatePassword);
 	}
-	
-	
+
 	/**
 	 * 
 	 * 鏂规硶璇存槑: IOS 澶氭帹
@@ -217,8 +237,7 @@
 	 * @return
 	 * @throws Exception
 	 */
-	public static JSONObject getJSONObject(MessageInfo info, String url, int type)
-			throws Exception {
+	public static JSONObject getJSONObject(MessageInfo info, String url, int type) throws Exception {
 
 		// json鑷畾涔変紶鍊�
 		JSONObject json = null;
@@ -242,6 +261,16 @@
 			json = IOSPushFactory.createURLPush(shortUrl, info.getTitle(), info.getContent());
 		} else if (type == PushController.ZNX) {
 			json = IOSPushFactory.createZNXPush(info.getTitle(), info.getContent());
+		} else if (type == PushController.WEEX) {
+			String shortUrl = HttpUtil.getShortLink(url);
+			if (StringUtil.isNullOrEmpty(shortUrl))
+				shortUrl = url;
+			json = IOSPushFactory.createWEEXPush(shortUrl, info.getTitle(), info.getContent());
+		} else if (type == PushController.BAICHUAN) {
+			String shortUrl = HttpUtil.getShortLink(url);
+			if (StringUtil.isNullOrEmpty(shortUrl))
+				shortUrl = url;
+			json = IOSPushFactory.createBaiChuanPush(shortUrl, info.getTitle(), info.getContent());
 		}
 
 		return json;

--
Gitblit v1.8.0