コード例 #1
0
ファイル: ApnsReceiverTest.php プロジェクト: juliangut/tify
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testBadToken()
 {
     $this->receiver->setToken('non_hex_short_token');
 }
コード例 #2
0
ファイル: ApnsBuilder.php プロジェクト: juliangut/tify
 /**
  * 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;
 }