• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PushNotificationPayload类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javapns.notification.PushNotificationPayload的典型用法代码示例。如果您正苦于以下问题:Java PushNotificationPayload类的具体用法?Java PushNotificationPayload怎么用?Java PushNotificationPayload使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PushNotificationPayload类属于javapns.notification包,在下文中一共展示了PushNotificationPayload类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createPayload

import javapns.notification.PushNotificationPayload; //导入依赖的package包/类
/**
 * Create a payload to be sent to client device.
 *
 * @param alertMessage Message that is visible to end user
 * @param hiddenMessage Message that is invisible to end user
 * @return a push notification payload to send to client device
 */
public PushNotificationPayload createPayload(String alertMessage,
    String hiddenMessage) {
  if (StringUtility.isNullOrEmpty(alertMessage) || StringUtility.isNullOrEmpty(hiddenMessage)) {
    throw new IllegalArgumentException("Input arguments cannot be a null or an empty String");
  }

  PushNotificationPayload payload = new PushNotificationPayload();

  try {
    payload.addAlert(alertMessage);
    payload.addCustomDictionary("hiddenMessage", hiddenMessage);
  } catch (JSONException e) {
    log.warning(e.getClass().toString() + " " + e.getMessage());
  }

  return payload;
}
 
开发者ID:googlesamples,项目名称:io2014-codelabs,代码行数:25,代码来源:Sender.java


示例2: sendIosInvitationNotification

import javapns.notification.PushNotificationPayload; //导入依赖的package包/类
/**
 * Sends an invitation notification to iOS devices.
 *
 * @param iOsDevices the list of Android devices to send the notification to.
 * @param invitee the Player who has been invited.
 * @param invitationId the invitation id.
 * @param gameId the game id.
 * @param messageText invitationText to be sent.
 * @throws CommunicationException if an error occurred while sending iOS push notifications.
 */
