pharmit / push
适用于Laravel的Google和Apple推送库
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ~6.1
- illuminate/support: >=5.2.0
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: 4.7.*
This package is not auto-updated.
Last update: 2024-09-14 19:31:04 UTC
README
此包为iOS和Android提供推送服务。它实现了iOS APS 2.0(HTTP2)API,这需要启用HTTP2的cURL版本。与其他包不同,此包可以在推送令牌失败时提供反馈。
安装
要安装此包,请运行composer命令
composer require pharmit/push
从您的配置目录打开 app.php
并将以下内容添加到提供者数组中:'PharmIT\Push\PushServiceProvider',
并将以下内容添加到别名数组中:'Push' => 'PharmIT\Push\PushServiceFacade',
然后通过执行以下命令发布配置:php artisan vendor:publish
服务器设置
由于新的Apple APS API使用HTTP2,并且HTTP2的支持并不好,请确保您有支持HTTP2的cURL编译版本。这已经在cURL版本7.43.0及以后的版本中得到全面实现。然而,cURL需要特别编译以启用此功能。当使用的cURL不支持HTTP2时,在尝试发送推送消息时将抛出(奇怪)SSL错误。
配置
该包包含一个名为"push.php"的配置文件。以下列出了配置设置。
throwExceptionOnError
当此变量设置为true时,所有错误都将抛出异常。否则,它将返回变量false。默认为true。
defaultEnvironment
此选项控制默认选择哪个环境,请注意,当所选选项找不到或不存在时,将回退到此选项。如果甚至找不到默认环境,除非将 throwExceptionOnError
设置为false,否则将抛出异常。
apple
此数组包含所有APS的配置选项。
certificate
证书相对于项目根路径的路径
environment
可以是"production"或"development",用于确定联系Apple时将使用哪个环境
passphrase
证书的密码(可选)
topic
应用程序标识符,例如"nl.PharmIT.MedApp"
此数组包含所有Google GCM的配置选项,目前只是一个选项。
apikey
GCM API密钥
用法
以下是一个Google API的代码示例。
// Get an instance
$google = Push::getPushService('google')
->setMessageText('Hi, how are you?')
->addRecipient('<PUSH_ID>')
->addRecipients(['<PUSH_ID>','<PUSH_ID>']);
// Get all push ID's to which the push message has been sent
$success = $google->send();
// Get all push ID's to which the push message could <u>not</u> be sent.
$failed = $google->getFailedRecipients();
对于APS,可以使用完全相同的模式,但传递给 getPushService
调用的参数必须是'apple'而不是'google'。