记得上下班打卡 | git大法好,push需谨慎

Commit 8c5d749b authored by zhoujianping's avatar zhoujianping

1.增加华为离线推送

parent a5dde0a7
......@@ -72,6 +72,15 @@ public abstract class AndroidNotification extends UmengNotification {
rootJson.put("policy", policyJson);
}
policyJson.put(key, value);
} else if(CHANNEL_PROPERTIES.contains(key)){
JSONObject channelJson = null;
if (rootJson.has("channel_properties")) {
channelJson = rootJson.getJSONObject("channel_properties");
} else {
channelJson = new JSONObject();
rootJson.put("channel_properties", channelJson);
}
channelJson.put(key, value);
} else {
if (key == "payload" || key == "body" || key == "policy" || key == "extra") {
throw new Exception("You don't need to set value for " + key + " , just set values for the sub keys in it.");
......
......@@ -22,7 +22,11 @@ public abstract class UmengNotification {
protected static final HashSet<String> POLICY_KEYS = new HashSet<String>(Arrays.asList(new String[]{
"start_time", "expire_time", "max_send_num"
}));
protected static final HashSet<String> CHANNEL_PROPERTIES = new HashSet<String>(Arrays.asList(new String[]{
"channel_activity"
}));
// Set predefined keys in the rootJson, for extra keys(Android) or customized keys(IOS) please
// refer to corresponding methods in the subclass.
public abstract boolean setPredefinedKeyValue(String key, Object value) throws Exception;
......
......@@ -4,9 +4,9 @@ package com.liquidnet.commons.lang.util.upush.android;
import com.liquidnet.commons.lang.util.upush.AndroidNotification;
public class AndroidBroadcast extends AndroidNotification {
public AndroidBroadcast(String appkey,String appMasterSecret,String type) throws Exception {
public AndroidBroadcast(String appkey,String appMasterSecret) throws Exception {
setAppMasterSecret(appMasterSecret);
setPredefinedKeyValue("appkey", appkey);
this.setPredefinedKeyValue("type", type);
this.setPredefinedKeyValue("type", "broadcast");
}
}
......@@ -4,10 +4,10 @@ package com.liquidnet.commons.lang.util.upush.ios;
import com.liquidnet.commons.lang.util.upush.IOSNotification;
public class IOSBroadcast extends IOSNotification {
public IOSBroadcast(String appkey,String appMasterSecret,String type) throws Exception {
public IOSBroadcast(String appkey,String appMasterSecret) throws Exception {
setAppMasterSecret(appMasterSecret);
setPredefinedKeyValue("appkey", appkey);
this.setPredefinedKeyValue("type", type);
this.setPredefinedKeyValue("type", "broadcast");
}
}
......@@ -8,7 +8,9 @@ import com.liquidnet.commons.lang.util.*;
import com.liquidnet.commons.lang.util.upush.AndroidNotification;
import com.liquidnet.commons.lang.util.upush.PushClient;
import com.liquidnet.commons.lang.util.upush.android.AndroidBroadcast;
import com.liquidnet.commons.lang.util.upush.android.AndroidUnicast;
import com.liquidnet.commons.lang.util.upush.ios.IOSBroadcast;
import com.liquidnet.commons.lang.util.upush.ios.IOSUnicast;
import com.liquidnet.service.kylin.constant.KylinRedisConst;
import com.liquidnet.service.kylin.dao.KylinPerformancesSubscribeDao;
import com.liquidnet.service.kylin.dto.param.PerformancePartnerVo;
......@@ -523,7 +525,7 @@ public class PerformanceVoTask {
log.info("友盟Android开票提醒推送开始startTime===={}",startTime);
for (KylinPerformancesSubscribeDao kylinPerformancesSubscribeDao : kylinPerformancesSubscribeDaoAndroidList) {
//友盟推送
sendAndroidBroadcast(kylinPerformancesSubscribeDao.getDeviceTokens(),kylinPerformancesSubscribeDao.getPushTitle(),6,kylinPerformancesSubscribeDao.getJumpValue());
sendAndroidUnicast(kylinPerformancesSubscribeDao.getDeviceTokens(),kylinPerformancesSubscribeDao.getPushTitle(),6,kylinPerformancesSubscribeDao.getJumpValue());
}
long endTime = System.currentTimeMillis(); // 获取结束时间
log.info("友盟Android开票提醒推送结束方法执行时间秒===={}",(startTime-endTime)/1000);
......@@ -539,7 +541,7 @@ public class PerformanceVoTask {
log.info("友盟IOS开票提醒推送开始startTime===={}",startTime);
for (KylinPerformancesSubscribeDao kylinPerformancesSubscribeDao : kylinPerformancesSubscribeDaoIOSList) {
//友盟推送
sendIOSBroadcast(kylinPerformancesSubscribeDao.getDeviceTokens(),kylinPerformancesSubscribeDao.getPushTitle(),6,kylinPerformancesSubscribeDao.getJumpValue());
sendIOSUnicastt(kylinPerformancesSubscribeDao.getDeviceTokens(),kylinPerformancesSubscribeDao.getPushTitle(),6,kylinPerformancesSubscribeDao.getJumpValue());
}
long endTime = System.currentTimeMillis(); // 获取结束时间
log.info("友盟IOS开票提醒推送结束方法执行时间秒===={}",(startTime-endTime)/1000);
......@@ -548,57 +550,60 @@ public class PerformanceVoTask {
performancesMapper.updatePerformanceSubscribePushById(IOSIds);
}
}
public void sendAndroidBroadcast(String deviceTokens,String pushTitle,Integer jumpType,String jumpValue) {
public void sendAndroidUnicast(String deviceTokens,String pushTitle,Integer jumpType,String jumpValue) {
try {
AndroidBroadcast broadcast = new AndroidBroadcast(androidAppkey, androidAppMasterSecret,"unicast");
broadcast.setBadge(1);
broadcast.setTicker("【正在现场】开票提醒");
broadcast.setTitle("【正在现场】开票提醒");
broadcast.setText(pushTitle+",10分钟后即将开售,请点击进入详情页购买。");
AndroidUnicast unicast = new AndroidUnicast(androidAppkey, androidAppMasterSecret);
unicast.setBadge(1);
unicast.setTicker("【正在现场】开票提醒");
unicast.setTitle("【正在现场】开票提醒");
unicast.setText(pushTitle+",10分钟后即将开售,请点击进入详情页购买。");
String custom = UpushTargetType.getTypeAction(jumpType);
broadcast.goCustomAfterOpen(custom);
broadcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
unicast.goCustomAfterOpen(custom);
unicast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
if (!LnsEnum.ENV.prod.name().equals(environment.getProperty(CurrentUtil.CK_ENV_ACTIVE))) {
broadcast.setTestMode();
unicast.setTestMode();
} else {
broadcast.setProductionMode();
unicast.setProductionMode();
}
// Set customized fields
broadcast.setExtraField("type", jumpType.toString());
broadcast.setExtraField("id", jumpValue);
broadcast.setExtraField("url", jumpValue);
unicast.setExtraField("type", jumpType.toString());
unicast.setExtraField("id", jumpValue);
unicast.setExtraField("url", jumpValue);
//表示指定的单个设备
broadcast.setPredefinedKeyValue("device_tokens",deviceTokens);
unicast.setDeviceToken(deviceTokens);
//配置华为离线通知
unicast.setPredefinedKeyValue("channel_activity","com.modernsky.istv.ui.activity.MfrMessageActivity");
log.info("友盟消息推送开始Android============deviceTokens========={},pushTitle========={}",deviceTokens,pushTitle);
String sendRes = client.send(broadcast);
String sendRes = client.send(unicast);
log.info("友盟消息推送成功AndroidReturn============sendRes===={}",sendRes);
} catch (Exception e) {
log.info("友盟消息推送失败Android============deviceTokens={},pushTitle={},e={}",deviceTokens,pushTitle,e);
}
}
public void sendIOSBroadcast(String deviceTokens,String pushTitle,Integer jumpType,String jumpValue) {
public void sendIOSUnicastt(String deviceTokens,String pushTitle,Integer jumpType,String jumpValue) {
AdminUpush updatePush = new AdminUpush();
try {
IOSBroadcast broadcast = new IOSBroadcast(iosAppkey, iosAppMasterSecret,"unicast");
IOSUnicast unicast = new IOSUnicast(iosAppkey, iosAppMasterSecret);
//alert的值设置为字典
broadcast.setAlert("【正在现场】开票提醒", "", pushTitle+",10分钟后即将开售,请点击进入详情页购买。");
broadcast.setBadge(1);
broadcast.setSound("default");
unicast.setAlert("【正在现场】开票提醒", "", pushTitle+",10分钟后即将开售,请点击进入详情页购买。");
unicast.setBadge(1);
unicast.setSound("default");
if (!LnsEnum.ENV.prod.name().equals(environment.getProperty(CurrentUtil.CK_ENV_ACTIVE))) {
broadcast.setTestMode();
unicast.setTestMode();
} else {
broadcast.setProductionMode();
unicast.setProductionMode();
}
// Set customized fields
broadcast.setCustomizedField("type", jumpType.toString());
broadcast.setCustomizedField("id", jumpValue);
broadcast.setCustomizedField("url", jumpValue);
unicast.setCustomizedField("type", jumpType.toString());
unicast.setCustomizedField("id", jumpValue);
unicast.setCustomizedField("url", jumpValue);
//表示指定的单个设备
broadcast.setPredefinedKeyValue("device_tokens",deviceTokens);
unicast.setDeviceToken(deviceTokens);
log.info("友盟消息推送开始IOS============deviceTokens========={},pushTitle========={}",deviceTokens,pushTitle);
String sendRes = client.send(broadcast);
String sendRes = client.send(unicast);
log.info("友盟消息推送成功IOS============sendRes===={}",sendRes);
} catch (Exception e) {
log.info("友盟消息推送失败IOS============deviceTokens={},pushTitle={},e={}",deviceTokens,pushTitle,e);;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment