From 4a7367a869ef12375ea6678ca44e102b8919c624 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 12 一月 2022 16:53:42 +0800 Subject: [PATCH] 极光推送完善(推送通知与透传消息) --- service-push/src/main/java/com/ks/push/utils/PushUtil.java | 67 ++++++++++++++++++++++++++++++--- 1 files changed, 61 insertions(+), 6 deletions(-) diff --git a/service-push/src/main/java/com/ks/push/utils/PushUtil.java b/service-push/src/main/java/com/ks/push/utils/PushUtil.java index a29c893..be20cac 100644 --- a/service-push/src/main/java/com/ks/push/utils/PushUtil.java +++ b/service-push/src/main/java/com/ks/push/utils/PushUtil.java @@ -1,14 +1,24 @@ package com.ks.push.utils; +import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; import com.ks.push.pojo.DO.BPushMessage; import com.ks.push.pojo.DO.PushPlatform; -import org.yeshi.utils.push.*; +import com.ks.push.utils.push.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yeshi.utils.StringUtil; import org.yeshi.utils.push.entity.PushAppInfo; import org.yeshi.utils.push.entity.PushMessage; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; public class PushUtil { + + static Logger logger = LoggerFactory.getLogger(PushUtil.class); /** * 鎺ㄩ�侀�氱煡 @@ -19,7 +29,7 @@ * @param tokenList * @throws Exception */ - public static void pushNotifyCation(PushPlatform platform, PushAppInfo appInfo, BPushMessage pushMessage, List<String> tokenList) throws Exception { + public static void pushNotifyCation(PushPlatform platform, PushAppInfo appInfo, BPushMessage pushMessage, String identifyCode, List<String> tokenList) throws Exception { if (appInfo == null) { throw new Exception("搴旂敤鍙傛暟涓虹┖"); } @@ -31,18 +41,38 @@ if (tokenList == null || tokenList.size() == 0) { throw new Exception("token涓虹┖"); } - PushMessage message = new PushMessage(pushMessage.getTitle(), pushMessage.getContent(), pushMessage.getAndroidActivity(), pushMessage.getAndroidActivityScheme(), pushMessage.getAndroidHostPath(), pushMessage.getExtras()); + + logger.info("{}鎺ㄩ�佸簲鐢ㄤ俊鎭細{}", platform.name(), new Gson().toJson(appInfo)); + logger.info("{}鎺ㄩ�佸唴瀹逛俊鎭細{}", platform.name(), new Gson().toJson(pushMessage)); + logger.info("{}鎺ㄩ�乼oken淇℃伅锛歿}", platform.name(), new Gson().toJson(tokenList)); + + + Map<String, String> extras = null; + if (pushMessage.getExtras() != null) { + extras = new HashMap<>(); + for (Iterator<String> its = pushMessage.getExtras().keySet().iterator(); its.hasNext(); ) { + String key = its.next(); + String value = pushMessage.getExtras().get(key); + if (!StringUtil.isNullOrEmpty(key) && !StringUtil.isNullOrEmpty(value)) { + extras.put(key, value); + } + } + } + + PushMessage message = new PushMessage(pushMessage.getTitle(), pushMessage.getContent(), pushMessage.getAndroidActivity(), pushMessage.getAndroidActivityScheme(), pushMessage.getAndroidHostPath(), extras); if (platform == PushPlatform.xm) { pushXM(appInfo, message, tokenList); } else if (platform == PushPlatform.hw) { - pushHW(appInfo, message, tokenList); + pushHW(appInfo, message, identifyCode, tokenList); } else if (platform == PushPlatform.oppo) { pushOPPO(appInfo, message, tokenList); } else if (platform == PushPlatform.vivo) { pushVIVO(appInfo, message, tokenList); } else if (platform == PushPlatform.mz) { pushMZ(appInfo, message, tokenList); + } else if (platform == PushPlatform.jpush) { + pushJPush(appInfo, message, tokenList,!pushMessage.isMessage()); } } @@ -63,11 +93,12 @@ * * @param appInfo * @param message + * @param bigTag * @param tokenList * @throws Exception */ - private static void pushHW(PushAppInfo appInfo, PushMessage message, List<String> tokenList) throws Exception { - HuaWeiPushUtil.pushNotificationByTokens(appInfo, message, tokenList); + private static void pushHW(PushAppInfo appInfo, PushMessage message, String bigTag, List<String> tokenList) throws Exception { + HuaWeiPushUtil.pushNotificationByTokens(appInfo, message, bigTag, tokenList); } /** @@ -107,4 +138,28 @@ } + /** + * 鏋佸厜鎺ㄩ�� + * + * @param appInfo + * @param message + * @param tokenList + * @throws Exception + */ + private static void pushJPush(PushAppInfo appInfo, PushMessage message, List<String> tokenList, boolean alert) throws Exception { + if (alert) { + JpushUtil.pushNotification(appInfo, message, tokenList, null); + } else { + JSONObject data = new JSONObject(); + if (message.getActivityParams() != null) { + for (Iterator<String> its = message.getActivityParams().keySet().iterator(); its.hasNext(); ) { + String key = its.next(); + data.put(key, message.getActivityParams().get(key)); + } + } + JpushUtil.pushMessage(appInfo, data, tokenList, null); + } + } + + } -- Gitblit v1.8.0