From 24a8d17e007545f7426c48352109aa1a9c6587ee Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 06 五月 2020 12:02:09 +0800
Subject: [PATCH] IOS上线隐藏我的界面的banner与超级会员升级信息

---
 fanli/src/main/java/com/yeshi/fanli/util/push/HWPushUtil.java |  139 ++++++++++++++++++++++++++++++++++------------
 1 files changed, 102 insertions(+), 37 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/push/HWPushUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/push/HWPushUtil.java
index 7fff6a6..a0d5e96 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/push/HWPushUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/push/HWPushUtil.java
@@ -3,8 +3,10 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.net.URLDecoder;
 import java.net.URLEncoder;
 import java.text.MessageFormat;
 import java.util.List;
@@ -15,14 +17,14 @@
 import org.apache.commons.io.IOUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.yeshi.utils.annotation.MapUtil;
 
 import com.alibaba.fastjson.JSONObject;
 import com.yeshi.fanli.entity.config.push.HWPushConfig;
-import com.yeshi.fanli.exception.PushException;
-import com.yeshi.fanli.service.inter.config.SystemService;
+import com.yeshi.fanli.exception.push.PushException;
+import com.yeshi.fanli.service.inter.config.BusinessSystemService;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.taobao.TaoBaoUtil;
-import org.yeshi.utils.annotation.MapUtil;
 
 import net.sf.json.JSONArray;
 
@@ -32,12 +34,12 @@
 	private static HWPushUtil hWPushUtil;
 
 	@Autowired
-	private SystemService systemService;
+	private BusinessSystemService businessSystemService;
 
 	@PostConstruct
 	public void init() {
 		hWPushUtil = this;
-		hWPushUtil.systemService = this.systemService;
+		hWPushUtil.businessSystemService = this.businessSystemService;
 	}
 
 	private static String appSecret = "";
@@ -55,6 +57,29 @@
 		appSecret = config.getAppSecret();
 	}
 
+	private static String getIntent(String type, String activity, String url, String webUrl, Long id) {
+		net.sf.json.JSONObject data = new net.sf.json.JSONObject();
+		if (type != null)
+			data.put("type", type);
+		if (activity != null)
+			data.put("activity", activity);
+		if (url != null)
+			data.put("url", url);
+		if (webUrl != null)
+			data.put("webUrl", webUrl);
+		if (id != null)
+			data.put("id", id);
+
+		try {
+			return String.format(
+					"intent://flq/hmpush?data=%s#Intent;scheme=banliapp;launchFlags=0x4000000;end",
+					URLDecoder.decode(data.toString(), "UTF-8"));
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
 	/**
 	 * 鎺ㄩ�佸晢鍝�
 	 * 
@@ -68,15 +93,13 @@
 	 */
 	public static void pushGoods(List<String> deviceTokens, String title, String content, int goodsType, Long goodsId)
 			throws PushException {
-		if (deviceTokens != null && deviceTokens.size() > 1000)
-			throw new PushException(1, "璁惧鏁颁笉鑳借秴杩�1000涓�");
+		if (deviceTokens != null && deviceTokens.size() > 100)
+			throw new PushException(1, "璁惧鏁颁笉鑳借秴杩�100涓�");
 
 		String activity = Constant.systemCommonConfig.getAndroidBaseactivityName()
 				+ ".ui.recommend.GoodsBrowserActivity";
-		activity = activity.replace(Constant.systemCommonConfig.getAndroidPackageName(),
-				Constant.systemCommonConfig.getAndroidPackageName() + "/");
+		String intent = getIntent("goodsdetail", activity, null, null, goodsId);
 
-		String intent = "intent:#Intent;launchFlags=0x4000000;component=" + activity + ";S.id=" + goodsId + ";end";
 		try {
 			String result = sendPushHWMessageForIntent(deviceTokens, title, content, intent);
 			net.sf.json.JSONObject data = net.sf.json.JSONObject.fromObject(result);
@@ -98,17 +121,13 @@
 	 *            -缃戦〉閾炬帴
 	 * @throws PushException
 	 */
-	public static void pushWeb(List<String> deviceTokens, String title, String content, String url)
+	public static void pushUrl(List<String> deviceTokens, String title, String content, String url)
 			throws PushException {
-		if (deviceTokens != null && deviceTokens.size() > 1000)
+		if (deviceTokens != null && deviceTokens.size() > 100)
 			throw new PushException(1, "璁惧鏁颁笉鑳借秴杩�1000涓�");
 
 		String activity = Constant.systemCommonConfig.getAndroidBaseactivityName() + ".ui.invite.ShareBrowserActivity";
-		activity = activity.replace(Constant.systemCommonConfig.getAndroidPackageName(),
-				Constant.systemCommonConfig.getAndroidPackageName() + "/");
-
-		String intent = "intent:#Intent;launchFlags=0x4000000;component=" + activity + ";S.url="
-				+ URLEncoder.encode(url) + ";end";
+		String intent = getIntent("url", activity, null, url, null);
 		try {
 			String result = sendPushHWMessageForIntent(deviceTokens, title, content, intent);
 			net.sf.json.JSONObject data = net.sf.json.JSONObject.fromObject(result);
@@ -131,14 +150,12 @@
 	 * @throws PushException
 	 */
 	public static void pushZNX(List<String> deviceTokens, String title, String content) throws PushException {
-		if (deviceTokens != null && deviceTokens.size() > 1000)
-			throw new PushException(1, "璁惧鏁颁笉鑳借秴杩�1000涓�");
+		if (deviceTokens != null && deviceTokens.size() > 100)
+			throw new PushException(1, "璁惧鏁颁笉鑳借秴杩�100涓�");
+		String intent = getIntent("ZNX", null, null, null, null);
+		if (intent == null)
+			return;
 
-		String activity = Constant.systemCommonConfig.getAndroidBaseactivityName() + ".ui.mine.AppMailActivity";
-		activity = activity.replace(Constant.systemCommonConfig.getAndroidPackageName(),
-				Constant.systemCommonConfig.getAndroidPackageName() + "/");
-
-		String intent = "intent:#Intent;launchFlags=0x4000000;component=" + activity + ";end";
 		try {
 			String result = sendPushHWMessageForIntent(deviceTokens, title, content, intent);
 			net.sf.json.JSONObject data = net.sf.json.JSONObject.fromObject(result);
@@ -149,20 +166,64 @@
 		}
 	}
 
-	/**
-	 * 鎺ㄩ�佺畝鍗曟枃瀛�
-	 * 
-	 * @param deviceTokens
-	 * @param title
-	 * @param content
-	 * @throws PushException
-	 */
+	public static void pushWEEX(List<String> deviceTokens, String title, String content, String weexUrl)
+			throws PushException {
+		String activity = Constant.systemCommonConfig.getAndroidBaseactivityName() + ".ui.mine.weex.WeexApplicationActivity";
+		String intent = getIntent("weex", activity, weexUrl, weexUrl, null);
+		if (intent == null)
+			return;
 
-	public static void pushSimpleText(List<String> deviceTokens, String title, String content) throws PushException {
-		if (deviceTokens != null && deviceTokens.size() > 1000)
-			throw new PushException(1, "璁惧鏁颁笉鑳借秴杩�1000涓�");
 		try {
-			String result = sendPushHWMessageForOpenApp(deviceTokens, title, content);
+			String result = sendPushHWMessageForIntent(deviceTokens, title, content, intent);
+			net.sf.json.JSONObject data = net.sf.json.JSONObject.fromObject(result);
+			if (!"success".equalsIgnoreCase(data.optString("msg")))
+				throw new PushException(2, result);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public static void pushBaiChuanUrl(List<String> deviceTokens, String title, String content, String url)
+			throws PushException {
+		String intent = getIntent("baichuan", null, url, null, null);
+		if (intent == null)
+			return;
+
+		try {
+			String result = sendPushHWMessageForIntent(deviceTokens, title, content, intent);
+			net.sf.json.JSONObject data = net.sf.json.JSONObject.fromObject(result);
+			if (!"success".equalsIgnoreCase(data.optString("msg")))
+				throw new PushException(2, result);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public static void pushWelfareCenter(List<String> deviceTokens, String title, String content) throws PushException {
+		String activity = Constant.systemCommonConfig.getAndroidBaseactivityName() + ".ui.mine.WelfareCenterActivity";
+		String intent = getIntent("welfare", activity, null, null, null);
+		if (intent == null)
+			return;
+
+		try {
+			String result = sendPushHWMessageForIntent(deviceTokens, title, content, intent);
+			net.sf.json.JSONObject data = net.sf.json.JSONObject.fromObject(result);
+			if (!"success".equalsIgnoreCase(data.optString("msg")))
+				throw new PushException(2, result);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+	
+
+	public static void pushUserSignInNotification(List<String> deviceTokens, String title, String content) throws PushException {
+		String activity = Constant.systemCommonConfig.getAndroidBaseactivityName() + ".ui.goldtask.GoldTaskActivity";
+		String intent = getIntent("signin", activity, null, null, null);
+		if (intent == null)
+			return;
+
+		try {
+			String result = sendPushHWMessageForIntent(deviceTokens, title, content, intent);
 			net.sf.json.JSONObject data = net.sf.json.JSONObject.fromObject(result);
 			if (!"success".equalsIgnoreCase(data.optString("msg")))
 				throw new PushException(2, result);
@@ -207,8 +268,10 @@
 
 		// 瀹氫箟闇�瑕佹墦寮�鐨刟ppPkgName
 		JSONObject param = new JSONObject();
+		// param.put("url", "http://www.baidu.com");
 
 		param.put("intent", intent);
+		// param.put("appPkgName", "com.yeshi.ec.rebate");
 
 		JSONObject action = new JSONObject();
 		action.put("type", 1);// 锛�1 鑷畾涔夎涓猴細琛屼负鐢卞弬鏁癷ntent瀹氫箟锛�2 鎵撳紑URL锛歎RL鍦板潃鐢卞弬鏁皍rl瀹氫箟锛�3
@@ -222,7 +285,7 @@
 
 		// 鎵╁睍淇℃伅锛屽惈BI娑堟伅缁熻锛岀壒瀹氬睍绀洪鏍硷紝娑堟伅鎶樺彔銆�
 		JSONObject ext = new JSONObject();
-		ext.put("biTag", "Trump");// 璁剧疆娑堟伅鏍囩锛屽鏋滃甫浜嗚繖涓爣绛撅紝浼氬湪鍥炴墽涓帹閫佺粰CP鐢ㄤ簬妫�娴嬫煇绉嶇被鍨嬫秷鎭殑鍒拌揪鐜囧拰鐘舵��
+
 		// ext.put("icon",
 		// "http://pic.qiantucdn.com/58pic/12/38/18/13758PIC4GV.jpg");//
 		// 鑷畾涔夋帹閫佹秷鎭湪閫氱煡鏍忕殑鍥炬爣,value涓轰竴涓叕缃戝彲浠ヨ闂殑URL
@@ -235,6 +298,8 @@
 		JSONObject payload = new JSONObject();
 		payload.put("hps", hps);
 
+		System.out.println(payload.toJSONString());
+
 		String postBody = MessageFormat.format(
 				"access_token={0}&nsp_svc={1}&nsp_ts={2}&device_token_list={3}&payload={4}",
 				URLEncoder.encode(accessToken, "UTF-8"), URLEncoder.encode("openpush.message.api.send", "UTF-8"),

--
Gitblit v1.8.0