No Description

IOSBuilder.php 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * IOS设备的消息体.
  4. * @author wangkuiwei
  5. * @name IOSBuilder
  6. * @desc 构建发送给IOS设备的Message对象。
  7. *
  8. */
  9. namespace xmpush;
  10. class IOSBuilder extends Message {
  11. const soundUrl = 'sound_url';
  12. const badge = 'badge';
  13. protected $apsProperFields; // 用于存储aps的属性,为的是支持新的扩展属性
  14. public function __construct() {
  15. parent::__construct();
  16. $this->apsProperFields = array();
  17. }
  18. public function description($description) {
  19. $this->description = $description;
  20. }
  21. public function timeToLive($ttl) {
  22. $this->time_to_live = $ttl;
  23. }
  24. public function timeToSend($timeToSend) {
  25. $this->time_to_send = $timeToSend;
  26. }
  27. public function soundUrl($url) {
  28. $this->extra(IOSBuilder::soundUrl, $url);
  29. }
  30. public function badge($badge) {
  31. $this->extra(IOSBuilder::badge, $badge);
  32. }
  33. public function extra($key, $value) {
  34. $this->extra[$key] = $value;
  35. }
  36. public function title($title) {
  37. $this->apsProperFields["title"] = $title;
  38. }
  39. public function subtitle($subtitle) {
  40. $this->apsProperFields["subtitle"] = $subtitle;
  41. }
  42. public function body($body) {
  43. $this->apsProperFields["body"] = $body;
  44. }
  45. public function mutableContent($mutableContent) {
  46. $this->apsProperFields["mutable-content"] = $mutableContent;
  47. }
  48. public function apsProperFields($key, $value) {
  49. $this->apsProperFields[$key] = $value;
  50. }
  51. public function build() {
  52. $keys = array(
  53. 'description', 'time_to_live', 'time_to_send'
  54. );
  55. foreach ($keys as $key) {
  56. if (isset($this->$key)) {
  57. $this->fields[$key] = $this->$key;
  58. $this->json_infos[$key] = $this->$key;
  59. }
  60. }
  61. //单独处理extra
  62. $JsonExtra = array();
  63. if (count($this->extra) > 0) {
  64. foreach ($this->extra as $extraKey => $extraValue) {
  65. $this->fields[Message::EXTRA_PREFIX . $extraKey] = $extraValue;
  66. $JsonExtra[$extraKey] = $extraValue;
  67. }
  68. }
  69. $this->json_infos['extra'] = $JsonExtra;
  70. // 单独处理apsProperFields
  71. if (count($this->apsProperFields) > 0) {
  72. foreach ($this->apsProperFields as $key => $value) {
  73. $this->fields[Message::APS_PROPER_FIELDS_PREFIX . $key] = $value;
  74. }
  75. }
  76. }
  77. }
  78. ?>