private void sendIosInvitationNotification(List<DeviceEntity> iOsDevices, PlayerEntity invitee,
    long invitationId, long gameId, String messageText) throws CommunicationException {
  PushNotificationPayload payload = PushNotificationPayload.complex();

  try {
    payload.addAlert(messageText);
    payload.addCustomDictionary("invitationId", String.valueOf(invitationId));
    payload.addCustomDictionary("gameId", String.valueOf(gameId));
    payload.addCustomDictionary("playerId", String.valueOf(invitee.getId()));
    payload.addCustomDictionary("nickName", invitee.getNickname());

    IosNotificationService notificationService = new IosNotificationService();
    notificationService.sendPushNotification(iOsDevices, payload, invitee.getKey());
  } catch (JSONException e) {
    logger.log(Level.WARNING, "Invalid format of a push notification payload", e);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:solutions-griddler-sample-backend-java,代码行数:28,代码来源:InvitationService.java


示例3: notificarIos

import javapns.notification.PushNotificationPayload; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public IosResponse notificarIos(String certifadoPath, String keyFile,
        Evento evento, Boolean productionMode) throws BusinessException {
    LOGGER.info("[Evento: " + evento + "]: Notificando iOs");
    File certificado = new File(certifadoPath);
    Payload payload = PushNotificationPayload.complex();
    ObjectNode pay = evento.getObjectNodePayLoad();
    try {
        if (evento.isSendToSync()) {
            ((PushNotificationPayload) payload).addCustomDictionary("content-available", "1");
        } else {
            ((PushNotificationPayload) payload).addAlert(evento
                    .getAlert());

            ((PushNotificationPayload) payload).addSound("default");
            if (evento.isSendToSync()) {
                ((PushNotificationPayload) payload).addSound("default");
            }
            Iterator it = pay.fieldNames();
            while (it.hasNext()) {
                String pair = (String) it.next();
                LOGGER.info(pair + " = " + pay.get(pair));
                payload.addCustomDictionary((String) pair,
                        pay.get(pair).asText());
            }
        }
    } catch (JSONException e) {
        LOGGER.error(e);
        throw new BusinessException(GlobalCodes.errors.BAD_REQUEST, "Error al parsear payload en notificacion iOs.");
    }
    IosResponse response = facade.send(payload, certificado, keyFile, productionMode, evento.getIosDevicesList());
    LOGGER.info("[IOS] Response: " + response);
    procesarErroresIos(evento, response);

    return response;

}
 
开发者ID:jokoframework,项目名称:notification-server,代码行数:38,代码来源:NotificationBusiness.java


示例4: sendAlert

import javapns.notification.PushNotificationPayload; //导入依赖的package包/类
/**
 * Sends an alert notification to a list of devices.
 *
 * @param alertMessage alert to be sent as a push notification
 * @param deviceTokens the list of tokens for devices to which the notifications should be sent 
 * @return a list of pushed notifications that contain details on transmission results.
 * @throws javapns.communication.exceptions.CommunicationException thrown if an error occurred while communicating with the target
 *         server even after a few retries.
 * @throws javapns.communication.exceptions.KeystoreException thrown if an error occurs with using the certificate.
 */
public PushedNotifications sendAlert(String alertMessage, String[] deviceTokens)
    throws CommunicationException, KeystoreException {

  log.info("Sending alert='" + alertMessage + "' to " + deviceTokens.length
      + " devices started at " + dateFormat.format(new Date()) + ".");
  PushedNotifications notifications =
      sendPayload(PushNotificationPayload.alert(alertMessage), deviceTokens);

  log.info("Sending alert='" + alertMessage + "' to " + deviceTokens.length
      + " devices completed at " + dateFormat.format(new Date()) + ".");

  return notifications;
}
 
开发者ID:googlesamples,项目名称:io2014-codelabs,代码行数:24,代码来源:Sender.java


示例5: sendAlert

import javapns.notification.PushNotificationPayload; //导入依赖的package包/类
/**
 * Sends an alert notification to a list of devices.
 *
 * @param alertMessage alert to be sent as a push notification
 * @param deviceTokens the list of tokens for devices to which the notifications should be sent 
 * @return a list of pushed notifications that contain details on transmission results.
 * @throws CommunicationException thrown if an error occurred while communicating with the target
 *         server even after a few retries.
 * @throws KeystoreException thrown if an error occurs with using the certificate.
 */
public PushedNotifications sendAlert(String alertMessage, String[] deviceTokens)
    throws CommunicationException, KeystoreException {

  log.info("Sending alert='" + alertMessage + "' to " + deviceTokens.length
      + " devices started at " + dateFormat.format(new Date()) + ".");
  PushedNotifications notifications =
      sendPayload(PushNotificationPayload.alert(alertMessage), deviceTokens);

  log.info("Sending alert='" + alertMessage + "' to " + deviceTokens.length
      + " devices completed at " + dateFormat.format(new Date()) + ".");

  return notifications;
}
 
开发者ID:googlearchive,项目名称:solutions-mobile-backend-starter-java,代码行数:24,代码来源:Sender.java


示例6: validateObject

import javapns.notification.PushNotificationPayload; //导入依赖的package包/类
@Override
public boolean validateObject(PushNotificationManager manager) {
    PushedNotification notification = null;
    try {
        notification = manager.sendNotification(new BasicDevice(RandomStringUtils.randomNumeric(64)),
                PushNotificationPayload.test());
    } catch (Exception e) {
        logger.error("validate manager:[{}] due to error:[{}]", manager, ExceptionUtils.getStackTrace(e));
    }
    return notification != null && notification.isSuccessful();
}
 
开发者ID:pippo1980,项目名称:upns,代码行数:12,代码来源:PushNotificationManagerPool.java


示例7: push

import javapns.notification.PushNotificationPayload; //导入依赖的package包/类
private void push(final APNSPushTask event, final List<Device> devices) {
	int appId = event.getMessage().getAppId();
	final PushNotificationTemplate pushNotificationTemplate = templates.payloads.get(appId);
	if (pushNotificationTemplate == null) {
		logger.warn("can not find pushNotificationTemplate with appId:[{}], ignore event:[{}]", appId, event);
		return;
	}

	pushNotificationTemplate.push(new PushNotificationProcessor() {

		@Override
		public void process(PushNotificationManager manager) throws Exception {
			//int unread = timelineRepository.unread(event.userId, event.message.appId) + 1;
			PushNotificationPayload payload = PushNotificationPayload.combined(event.message.title, 1, "default");

			for (Device device : devices) {
				if (device.token == null || device.token.length() != 64) {
					continue;
				}

				PushedNotification notification = manager.sendNotification(new BasicDevice(device.token), payload,
						false);

				if (notification != null) {
					logger.debug(
							"push message:[{}] to apns[user/device]:[{}/{}], the acknowledge is:[{}], the push result is:{}",
							event.message.title,
							device.userId,
							device.token,
							notification,
							notification.isSuccessful());
				}
			}

		}
	});
}
 
开发者ID:pippo1980,项目名称:upns,代码行数:38,代码来源:APNSPushTaskConsumer.java


示例8: sendAlert

import javapns.notification.PushNotificationPayload; //导入依赖的package包/类
/**
 * Sends an alert notification to a list of devices.
 *
 * @param alertMessage alert to be sent as a push notification
 * @param deviceTokens the list of tokens for devices to which the notifications should be sent
 * @return a list of pushed notifications that contain details on transmission results.
 * @throws CommunicationException thrown if an error occurred while communicating with the target
 *         server even after a few retries.
 * @throws KeystoreException thrown if an error occurs with using the certificate.
 */
public PushedNotifications sendAlert(String alertMessage, String[] deviceTokens)
    throws CommunicationException, KeystoreException {

  log.info("Sending alert='" + alertMessage + "' to " + deviceTokens.length
      + " devices started at " + dateFormat.format(new Date()) + ".");
  PushedNotifications notifications =
      sendPayload(PushNotificationPayload.alert(alertMessage), deviceTokens);

  log.info("Sending alert='" + alertMessage + "' to " + deviceTokens.length
      + " devices completed at " + dateFormat.format(new Date()) + ".");

  return notifications;
}
 
开发者ID:GoogleCloudPlatform,项目名称:solutions-ios-push-notification-sample-backend-java,代码行数:24,代码来源:PushNotificationSender.java


示例9: sendToUsers

import javapns.notification.PushNotificationPayload; //导入依赖的package包/类
@PostMapping(value = "/toUsers")
public Callable<BaseModel<?>> sendToUsers(@RequestBody IosPushReq message) {

    return new Callable<BaseModel<?>>() {
        @Override
        public BaseModel<?> call() throws Exception {

            String certKeyPath = pushServerInfo.getIos().getCertKeyPath();
            String keyPassword = pushServerInfo.getIos().getCertPassword();
            
            try {
                
                List<String> tokens = new ArrayList<String>();
                
                for (UserToken user: message.getUserTokenList()) {
                    String token;
                    if (user.getUserToken() != null) {
                        token = user.getUserToken();
                    } else {
                        token = userTokenService.getToken(user.getUserId());
                    }
                    if (token != null && token.startsWith("ios:")) {
                        tokens.add(token.substring(4));
                    }
                }
                
                if (!tokens.isEmpty()) {

                    PushNotificationPayload payload =
                            PushNotificationPayload.alert(message.getContent());
                    payload.addSound("default");
                    payload.addCustomDictionary("time", CommonUtils.currentTimeSeconds());
                    payload.addCustomDictionary("msg_type", message.getMsgType());
                    payload.addCustomDictionary("from_id", message.getFromId());
                    
                    // 群组时
                    if (CommonUtils.isGroup(message.getMsgType())) {
                        payload.addCustomDictionary("group_id", message.getGroupId());
                    }

                    PushedNotifications apnResults;
                    if (pushServerInfo.isTestMode()) {
                        apnResults =
                                Push.payload(payload, certKeyPath, keyPassword, false, 30, tokens);
                    } else {
                        apnResults =
                                Push.payload(payload, certKeyPath, keyPassword, true, 30, tokens);
                    }
                    if (apnResults != null) {
                        for (PushedNotification apnResult : apnResults) {
                            // ResponsePacket responsePacket = apnResult.getResponse();
                            if (apnResult.isSuccessful()) {
                                logger.debug("推送结果:成功");
                                // logger.debug("推送结果:",
                                // responsePacket.getStatus(),responsePacket.getMessage());
                            } else {
                                logger.debug("推送结果:失败");
                            }
                        }
                    }
                }

                return new BaseModel<Integer>();
            } catch (Exception e) {

                logger.error("Iphone 推送失败!", e);
                throw new Exception("推送失败!");
            }
        }
    };
}
 
开发者ID:ccfish86,项目名称:sctalk,代码行数:72,代码来源:IphonePushServiceController.java


示例10: pushAll4Apple

import javapns.notification.PushNotificationPayload; //导入依赖的package包/类
@Override
	public void pushAll4Apple(MsgEntity msgEntity) {
		//群推线程数
		String	pushThreads = ResourceUtil.getConfigByName("applePushAllThread");
		//p12文件地址
		String	appleP12Path = ResourceUtil.getConfigByName("appleP12Path");
		//p12文件密码
		String	appleP12Pwd = ResourceUtil.getConfigByName("appleP12Pwd");
		//苹果推送服务器选择,true为正式服务器,false为开发者服务器
		String	applePushServer = ResourceUtil.getConfigByName("applePushServer");
		try {
			// 建立与Apple服务器连接
			AppleNotificationServer server = new AppleNotificationServerBasicImpl(
					appleP12Path, appleP12Pwd, Boolean.parseBoolean(applePushServer));
			List<PayloadPerDevice> list = new ArrayList<PayloadPerDevice>();
			// 获取要推送的tokenlist
			List<AppleTokenEntity> tokenList = commonDao.loadAll(AppleTokenEntity.class);
			for (AppleTokenEntity tokenEntity : tokenList) {
				Gson gson = new Gson();
				String msg = gson.toJson(msgEntity);
				StringBuilder sb=new StringBuilder();
				PushNotificationPayload payload = new PushNotificationPayload();
				sb.append("{'title':").append(msgEntity.getTitle()).append(",'body':").append(msgEntity.getContent()).append("}");
				payload.addBadge(0);// 图标小红圈的数值
				payload.addCustomAlertBody(msgEntity.getContent());
				payload.addCustomDictionary("data", msg);
//				payload.addCustomDictionary("content-available", 1);
				PayloadPerDevice pay = new PayloadPerDevice(payload,
						tokenEntity.getToken());// 将要推送的消息和手机唯一标识绑定
				list.add(pay);
			}
			NotificationThreads work = new NotificationThreads(server, list,
					Integer.parseInt(pushThreads));//
			work.setListener(DEBUGGING_PROGRESS_LISTENER);// 对线程的监听,一定要加上这个监听
			work.start(); // 启动线程
			work.waitForAllThreads();// 等待所有线程启动完成

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
 
开发者ID:Martin404,项目名称:jmsRestful,代码行数:43,代码来源:ActiveMQProducerServiceImpl.java



注:本文中的javapns.notification.PushNotificationPayload类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DataTableRow类代码示例发布时间:2022-05-22
下一篇:
Java Status类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap