Builder.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * (android)消息体.
  4. * @author wangkuiwei
  5. * @name Builder
  6. * @desc 构建发送给Android设备的Message对象。
  7. *
  8. */
  9. namespace xmpush;
  10. // message1 演示开发机
  11. // message1 演示开发机
  12. // message1 演示开发机
  13. // message1 演示开发机
  14. // message1 演示开发机
  15. // message1 演示开发机
  16. class Builder extends Message {
  17. const soundUri = 'sound_uri';
  18. const notifyForeground = 'notify_foreground';
  19. const notifyEffect = 'notify_effect';
  20. const intentUri = 'intent_uri';
  21. const webUri = 'web_uri';
  22. const flowControl = 'flow_control';
  23. const callback = 'callback';
  24. public function __construct() {
  25. $this->notify_id = 0;
  26. $this->notify_type = -1;
  27. $this->payload = '';
  28. $this->restricted_package_name = Constants::$packageName;
  29. parent::__construct();
  30. }
  31. public function payload($payload) {
  32. $this->payload = $payload;
  33. }
  34. public function title($title) {
  35. $this->title = $title;
  36. }
  37. public function description($description) {
  38. $this->description = $description;
  39. }
  40. public function passThrough($passThrough) {
  41. $this->pass_through = $passThrough;
  42. }
  43. public function notifyType($type) {
  44. $this->notify_type = $type;
  45. }
  46. public function restrictedPackageNames($packageNameList) {
  47. $jointPackageNames = '';
  48. foreach ($packageNameList as $packageName) {
  49. if (isset($packageName)) {
  50. $jointPackageNames .= $packageName . Constants::$comma;
  51. }
  52. }
  53. $this->restricted_package_name = $jointPackageNames;
  54. }
  55. public function timeToLive($ttl) {
  56. $this->time_to_live = $ttl;
  57. }
  58. public function timeToSend($timeToSend) {
  59. $this->time_to_send = $timeToSend;
  60. }
  61. public function notifyId($notifyId) {
  62. $this->notify_id = $notifyId;
  63. }
  64. public function extra($key, $value) {
  65. $this->extra[$key] = $value;
  66. }
  67. public function build() {
  68. $keys = array(
  69. 'payload', 'title', 'description', 'pass_through', 'notify_type',
  70. 'restricted_package_name', 'time_to_live', 'time_to_send', 'notify_id'
  71. );
  72. foreach ($keys as $key) {
  73. if (isset($this->$key)) {
  74. $this->fields[$key] = $this->$key;
  75. $this->json_infos[$key] = $this->$key;
  76. }
  77. }
  78. //单独处理extra
  79. $JsonExtra = array();
  80. if (count($this->extra) > 0) {
  81. foreach ($this->extra as $extraKey => $extraValue) {
  82. $this->fields[Message::EXTRA_PREFIX . $extraKey] = $extraValue;
  83. $JsonExtra[$extraKey] = $extraValue;
  84. }
  85. }
  86. $this->json_infos['extra'] = $JsonExtra;
  87. }
  88. }
  89. // message1 演示开发机
  90. // message1 演示开发机
  91. // message1 演示开发机
  92. // message1 演示开发机
  93. // message1 演示开发机
  94. ?>