fei / notification-common
闪存通知 - 通用组件
v1.3.0
2019-01-31 14:48 UTC
Requires
- php: >=7.0
- doctrine/common: ~2.7.0
- fei/entities: ~1.1.0
- league/fractal: ^0.14.0
- objective-php/gateway: ^1.0.0
- zendframework/zend-validator: ^2.10
Requires (Dev)
- codeception/codeception: ^2.2
- jakub-onderka/php-parallel-lint: ^0.9.2
- phpmd/phpmd: ^2.6
- phpro/grumphp: ^0.11.1
- sebastian/phpcpd: ^3.0
- squizlabs/php_codesniffer: ^2.7
README
目录
实体
通知
origin
是表示通知来源的字符串recipient
是表示通知接收者的字符串event
是表示与通知相关的事件的字符串message
是表示消息的字符串type
是表示通知类型的整数。1 : 信息,2 : 警告status
是表示通知状态的整数。0 : 未读,1 : 已读,2 : 已确认parentNotificationId
是表示父通知的整数context
是 JSONaction
是 JSON
Android 提醒实体
message
是表示消息的 Message(如下所述)
消息(Android 提醒)
Android\Notification(Android 提醒)
电子邮件提醒实体
email
是表示电子邮件接收者的字符串subject
是表示电子邮件主题的字符串content
是表示电子邮件内容的字符串
SMS 提醒实体
message
是表示消息的 Message(如下所述)
消息(SMS 提醒)
贡献
作为 OpCoding 设计和制作的 FEI 服务,贡献工作流程将涉及两个技术团队。欢迎贡献力量,改进功能和应用补丁,但请注意仔细处理拉取请求。合并必须是 Flash 和 OpCoding 团队之间完整讨论的结果 :)
示例
您可以使用 NotificationValidator 类验证 Notification
实体
<?php use Fei\Service\Notification\Validator; use Fei\Service\Notification\Entity; $notificationData = [ 'origin' => 'origin', 'recipient' => 'thomas', 'event' => 'chat.message.new', 'message' => 'Example message', 'type' => 1, ]; $notification = new Notification(); $notificationValidator = new NotificationValidator(); $notificationHydrator = new NotificationHydrator(); $notification = $notificationHydrator->hydrate($notificationData, $notification); //validate returns true if your Notification instance is valid, or false in the other case $isValid = $notificationValidator->validate($notification); //getErrors() allows you to get an array of errors if there are some, or an empty array in the other case $errors = $notificationValidator->getErrors();
通知和警报创建
<?php use Fei\Service\Notification\Entity\Alert\Email; use Fei\Service\Notification\Entity\Notification; use Fei\Service\Notification\Entity\Alert\Android\Message as AndroidMessage; use Fei\Service\Notification\Entity\Alert\Sms\Message as SmsMessage; $notification = (new Notification()) ->setMessage('Last test') ->setOrigin('test') ->setEvent('My best event') ->setType(Notification::TYPE_INFO) ->setAction(json_encode(['my.action' => 'first create'])) ->setRecipient('user'); $alert_email = (new Email()) ->setNotification($notification) ->setSubject('Email Subject') ->setContent('Email content') ->setEmail('email@provider.com'); $alert_android = (new Android()) ->setNotification($notification) ->setMessage(new AndroidMessage()) ->setRecipients(['id_device_1', 'id_device_2']) ->setDryRun(true) ->setPushNotification(['title' => 'Notif', 'body' => 'Test message']); $alert_sms = (new Sms()) ->setNotification($notification) ->setMessage(new SmsMessage()) ->setFrom('email@provider.com') ->setRecipients(['email@provider.com', 'email2@provider.com']) ->setContent("Sms de test");