Notification.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Libs\Push\HuaWei\Admin\Msg\Notification;
  3. use Exception;
  4. class Notification
  5. {
  6. /**
  7. * optional
  8. */
  9. private $title;
  10. /**
  11. * optional
  12. */
  13. private $body;
  14. /**
  15. * optional
  16. */
  17. private $image;
  18. private $fields;
  19. public function __construct($title, $body, $image)
  20. {
  21. $this->title = $title;
  22. $this->body = $body;
  23. $this->image = $image;
  24. $this->fields = array();
  25. }
  26. public function title($value)
  27. {
  28. $this->title = $value;
  29. }
  30. public function body($value)
  31. {
  32. $this->body = $value;
  33. }
  34. public function image($value)
  35. {
  36. $this->image = $value;
  37. }
  38. public function getFields()
  39. {
  40. return $this->fields;
  41. }
  42. public function buildFields()
  43. {
  44. try {
  45. $this->check_parameter();
  46. } catch (Exception $e) {
  47. echo $e;
  48. }
  49. $keys = array(
  50. 'title',
  51. 'body',
  52. 'image'
  53. );
  54. foreach ($keys as $key) {
  55. if (isset($this->$key)) {
  56. $this->fields[$key] = $this->$key;
  57. }
  58. }
  59. }
  60. private function check_parameter()
  61. {
  62. if (empty($this->title)) {
  63. throw new Exception("title should be set");
  64. }
  65. if (empty($this->body)) {
  66. throw new Exception("body should be set");
  67. }
  68. }
  69. }