Aps.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Libs\Push\HuaWei\Admin\Msg\Apns;
  3. use App\Libs\Push\HuaWei\Admin\Constants;
  4. use App\Libs\Push\HuaWei\Admin\PushLogConfig;
  5. class Aps
  6. {
  7. private $alert;
  8. private $badge;
  9. private $sound;
  10. private $content_available;
  11. private $category;
  12. private $thread_id;
  13. private $fields;
  14. public function alert($value)
  15. {
  16. $this->alert = $value;
  17. }
  18. public function badge($value)
  19. {
  20. $this->badge = $value;
  21. }
  22. public function sound($value)
  23. {
  24. $this->sound = $value;
  25. }
  26. public function content_available($value)
  27. {
  28. $this->content_available = $value;
  29. }
  30. public function category($value)
  31. {
  32. $this->category = $value;
  33. }
  34. public function thread_id($value)
  35. {
  36. $this->thread_id = $value;
  37. }
  38. public function getFields()
  39. {
  40. return $this->fields;
  41. }
  42. public function buildFields()
  43. {
  44. $keys = array(
  45. 'alert',
  46. 'badge',
  47. 'sound',
  48. 'content-available',
  49. 'category',
  50. 'thread-id'
  51. );
  52. foreach ($keys as $key) {
  53. $value = str_replace('-', '_', $key);
  54. PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][before key:' . $key . '][after key:' . $value . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL);
  55. if (isset($this->$value)) {
  56. $this->fields[$key] = $this->$value;
  57. }
  58. }
  59. PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL);
  60. }
  61. }