Exemple #1
0
 /**
  * Get configured service message.
  *
  * @param array                   $tokens
  * @param \Jgut\Tify\Notification $notification
  *
  * @throws \ZendService\Google\Exception\InvalidArgumentException
  * @throws \ZendService\Google\Exception\RuntimeException
  *
  * @return \Jgut\Tify\Adapter\Gcm\GcmMessage
  */
 public function buildPushMessage(array $tokens, Notification $notification)
 {
     $message = $notification->getMessage();
     $pushMessage = new GcmMessage();
     $pushMessage->setRegistrationIds($tokens)->setCollapseKey($notification->getParameter('collapse_key'))->setDelayWhileIdle($notification->getParameter('delay_while_idle'))->setTimeToLive($notification->getParameter('time_to_live'))->setRestrictedPackageName($notification->getParameter('restricted_package_name'))->setDryRun($notification->getParameter('dry_run'))->setData($message->getPayloadData());
     if ($this->shouldHaveNotification($message)) {
         $pushMessage->setNotificationPayload($message->getParameters());
     }
     return $pushMessage;
 }
Exemple #2
0
 public function testMessage()
 {
     $message = $this->getMockBuilder(Message::class)->disableOriginalConstructor()->getMock();
     $this->notification->setMessage($message);
     self::assertEquals($message, $this->notification->getMessage());
 }
Exemple #3
0
 /**
  * Get service message from origin.
  *
  * @param \Jgut\Tify\Receiver\ApnsReceiver $receiver
  * @param \Jgut\Tify\Notification          $notification
  *
  * @throws \ZendService\Apple\Exception\RuntimeException
  *
  * @return \ZendService\Apple\Apns\Message
  */
 public function buildPushMessage(ApnsReceiver $receiver, Notification $notification)
 {
     $message = $notification->getMessage();
     $messageId = sha1(sprintf('%s%s%s%s', $receiver->getToken(), $message->getParameter('title'), $message->getParameter('body'), time()));
     $badge = $notification->getParameter('badge') === null ? null : (int) $notification->getParameter('badge');
     $pushMessage = (new ServiceMessage())->setId($messageId)->setToken($receiver->getToken())->setBadge($badge)->setSound($notification->getParameter('sound'))->setCategory($notification->getParameter('category'))->setCustom($message->getPayloadData());
     if ($notification->getParameter('content-available') !== null) {
         $pushMessage->setContentAvailable((int) $notification->getParameter('content-available'));
     }
     if (is_array($notification->getParameter('url-args'))) {
         $pushMessage->setUrlArgs($notification->getParameter('url-args'));
     }
     if ($notification->getParameter('expire') !== null) {
         $pushMessage->setExpire($notification->getParameter('expire'));
     }
     if ($this->shouldHaveAlert($message)) {
         $pushMessage->setAlert(new ServiceMessageAlert($message->getParameter('body'), $message->getParameter('action-loc-key'), $message->getParameter('loc-key'), $message->getParameter('loc-args'), $message->getParameter('launch-image'), $message->getParameter('title'), $message->getParameter('title-loc-key'), $message->getParameter('title-loc-args')));
     }
     return $pushMessage;
 }