コード例 #1
0
ファイル: PushCommand.php プロジェクト: integer/AppleApnPush
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Create connection
     $certificate = new Certificate($input->getArgument('certificate-file'), $input->getArgument('pass-phrase'));
     $connection = new Connection($certificate, (bool) $input->getOption('sandbox'));
     // Create payload factory
     $payloadFactory = new PayloadFactory();
     // Create notification system
     $notification = new Notification();
     $notification->setPayloadFactory($payloadFactory);
     $notification->setConnection($connection);
     // Create message
     $message = new Message();
     $message->setDeviceToken($input->getArgument('device-token'));
     $apsData = $message->getApsData();
     $apsData->setBody($input->getArgument('message'));
     $apsData->setSound($input->getOption('sound'));
     $apsData->setBadge($input->getOption('badge'));
     // Send message
     try {
         $notification->send($message);
         $output->writeln('<info>Success send push.</info>');
     } catch (\Exception $e) {
         $output->writeln('<error>Error send push notification with message: ' . $e->getMessage() . '.</error>');
     }
 }
コード例 #2
0
ファイル: AppleApnSender.php プロジェクト: genkgo/push
 /**
  * @param Message $message
  * @param RecipientInterface|AppleDeviceRecipient $recipient
  * @codeCoverageIgnore
  */
 public function send(Message $message, RecipientInterface $recipient)
 {
     $appleMessage = new AppleMessage();
     $appleMessage->setBody((string) $message->getBody());
     $appleMessage->setDeviceToken($recipient->getToken());
     $appleMessage->setCustomData($message->getExtra());
     $notification = new Notification($this->connection);
     $notification->send($appleMessage);
 }
コード例 #3
0
ファイル: AmqpTest.php プロジェクト: integer/AppleApnPush
 /**
  * Testing send message without errors
  *
  * @dataProvider providerAddMessageParameters
  */
 public function testAddMessage($routingKey, $publishFlag, $publishParameters)
 {
     $message = new Message();
     $message->setDeviceToken(str_repeat('af', 32))->setBody('Foo bar');
     $messageSerialized = serialize($message);
     $this->exchange->expects($this->once())->method('publish')->with($messageSerialized, $routingKey, $publishFlag, $publishParameters)->will($this->returnValue(true));
     $adapter = new AmqpAdapter();
     $adapter->setExchange($this->exchange)->setRoutingKey($routingKey)->setPublishOptions($publishParameters)->setPublishFlag($publishFlag);
     $adapter->addMessage($message);
 }
コード例 #4
0
 /**
  * Create message
  */
 public static function createMessage($body, $identifier = null, $deviceToken = null)
 {
     $message = new Message();
     $message->setBody($body);
     if ($identifier !== null) {
         $message->setIdentifier($identifier);
     }
     if ($deviceToken !== null) {
         $message->setDeviceToken($deviceToken);
     } else {
         $message->setDeviceToken(str_repeat('af', 32));
     }
     return $message;
 }