wrep/notificato

此包已被废弃且不再维护。未建议替代包。

处理PHP项目中的推送通知。

1.2.1 2019-05-27 08:43 UTC

This package is auto-updated.

Last update: 2024-07-17 23:14:46 UTC


README

Notificato负责处理PHP项目中的推送通知。

意大利语: notificato 是:过去分词 英语: notified

为什么使用Notificato而不是X?

Notificato拥有其他PHP推送库没有的一些优势

  1. 支持多个APNS证书,因此您可以推送多个应用程序/Passbook通行证
  2. 精心处理PHP的buggy SSL套接字,正确处理怪异和错误响应
  3. 经过单元测试和良好的面向对象结构进行良好测试

安装

建议使用Composer进行安装。运行require命令将Notificato添加到项目中

composer require wrep/notificato

建议:还有Notificato for Symfony bundle可用,强烈推荐给Symfony2 & Symfony3用户。

入门

  1. 查看以下代码片段,了解Notificato的工作方式
  2. 阅读文档,它将帮助您了解常见用例
  3. 查看API文档以深入了解Notificato的功能
<?php
// This imports the Composer autoloader
require_once('vendor/autoload.php');

use Wrep\Notificato\Notificato;

class GettingStarted
{
	/**
	 * This example sends one pushnotification with an alert to Apples production push servers
	 */
	public function sendOnePushNotification()
	{
		// First we get a Notificato instance and tell it what certificate to use as default certificate
		$notificato = new Notificato('./certificate.pem', 'passphrase-to-use');

		// Now we get a fresh messagebuilder from Notificato
		//  This message will be send to device with pushtoken 'fffff...'
		//  it will automaticly be associated with the default certificate
		//  and we will set the red badge on the App icon to 1
		$message = $notificato->messageBuilder()
								->setDeviceToken('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')
								->setBadge(1)
								->build();

		// The message is ready, let's send it!
		//  Be aware that this method is blocking and on failure Notificato will retry if necessary
		$messageEnvelope = $notificato->send($message);

		// The returned envelope contains usefull information about how many retries where needed and if sending succeeded
		echo $messageEnvelope->getFinalStatusDescription();
	}

	/**
	 * This example reads all unregistered devices from Apples feedback service
	 */
	public function readFeedbackService()
	{
		// First we get the a Notificato instance and tell it what certificate to use as default certificate
		$notificato = new Notificato('./certificate.pem', 'passphrase-to-use');

		// Now read all "tuples" from the feedback service, be aware that this method is blocking
		$tuples = $notificato->receiveFeedback();

		// The tuples contain information about what device unregistered and when it did unregister.
		//  Don't forget to check if the device reregistered after the "invaidated at" date!
		foreach ($tuples as $tuple)
		{
			echo 'Device ' . $tuple->getDeviceToken() . ' invalidated at ' . $tuple->getInvalidatedAt()->format(\DateTime::ISO8601) . PHP_EOL;
		}
	}
}

$gettingStarted = new GettingStarted();
$gettingStarted->sendOnePushNotification();
$gettingStarted->readFeedbackService();

贡献

我们非常欢迎贡献,请阅读Contribute.md以获取有关您可以做什么以及如果您想帮助应该了解的内容的更多信息!

许可 & 信用

Notificato由MIT License发布,由Mathijs Kadijk,因此您可以自由地在商业和非商业项目中使用它。