123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- namespace App\Libs\Push\HuaWei\Admin\Msg\WebPush;
- use Exception;
- class WebPushNotification
- {
- private $title;
- private $body;
- private $icon;
- private $image;
- private $lang;
- private $tag;
- private $badge;
- private $dir;
- private $vibrate;
- private $renotify;
- private $require_interaction;
- private $silent;
- private $timestamp;
- private $actions;
- private $fields;
- public function __construct()
- {
- $this->actions = array();
- $this->fields = array();
- }
- public function title($value)
- {
- $this->title = $value;
- }
- public function body($value)
- {
- $this->body = $value;
- }
- public function icon($value)
- {
- $this->icon = $value;
- }
- public function image($value)
- {
- $this->image = $value;
- }
- public function lang($value)
- {
- $this->lang = $value;
- }
- public function tag($value)
- {
- $this->tag = $value;
- }
- public function badge($value)
- {
- $this->badge = $value;
- }
- public function dir($value)
- {
- $this->dir = $value;
- }
- public function vibrate($value)
- {
- $this->vibrate = $value;
- }
- public function renotify($value)
- {
- $this->renotify = $value;
- }
- public function require_interaction($value)
- {
- $this->require_interaction = $value;
- }
- public function silent($value)
- {
- $this->silent = $value;
- }
- public function timestamp($value)
- {
- $this->timestamp = $value;
- }
- public function actions($value)
- {
- $this->actions = $value;
- }
- public function getFields()
- {
- return $this->fields;
- }
- public function buildFields()
- {
- try {
- $this->check_parameter();
- } catch (Exception $e) {
- echo $e;
- }
- $keys = array(
- 'title',
- 'body',
- 'icon',
- 'image',
- 'lang',
- 'tag',
- 'badge',
- 'dir',
- 'vibrate',
- 'renotify',
- 'require_interaction',
- 'silent',
- 'timestamp',
- 'actions'
- );
- foreach ($keys as $key) {
- if (isset($this->$key)) {
- $this->fields[$key] = $this->$key;
- }
- }
- }
- private function check_parameter()
- {
- if (($this->renotify) && (gettype($this->renotify) != "boolean")) {
- throw new Exception("type of renotify is wrong.");
- }
- if (($this->require_interaction) && (gettype($this->require_interaction) != "boolean")) {
- throw new Exception("type of requireInteraction is wrong.");
- }
- if (($this->silent) && (gettype($this->silent) != "boolean")) {
- throw new Exception("type of silent is wrong.");
- }
- }
- }
|